r361779 - [Preprocessor] Fix crash emitting note with framework location for "file not found" error.

Volodymyr Sapsai via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 12:15:31 PDT 2019


Author: vsapsai
Date: Mon May 27 12:15:30 2019
New Revision: 361779

URL: http://llvm.org/viewvc/llvm-project?rev=361779&view=rev
Log:
[Preprocessor] Fix crash emitting note with framework location for "file not found" error.

A filename can be remapped with a header map to point to a framework
header and we can find the corresponding framework without the header.
But if the original filename doesn't have a remapped framework name,
we'll fail to find its location and will dereference a null pointer
during diagnostics emission.

Fix by tracking remappings better and emit the note only if a framework
is found before any of the remappings.

rdar://problem/48883447

Reviewers: arphaman, erik.pilkington, jkorous

Reviewed By: arphaman

Subscribers: dexonsmith, cfe-commits

Differential Revision: https://reviews.llvm.org/D61707

Added:
    cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/
    cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
    cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
Modified:
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/lib/Lex/HeaderSearch.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=361779&r1=361778&r2=361779&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Mon May 27 12:15:30 2019
@@ -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,

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=361779&r1=361778&r2=361779&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Mon May 27 12:15:30 2019
@@ -869,7 +869,10 @@ const FileEntry *HeaderSearch::LookupFil
         *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];

Added: cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json?rev=361779&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json (added)
+++ cfe/trunk/test/Preprocessor/Inputs/include-header-missing-in-framework/TestFramework.hmap.json Mon May 27 12:15:30 2019
@@ -0,0 +1,7 @@
+{
+  "mappings" :
+    {
+     "RemappedHeader.h" : "TestFramework/RemappedHeader.h",
+     "TestFramework/BeforeRemapping.h" : "TestFramework/AfterRemapping.h"
+    }
+}

Added: cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c?rev=361779&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c (added)
+++ cfe/trunk/test/Preprocessor/include-header-missing-in-framework-with-headermap.c Mon May 27 12:15:30 2019
@@ -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 at -1 {{'TestFramework/BeforeRemapping.h' file not found}}
+// expected-note at -2 {{did not find header 'BeforeRemapping.h' in framework 'TestFramework' (loaded from}}
+
+#else
+// Framework is found after remapping.
+#include "RemappedHeader.h"
+// expected-error at -1 {{'RemappedHeader.h' file not found}}
+#endif // LATE_REMAPPING




More information about the cfe-commits mailing list