Author: Haojian Wu Date: 2022-12-09T12:12:16+01:00 New Revision: 526fb5fae79f1b037eb084783d5eb082258ede9b
URL: https://github.com/llvm/llvm-project/commit/526fb5fae79f1b037eb084783d5eb082258ede9b DIFF: https://github.com/llvm/llvm-project/commit/526fb5fae79f1b037eb084783d5eb082258ede9b.diff LOG: [include-cleaner] Fix walkUsed only report a single macro ref. The fix 962343a979d51cea9363167e9121c446abbdfdbc was reverted during a rebase of a later patch. Added a test. Added: Modified: clang-tools-extra/include-cleaner/lib/Analysis.cpp clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp b/clang-tools-extra/include-cleaner/lib/Analysis.cpp index 95cf8ab7550a5..fa3bbaab27c24 100644 --- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp +++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp @@ -52,7 +52,7 @@ void walkUsed(llvm::ArrayRef<Decl *> ASTRoots, } for (const SymbolReference &MacroRef : MacroRefs) { assert(MacroRef.Target.kind() == Symbol::Macro); - return CB(MacroRef, headersForSymbol(MacroRef.Target, SM, PI)); + CB(MacroRef, headersForSymbol(MacroRef.Target, SM, PI)); } } diff --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp index 9a1f4fce801c3..13f5aad4912a4 100644 --- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp @@ -145,25 +145,33 @@ TEST_F(WalkUsedTest, MultipleProviders) { TEST_F(WalkUsedTest, MacroRefs) { llvm::Annotations Code(R"cpp( #include "hdr.h" - int x = ^ANSWER; + int x = $1^ANSWER; + int y = $2^ANSWER; )cpp"); llvm::Annotations Hdr(guard("#define ^ANSWER 42")); Inputs.Code = Code.code(); Inputs.ExtraFiles["hdr.h"] = Hdr.code(); TestAST AST(Inputs); auto &SM = AST.sourceManager(); - auto HdrFile = SM.getFileManager().getFile("hdr.h").get(); + const auto *HdrFile = SM.getFileManager().getFile("hdr.h").get(); auto HdrID = SM.translateFile(HdrFile); IdentifierTable Idents; - Symbol Answer = + Symbol Answer1 = + Macro{&Idents.get("ANSWER"), SM.getComposedLoc(HdrID, Hdr.point())}; + Symbol Answer2 = Macro{&Idents.get("ANSWER"), SM.getComposedLoc(HdrID, Hdr.point())}; EXPECT_THAT( - offsetToProviders( - AST, SM, - {SymbolReference{SM.getComposedLoc(SM.getMainFileID(), Code.point()), - Answer, RefType::Explicit}}), - UnorderedElementsAre(Pair(Code.point(), UnorderedElementsAre(HdrFile)))); + offsetToProviders(AST, SM, + {SymbolReference{SM.getComposedLoc(SM.getMainFileID(), + Code.point("1")), + Answer1, RefType::Explicit}, + SymbolReference{SM.getComposedLoc(SM.getMainFileID(), + Code.point("2")), + Answer2, RefType::Explicit}}), + UnorderedElementsAre( + Pair(Code.point("1"), UnorderedElementsAre(HdrFile)), + Pair(Code.point("2"), UnorderedElementsAre(HdrFile)))); } TEST(Analyze, Basic) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits