]> granicus.if.org Git - clang/commitdiff
Default getFile() to use the last accessed name in the FileEntry.
authorManuel Klimek <klimek@google.com>
Wed, 13 Aug 2014 12:34:41 +0000 (12:34 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 13 Aug 2014 12:34:41 +0000 (12:34 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215541 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/FileManager.cpp
test/Modules/Inputs/filename/a.h [new file with mode: 0644]
test/Modules/Inputs/filename/module.map [new file with mode: 0644]
test/Modules/filename.cpp [new file with mode: 0644]

index e4a7f1e257502474259eb47bad076bc4662f8c36..07297baf6d5d24835a3f94ead90e53c17041b7d2 100644 (file)
@@ -281,6 +281,13 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
     if (DirInfo != UFE.Dir && Data.IsVFSMapped)
       UFE.Dir = DirInfo;
 
+    // Always update the name to use the last name by which a file was accessed.
+    // FIXME: Neither this nor always using the first name is correct; we want
+    // to switch towards a design where we return a FileName object that
+    // encapsulates both the name by which the file was accessed and the
+    // corresponding FileEntry.
+    UFE.Name = Data.Name;
+
     return &UFE;
   }
 
diff --git a/test/Modules/Inputs/filename/a.h b/test/Modules/Inputs/filename/a.h
new file mode 100644 (file)
index 0000000..8f896a9
--- /dev/null
@@ -0,0 +1 @@
+const char *p = __FILE__;
diff --git a/test/Modules/Inputs/filename/module.map b/test/Modules/Inputs/filename/module.map
new file mode 100644 (file)
index 0000000..ff164ad
--- /dev/null
@@ -0,0 +1,3 @@
+module "A" {
+  header "a.h"
+}
diff --git a/test/Modules/filename.cpp b/test/Modules/filename.cpp
new file mode 100644 (file)
index 0000000..66891a0
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: cd %S
+// RUN: %clang_cc1 -I. -fmodule-maps -fmodule-name=A  -fmodule-map-file=%S/Inputs/filename/module.map %s -E | FileCheck %s
+// REQUIRES: shell
+
+#include "Inputs/filename/a.h"
+
+// Make sure that headers that are referenced by module maps have __FILE__
+// reflect the include path they were found with.
+// CHECK: const char *p = "./Inputs/filename/a.h"