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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203063
91177308-0d34-0410-b5e6-
96231b3b80d8
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.
// 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
#define TOP_OTHER_REDEF2 2
#define TOP_OTHER_DEF_RIGHT_UNDEF void
+
+#define TOP_REDEF_IN_SUBMODULES 0
--- /dev/null
+#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
--- /dev/null
+#include "macros_top_b.h"
+#undef TOP_REDEF_IN_SUBMODULES
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"
int n2 = TOP_OTHER_REDEF2; // ok
int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
+
+int top_redef_in_submodules = TOP_REDEF_IN_SUBMODULES;
+@import macros_top.c;
+void test2() {
+ int TOP_REDEF_IN_SUBMODULES = top_redef_in_submodules;
+}