r204220 - Use the expansion location of the file name when finding the module.
Manuel Klimek
klimek at google.com
Wed Mar 19 03:22:36 PDT 2014
Author: klimek
Date: Wed Mar 19 05:22:36 2014
New Revision: 204220
URL: http://llvm.org/viewvc/llvm-project?rev=204220&view=rev
Log:
Use the expansion location of the file name when finding the module.
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.
Added:
cfe/trunk/test/Modules/Inputs/declare-use/j.h
cfe/trunk/test/Modules/declare-use3.cpp
cfe/trunk/test/Modules/declare-use4.cpp
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Modules/Inputs/declare-use/module.map
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=204220&r1=204219&r2=204220&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Mar 19 05:22:36 2014
@@ -540,7 +540,7 @@ Module *Preprocessor::getModuleForLocati
}
// 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();
Added: cfe/trunk/test/Modules/Inputs/declare-use/j.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/declare-use/j.h?rev=204220&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/declare-use/j.h (added)
+++ cfe/trunk/test/Modules/Inputs/declare-use/j.h Wed Mar 19 05:22:36 2014
@@ -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
Modified: cfe/trunk/test/Modules/Inputs/declare-use/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/declare-use/module.map?rev=204220&r1=204219&r2=204220&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/declare-use/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/declare-use/module.map Wed Mar 19 05:22:36 2014
@@ -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 {
}
Added: cfe/trunk/test/Modules/declare-use3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/declare-use3.cpp?rev=204220&view=auto
==============================================================================
--- cfe/trunk/test/Modules/declare-use3.cpp (added)
+++ cfe/trunk/test/Modules/declare-use3.cpp Wed Mar 19 05:22:36 2014
@@ -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;
Added: cfe/trunk/test/Modules/declare-use4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/declare-use4.cpp?rev=204220&view=auto
==============================================================================
--- cfe/trunk/test/Modules/declare-use4.cpp (added)
+++ cfe/trunk/test/Modules/declare-use4.cpp Wed Mar 19 05:22:36 2014
@@ -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
More information about the cfe-commits
mailing list