r203063 - Fix crash if a submodule overrides one of its own macros, and add support for
Richard Smith
richard-llvm at metafoo.co.uk
Wed Mar 5 19:16:28 PST 2014
Author: rsmith
Date: Wed Mar 5 21:16:27 2014
New Revision: 203063
URL: http://llvm.org/viewvc/llvm-project?rev=203063&view=rev
Log:
Fix crash if a submodule overrides one of its own macros, and add support for
submodule macro overriding within the same top-level module (necessary for the
testcase to be remotely reasonable). Incidentally reduces the number of libc++
testsuite regressions with modules enabled from 7 to 6.
Added:
cfe/trunk/test/Modules/Inputs/macros_top_b.h
cfe/trunk/test/Modules/Inputs/macros_top_c.h
Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Modules/Inputs/macros_top.h
cfe/trunk/test/Modules/Inputs/module.map
cfe/trunk/test/Modules/macros2.c
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=203063&r1=203062&r2=203063&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Mar 5 21:16:27 2014
@@ -1679,8 +1679,9 @@ void ASTReader::removeOverriddenMacros(I
HiddenNames &Hidden = HiddenNamesMap[Owner];
HiddenMacrosMap::iterator HI = Hidden.HiddenMacros.find(II);
if (HI != Hidden.HiddenMacros.end()) {
- removeOverriddenMacros(II, Ambig, HI->second->getOverriddenSubmodules());
+ auto SubOverrides = HI->second->getOverriddenSubmodules();
Hidden.HiddenMacros.erase(HI);
+ removeOverriddenMacros(II, Ambig, SubOverrides);
}
// If this macro is already in our list of conflicts, remove it from there.
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=203063&r1=203062&r2=203063&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Mar 5 21:16:27 2014
@@ -3021,9 +3021,19 @@ class ASTIdentifierTableTrait {
// We can't do that currently, because a #include of a different submodule
// of the same module just leaks through macros instead of providing new
// DefMacroDirectives for them.
- if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD))
- if (SubmoduleID SourceID = DefMD->getInfo()->getOwningModuleID())
+ if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD)) {
+ // Figure out which submodule the macro was originally defined within.
+ SubmoduleID SourceID = DefMD->getInfo()->getOwningModuleID();
+ if (!SourceID) {
+ SourceLocation DefLoc = DefMD->getInfo()->getDefinitionLoc();
+ if (DefLoc == MD->getLocation())
+ SourceID = ThisModID;
+ else
+ SourceID = Writer.inferSubmoduleIDFromLocation(DefLoc);
+ }
+ if (SourceID != OrigModID)
Overridden.push_back(SourceID);
+ }
// We are looking for a definition in a different submodule than the one
// that we started with. If a submodule has re-definitions of the same
Modified: cfe/trunk/test/Modules/Inputs/macros_top.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macros_top.h?rev=203063&r1=203062&r2=203063&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macros_top.h (original)
+++ cfe/trunk/test/Modules/Inputs/macros_top.h Wed Mar 5 21:16:27 2014
@@ -20,3 +20,5 @@
#define TOP_OTHER_REDEF2 2
#define TOP_OTHER_DEF_RIGHT_UNDEF void
+
+#define TOP_REDEF_IN_SUBMODULES 0
Added: cfe/trunk/test/Modules/Inputs/macros_top_b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macros_top_b.h?rev=203063&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macros_top_b.h (added)
+++ cfe/trunk/test/Modules/Inputs/macros_top_b.h Wed Mar 5 21:16:27 2014
@@ -0,0 +1,5 @@
+#include "macros_top.h"
+#undef TOP_REDEF_IN_SUBMODULES
+#define TOP_REDEF_IN_SUBMODULES 1
+#undef TOP_REDEF_IN_SUBMODULES
+#define TOP_REDEF_IN_SUBMODULES 2
Added: cfe/trunk/test/Modules/Inputs/macros_top_c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macros_top_c.h?rev=203063&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macros_top_c.h (added)
+++ cfe/trunk/test/Modules/Inputs/macros_top_c.h Wed Mar 5 21:16:27 2014
@@ -0,0 +1,2 @@
+#include "macros_top_b.h"
+#undef TOP_REDEF_IN_SUBMODULES
Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=203063&r1=203062&r2=203063&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Wed Mar 5 21:16:27 2014
@@ -23,6 +23,8 @@ module module_private_left { header "mod
module module_private_right { header "module_private_right.h" }
module macros_top {
header "macros_top.h"
+ explicit module b { header "macros_top_b.h" }
+ explicit module c { header "macros_top_c.h" }
}
module macros_left {
header "macros_left.h"
Modified: cfe/trunk/test/Modules/macros2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macros2.c?rev=203063&r1=203062&r2=203063&view=diff
==============================================================================
--- cfe/trunk/test/Modules/macros2.c (original)
+++ cfe/trunk/test/Modules/macros2.c Wed Mar 5 21:16:27 2014
@@ -75,3 +75,9 @@ int n1 = TOP_OTHER_REDEF1; // expected-w
int n2 = TOP_OTHER_REDEF2; // ok
int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
+
+int top_redef_in_submodules = TOP_REDEF_IN_SUBMODULES;
+ at import macros_top.c;
+void test2() {
+ int TOP_REDEF_IN_SUBMODULES = top_redef_in_submodules;
+}
More information about the cfe-commits
mailing list