]> granicus.if.org Git - clang/commitdiff
Use the expansion location of the file name when finding the module.
authorManuel Klimek <klimek@google.com>
Wed, 19 Mar 2014 10:22:36 +0000 (10:22 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 19 Mar 2014 10:22:36 +0000 (10:22 +0000)
The spelling location of stringified strings is not a file location.
Optimally, we'll want to solve the problem (as the FIXME states) by
handing in the right FileEntry of the #include location.

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

lib/Lex/PPDirectives.cpp
test/Modules/Inputs/declare-use/j.h [new file with mode: 0644]
test/Modules/Inputs/declare-use/module.map
test/Modules/declare-use3.cpp [new file with mode: 0644]
test/Modules/declare-use4.cpp [new file with mode: 0644]

index 8ef3c918f337dae7e117ff33e3bfeae3f84a400d..57dc49536af293a575ef3ed2089fed70d39a41c0 100644 (file)
@@ -540,7 +540,7 @@ Module *Preprocessor::getModuleForLocation(SourceLocation FilenameLoc) {
   }
   // Try to determine the module of the include directive.
   // FIXME: Look into directly passing the FileEntry from LookupFile instead.
-  FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getSpellingLoc(FilenameLoc));
+  FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(FilenameLoc));
   if (const FileEntry *EntryOfIncl = SourceMgr.getFileEntryForID(IDOfIncl)) {
     // The include comes from a file.
     return ModMap.findModuleForHeader(EntryOfIncl).getModule();
diff --git a/test/Modules/Inputs/declare-use/j.h b/test/Modules/Inputs/declare-use/j.h
new file mode 100644 (file)
index 0000000..04d46a9
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef J_H
+#define J_H
+
+#define STR(x) #x
+#define HDR(x) STR(x.h)
+
+#include ALLOWED_INC
+#include HDR(a)
+
+const int j = a * a + b;
+
+// expected-no-diagnostics
+
+#endif
index 3b1b0e743e45501dbacaae93a46559c21fae8b4c..a176fb3a141fc720e8bbb33a4fba296a7443b31b 100644 (file)
@@ -37,6 +37,7 @@ module XG {
   header "g1.h"
   use XC
   use XE
+  use XJ
 }
 
 module XH {
@@ -47,5 +48,9 @@ module XH {
   use XE
 }
 
+module XJ {
+  header "j.h"
+}
+
 module XS {
 }
diff --git a/test/Modules/declare-use3.cpp b/test/Modules/declare-use3.cpp
new file mode 100644 (file)
index 0000000..8b0bbfa
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -include "g.h" -include "e.h" -include "f.h" -include "i.h" -fmodule-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
+// expected-error {{module XG does not depend on a module exporting 'f.h'}}
+const int g2 = g1 + e + f + aux_i;
diff --git a/test/Modules/declare-use4.cpp b/test/Modules/declare-use4.cpp
new file mode 100644 (file)
index 0000000..1d34646
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodule-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
+
+#define ALLOWED_INC "b.h"
+
+#include "j.h"
+
+const int g2 = j;
+
+// expected-no-diagnostics