[PATCH] D124638: [clang] Track how headers get included generally during lookup time

Cyndy Ishida via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 28 14:29:35 PDT 2022


cishida created this revision.
cishida added reviewers: ributzka, zixuw, jansvoboda11.
Herald added a project: All.
cishida requested review of this revision.
Herald added a project: clang.

tapi & clang-extractapi both attempt to construct then check against
how a header was included to determine api information when working
against multiple search paths, headermap, and vfsoverlay mechanisms.
Validating this against what the preprocessor sees during lookup time
makes this check more reliable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124638

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Lex/HeaderSearchTest.cpp


Index: clang/unittests/Lex/HeaderSearchTest.cpp
===================================================================
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -207,6 +207,7 @@
   EXPECT_TRUE(FI);
   EXPECT_TRUE(FI->IsValid);
   EXPECT_EQ(FI->Framework.str(), "Foo");
+  EXPECT_EQ(FI->Alias, "Foo/Foo.h");
 }
 
 // Helper struct with null terminator character to make MemoryBuffer happy.
@@ -275,6 +276,7 @@
   EXPECT_TRUE(FI);
   EXPECT_TRUE(FI->IsValid);
   EXPECT_EQ(FI->Framework.str(), "Foo");
+  EXPECT_EQ(FI->Alias, "Foo/Foo.h");
 }
 
 } // namespace
Index: clang/lib/Lex/HeaderSearch.cpp
===================================================================
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1030,8 +1030,10 @@
 
     CurDir = It;
 
-    // This file is a system header or C++ unfriendly if the dir is.
     HeaderFileInfo &HFI = getFileInfo(&File->getFileEntry());
+    HFI.Alias = Filename.str();
+
+    // This file is a system header or C++ unfriendly if the dir is.
     HFI.DirInfo = CurDir->getDirCharacteristic();
 
     // If the directory characteristic is User but this framework was
Index: clang/include/clang/Lex/HeaderSearch.h
===================================================================
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -20,6 +20,7 @@
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
@@ -116,6 +117,9 @@
   /// of the framework.
   StringRef Framework;
 
+  /// Alias that this header is known as.
+  llvm::SmallString<64> Alias;
+
   HeaderFileInfo()
       : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User),
         External(false), isModuleHeader(false), isCompilingModuleHeader(false),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124638.425908.patch
Type: text/x-patch
Size: 1961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220428/9a256af0/attachment-0001.bin>


More information about the cfe-commits mailing list