Index: lib/Tooling/ASTDiff/ASTDiff.cpp =================================================================== --- lib/Tooling/ASTDiff/ASTDiff.cpp +++ lib/Tooling/ASTDiff/ASTDiff.cpp @@ -203,8 +203,7 @@ return true; SourceLocation SLoc = N->getSourceRange().getBegin(); if (SLoc.isValid()) { - // Ignore everything from other files. - if (!SM.isInMainFile(SLoc)) + if (SM.isInSystemHeader(SLoc)) return true; const Preprocessor &PP = AST.getPreprocessor(); if (SLoc.isMacroID() && !PP.isAtStartOfMacroExpansion(SLoc)) Index: test/Tooling/clang-diff-ast.cpp =================================================================== --- test/Tooling/clang-diff-ast.cpp +++ test/Tooling/clang-diff-ast.cpp @@ -95,14 +95,14 @@ #define GUARD // CHECK-NEXT: NamespaceDecl(93) namespace world { -// nodes from other files are excluded, there should be no output here +// CHECK-NEXT: NamespaceDecl #include "clang-diff-ast.cpp" } -// CHECK-NEXT: FunctionDecl(94) +// CHECK: FunctionDecl(197) void sentinel(); #endif -// CHECK: ClassTemplateDecl(97) +// CHECK: ClassTemplateDecl(200) // CHECK-NEXT: TemplateTypeParmDecl // CHECK-NEXT: QualType // CHECK-NEXT: CXXRecordDecl Index: tools/clang-diff/ClangDiff.cpp =================================================================== --- tools/clang-diff/ClangDiff.cpp +++ tools/clang-diff/ClangDiff.cpp @@ -276,6 +276,10 @@ char MyTag, OtherTag; diff::NodeId LeftId, RightId; diff::SyntaxTree &Tree = Node.getTree(); + const SourceManager &SM = Tree.getASTContext().getSourceManager(); + SourceLocation SLoc = Node.getSourceRange().getBegin(); + if (SLoc.isValid() && !SM.isInMainFile(SLoc)) + return Offset; const diff::Node *Target = Diff.getMapped(Node); diff::NodeId TargetId = Target ? Target->getId() : diff::NodeId(); if (IsLeft) { @@ -291,7 +295,6 @@ } unsigned Begin, End; std::tie(Begin, End) = Node.getSourceRangeOffsets(); - const SourceManager &SM = Tree.getASTContext().getSourceManager(); auto Code = SM.getBuffer(SM.getMainFileID())->getBuffer(); for (; Offset < Begin; ++Offset) printHtml(OS, Code[Offset]);