[PATCH] D20383: PCH + Module: make sure we write out macros associated with builtin identifiers
Manman Ren via cfe-commits
cfe-commits at lists.llvm.org
Wed May 18 14:00:09 PDT 2016
manmanren created this revision.
manmanren added reviewers: benlangmuir, rsmith.
manmanren added a subscriber: cfe-commits.
When we import a module that defines a builtin identifier from prefix header and precompile the prefix header, the macro information related to the identifier is lost.
If we don't precompile the prefix header, the source file can still see the macro information.
The reason is that we write out the identifier in the pch but not the macro information since the macro is not defined locally.
This seems to be related to r251565: If we read a builtin identifier from a module that wasn't "interesting" to that module, we will still write it out to a PCH that imports that module.
The fix proposed here is to write exported module macros for PCH as well. I am open to other suggestions.
http://reviews.llvm.org/D20383
Files:
lib/Serialization/ASTWriter.cpp
test/Modules/Inputs/MacroFabs1.h
test/Modules/Inputs/module.map
test/Modules/Inputs/pch-import-module-with-macro.pch
test/Modules/pch-module-macro.m
Index: test/Modules/pch-module-macro.m
===================================================================
--- test/Modules/pch-module-macro.m
+++ test/Modules/pch-module-macro.m
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -emit-pch -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -o %t.pch -I %S/Inputs -x objective-c-header %S/Inputs/pch-import-module-with-macro.pch
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fsyntax-only -I %S/Inputs -include-pch %t.pch %s -verify
+// expected-no-diagnostics
+
+int test(int x) {
+ return my_fabs(x) + fabs(x);
+}
+
Index: test/Modules/Inputs/pch-import-module-with-macro.pch
===================================================================
--- test/Modules/Inputs/pch-import-module-with-macro.pch
+++ test/Modules/Inputs/pch-import-module-with-macro.pch
@@ -0,0 +1,3 @@
+
+ at import MacroFabs1;
+
Index: test/Modules/Inputs/module.map
===================================================================
--- test/Modules/Inputs/module.map
+++ test/Modules/Inputs/module.map
@@ -414,3 +414,7 @@
}
module Empty {}
+
+module MacroFabs1 {
+ header "MacroFabs1.h"
+}
Index: test/Modules/Inputs/MacroFabs1.h
===================================================================
--- test/Modules/Inputs/MacroFabs1.h
+++ test/Modules/Inputs/MacroFabs1.h
@@ -0,0 +1,6 @@
+
+#undef fabs
+#define fabs(x) (x)
+
+#undef my_fabs
+#define my_fabs(x) (x)
Index: lib/Serialization/ASTWriter.cpp
===================================================================
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -2187,7 +2187,8 @@
// Write out any exported module macros.
bool EmittedModuleMacros = false;
- if (IsModule) {
+ // We write out exported module macros for PCH as well.
+ if (true) {
auto Leafs = PP.getLeafModuleMacros(Name);
SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end());
llvm::DenseMap<ModuleMacro*, unsigned> Visits;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20383.57673.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160518/d5c158f9/attachment.bin>
More information about the cfe-commits
mailing list