Skip to content

Commit c0ff990

Browse files
committed
Default getFile() to use the last accessed name in the FileEntry.
With modules we start accessing headers for the first time while reading the module map, which often has very different paths from the include scanning logic. Using the name by which the file was accessed gets us one step closer to the right solution, which is using a FileName abstraction that decouples the name by which a file was accessed from the FileEntry. llvm-svn: 215541
1 parent 2fe75b3 commit c0ff990

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

clang/lib/Basic/FileManager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
281281
if (DirInfo != UFE.Dir && Data.IsVFSMapped)
282282
UFE.Dir = DirInfo;
283283

284+
// Always update the name to use the last name by which a file was accessed.
285+
// FIXME: Neither this nor always using the first name is correct; we want
286+
// to switch towards a design where we return a FileName object that
287+
// encapsulates both the name by which the file was accessed and the
288+
// corresponding FileEntry.
289+
UFE.Name = Data.Name;
290+
284291
return &UFE;
285292
}
286293

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const char *p = __FILE__;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module "A" {
2+
header "a.h"
3+
}

clang/test/Modules/filename.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: cd %S
2+
// RUN: %clang_cc1 -I. -fmodule-maps -fmodule-name=A -fmodule-map-file=%S/Inputs/filename/module.map %s -E | FileCheck %s
3+
// REQUIRES: shell
4+
5+
#include "Inputs/filename/a.h"
6+
7+
// Make sure that headers that are referenced by module maps have __FILE__
8+
// reflect the include path they were found with.
9+
// CHECK: const char *p = "./Inputs/filename/a.h"

0 commit comments

Comments
 (0)