summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Lex/HeaderSearch.h5
-rw-r--r--clang/lib/Lex/HeaderSearch.cpp5
-rw-r--r--clang/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json7
-rw-r--r--clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c20
4 files changed, 34 insertions, 3 deletions
diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h
index 7488d9e0e3d..d6602360728 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -392,8 +392,9 @@ public:
/// true.
///
/// \param IsFrameworkFound If non-null, will be set to true if a framework is
- /// found in any of searched SearchDirs. Doesn't guarantee the requested file
- /// is found.
+ /// found in any of searched SearchDirs. Will be set to false if a framework
+ /// is found only through header maps. Doesn't guarantee the requested file is
+ /// found.
const FileEntry *LookupFile(
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir,
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index af763059ea9..16a53bf634a 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -869,7 +869,10 @@ const FileEntry *HeaderSearch::LookupFile(
*IsMapped = true;
}
if (IsFrameworkFound)
- *IsFrameworkFound |= IsFrameworkFoundInDir;
+ // Because we keep a filename remapped for subsequent search directory
+ // lookups, ignore IsFrameworkFoundInDir after the first remapping and not
+ // just for remapping in a current search directory.
+ *IsFrameworkFound |= (IsFrameworkFoundInDir && !CacheLookup.MappedName);
if (!FE) continue;
CurDir = &SearchDirs[i];
diff --git a/clang/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json b/clang/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
new file mode 100644
index 00000000000..193c7a779c6
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
@@ -0,0 +1,7 @@
+{
+ "mappings" :
+ {
+ "RemappedHeader.h" : "TestFramework/RemappedHeader.h",
+ "TestFramework/BeforeRemapping.h" : "TestFramework/AfterRemapping.h"
+ }
+}
diff --git a/clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c b/clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
new file mode 100644
index 00000000000..da8d50cf915
--- /dev/null
+++ b/clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
@@ -0,0 +1,20 @@
+// RUN: rm -f %t.hmap
+// RUN: %hmaptool write %S/Inputs/include-header-missing-in-framework/TestFramework.hmap.json %t.hmap
+// RUN: %clang_cc1 -fsyntax-only -F %S/Inputs -I %t.hmap -verify %s -DLATE_REMAPPING
+// RUN: %clang_cc1 -fsyntax-only -I %t.hmap -F %S/Inputs -verify %s
+
+// The test is similar to 'include-header-missing-in-framework.c' but covers
+// the case when a header is remapped to a framework-like path with a .hmap
+// file. And we can find the framework but not the header.
+
+#ifdef LATE_REMAPPING
+// Framework is found before remapping.
+#include <TestFramework/BeforeRemapping.h>
+// expected-error@-1 {{'TestFramework/BeforeRemapping.h' file not found}}
+// expected-note@-2 {{did not find header 'BeforeRemapping.h' in framework 'TestFramework' (loaded from}}
+
+#else
+// Framework is found after remapping.
+#include "RemappedHeader.h"
+// expected-error@-1 {{'RemappedHeader.h' file not found}}
+#endif // LATE_REMAPPING
OpenPOWER on IntegriCloud