Author: David Goldman Date: 2022-02-04T13:32:39-05:00 New Revision: 9385ece95a4a342ca4f4c46ea747f79d4ede9783
URL: https://github.com/llvm/llvm-project/commit/9385ece95a4a342ca4f4c46ea747f79d4ede9783 DIFF: https://github.com/llvm/llvm-project/commit/9385ece95a4a342ca4f4c46ea747f79d4ede9783.diff LOG: [HeaderSearch] Track framework name in LookupFile Previously, the Framework name was only set if the file came from a header mapped framework; now we'll always set the framework name if the file is in a framework. Differential Revision: https://reviews.llvm.org/D117830 Added: Modified: clang/lib/Lex/HeaderSearch.cpp clang/unittests/Lex/HeaderSearchTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 39c125c395ef8..19e284f04b38c 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1037,8 +1037,9 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( } } - // If this file is found in a header map and uses the framework style of - // includes, then this header is part of a framework we're building. + // Set the `Framework` info if this file is in a header map with framework + // style include spelling or found in a framework dir. The header map case + // is possible when building frameworks which use header maps. if (CurDir->isHeaderMap() && isAngled) { size_t SlashPos = Filename.find('/'); if (SlashPos != StringRef::npos) @@ -1046,6 +1047,11 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos)); if (CurDir->isIndexHeaderMap()) HFI.IndexHeaderMapHeader = 1; + } else if (CurDir->isFramework()) { + size_t SlashPos = Filename.find('/'); + if (SlashPos != StringRef::npos) + HFI.Framework = + getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos)); } if (checkMSVCHeaderSearch(Diags, MSFE ? &MSFE->getFileEntry() : nullptr, diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index 10ecbbd26659e..fbb5cb30754a7 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -186,6 +186,29 @@ TEST_F(HeaderSearchTest, NestedFramework) { "Sub/Sub.h"); } +TEST_F(HeaderSearchTest, HeaderFrameworkLookup) { + std::string HeaderPath = "/tmp/Frameworks/Foo.framework/Headers/Foo.h"; + addSystemFrameworkSearchDir("/tmp/Frameworks"); + VFS->addFile( + HeaderPath, 0, llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/None, /*Group=*/None, llvm::sys::fs::file_type::regular_file); + + bool IsFrameworkFound = false; + auto FoundFile = Search.LookupFile( + "Foo/Foo.h", SourceLocation(), /*isAngled=*/true, /*FromDir=*/nullptr, + /*CurDir=*/nullptr, /*Includers=*/{}, /*SearchPath=*/nullptr, + /*RelativePath=*/nullptr, /*RequestingModule=*/nullptr, + /*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr, &IsFrameworkFound); + + EXPECT_TRUE(FoundFile.hasValue()); + EXPECT_TRUE(IsFrameworkFound); + auto &FE = FoundFile.getValue(); + auto FI = Search.getExistingFileInfo(FE); + EXPECT_TRUE(FI); + EXPECT_TRUE(FI->IsValid); + EXPECT_EQ(FI->Framework.str(), "Foo"); +} + // Helper struct with null terminator character to make MemoryBuffer happy. template <class FileTy, class PaddingTy> struct NullTerminatedFile : public FileTy { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits