r215541 - Default getFile() to use the last accessed name in the FileEntry.

Manuel Klimek klimek at google.com
Wed Aug 13 05:34:41 PDT 2014


Author: klimek
Date: Wed Aug 13 07:34:41 2014
New Revision: 215541

URL: http://llvm.org/viewvc/llvm-project?rev=215541&view=rev
Log:
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.

Added:
    cfe/trunk/test/Modules/Inputs/filename/
    cfe/trunk/test/Modules/Inputs/filename/a.h
    cfe/trunk/test/Modules/Inputs/filename/module.map
    cfe/trunk/test/Modules/filename.cpp
Modified:
    cfe/trunk/lib/Basic/FileManager.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=215541&r1=215540&r2=215541&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Wed Aug 13 07:34:41 2014
@@ -281,6 +281,13 @@ const FileEntry *FileManager::getFile(St
     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;
   }
 

Added: cfe/trunk/test/Modules/Inputs/filename/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/filename/a.h?rev=215541&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/filename/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/filename/a.h Wed Aug 13 07:34:41 2014
@@ -0,0 +1 @@
+const char *p = __FILE__;

Added: cfe/trunk/test/Modules/Inputs/filename/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/filename/module.map?rev=215541&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/filename/module.map (added)
+++ cfe/trunk/test/Modules/Inputs/filename/module.map Wed Aug 13 07:34:41 2014
@@ -0,0 +1,3 @@
+module "A" {
+  header "a.h"
+}

Added: cfe/trunk/test/Modules/filename.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/filename.cpp?rev=215541&view=auto
==============================================================================
--- cfe/trunk/test/Modules/filename.cpp (added)
+++ cfe/trunk/test/Modules/filename.cpp Wed Aug 13 07:34:41 2014
@@ -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"





More information about the cfe-commits mailing list