Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit ab4fa50

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361779 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit b84e04d)
1 parent cda703c commit ab4fa50

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

include/clang/Lex/HeaderSearch.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,9 @@ class HeaderSearch {
393393
/// true.
394394
///
395395
/// \param IsFrameworkFound If non-null, will be set to true if a framework is
396-
/// found in any of searched SearchDirs. Doesn't guarantee the requested file
397-
/// is found.
396+
/// found in any of searched SearchDirs. Will be set to false if a framework
397+
/// is found only through header maps. Doesn't guarantee the requested file is
398+
/// found.
398399
const FileEntry *LookupFile(
399400
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
400401
const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir,

lib/Lex/HeaderSearch.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,10 @@ const FileEntry *HeaderSearch::LookupFile(
870870
*IsMapped = true;
871871
}
872872
if (IsFrameworkFound)
873-
*IsFrameworkFound |= IsFrameworkFoundInDir;
873+
// Because we keep a filename remapped for subsequent search directory
874+
// lookups, ignore IsFrameworkFoundInDir after the first remapping and not
875+
// just for remapping in a current search directory.
876+
*IsFrameworkFound |= (IsFrameworkFoundInDir && !CacheLookup.MappedName);
874877
if (!FE) continue;
875878

876879
CurDir = &SearchDirs[i];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"mappings" :
3+
{
4+
"RemappedHeader.h" : "TestFramework/RemappedHeader.h",
5+
"TestFramework/BeforeRemapping.h" : "TestFramework/AfterRemapping.h"
6+
}
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: rm -f %t.hmap
2+
// RUN: %hmaptool write %S/Inputs/include-header-missing-in-framework/TestFramework.hmap.json %t.hmap
3+
// RUN: %clang_cc1 -fsyntax-only -F %S/Inputs -I %t.hmap -verify %s -DLATE_REMAPPING
4+
// RUN: %clang_cc1 -fsyntax-only -I %t.hmap -F %S/Inputs -verify %s
5+
6+
// The test is similar to 'include-header-missing-in-framework.c' but covers
7+
// the case when a header is remapped to a framework-like path with a .hmap
8+
// file. And we can find the framework but not the header.
9+
10+
#ifdef LATE_REMAPPING
11+
// Framework is found before remapping.
12+
#include <TestFramework/BeforeRemapping.h>
13+
// expected-error@-1 {{'TestFramework/BeforeRemapping.h' file not found}}
14+
// expected-note@-2 {{did not find header 'BeforeRemapping.h' in framework 'TestFramework' (loaded from}}
15+
16+
#else
17+
// Framework is found after remapping.
18+
#include "RemappedHeader.h"
19+
// expected-error@-1 {{'RemappedHeader.h' file not found}}
20+
#endif // LATE_REMAPPING

0 commit comments

Comments
 (0)