]> granicus.if.org Git - clang/commitdiff
Fix crash if a submodule overrides one of its own macros, and add support for
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 6 Mar 2014 03:16:27 +0000 (03:16 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 6 Mar 2014 03:16:27 +0000 (03:16 +0000)
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

lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp
test/Modules/Inputs/macros_top.h
test/Modules/Inputs/macros_top_b.h [new file with mode: 0644]
test/Modules/Inputs/macros_top_c.h [new file with mode: 0644]
test/Modules/Inputs/module.map
test/Modules/macros2.c

index 99361d207e8d5f756c96fd72ddd1cc3b6a5658d4..cc218a2807bf3195c7bf0d550d45fd0f36f5dadd 100644 (file)
@@ -1679,8 +1679,9 @@ void ASTReader::removeOverriddenMacros(IdentifierInfo *II,
     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.
index 3365d1ee0c54aabe7c959b434746bf603ab5823f..2769b9fda11775df9551bbed8650bfa9846d68c3 100644 (file)
@@ -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
index 2955471a8fa0e1d25ed2dd5fea70a288f23a7c1f..10935043e2a166406c9dda4640aae4a5a6a94c5d 100644 (file)
@@ -20,3 +20,5 @@
 #define TOP_OTHER_REDEF2 2
 
 #define TOP_OTHER_DEF_RIGHT_UNDEF void
+
+#define TOP_REDEF_IN_SUBMODULES 0
diff --git a/test/Modules/Inputs/macros_top_b.h b/test/Modules/Inputs/macros_top_b.h
new file mode 100644 (file)
index 0000000..cfee17c
--- /dev/null
@@ -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
diff --git a/test/Modules/Inputs/macros_top_c.h b/test/Modules/Inputs/macros_top_c.h
new file mode 100644 (file)
index 0000000..aee8246
--- /dev/null
@@ -0,0 +1,2 @@
+#include "macros_top_b.h"
+#undef TOP_REDEF_IN_SUBMODULES
index 67b3a5a0ebe323b01193b8c23887d7a83332b6e7..c4727d74918a19e7dfc626c58c4e8b9ed7afbb17 100644 (file)
@@ -23,6 +23,8 @@ module module_private_left { header "module_private_left.h" }
 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" 
index 87b4c97d96d723e1fec16b831f882450d56d1b75..c4c8059011ccd18787b4097250a4a3cbc91094a3 100644 (file)
@@ -75,3 +75,9 @@ int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TO
 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;
+}