r213498 - [modules] Fix some of the confusion when computing the override set for a macro
Richard Smith
richard-llvm at metafoo.co.uk
Sun Jul 20 21:10:41 PDT 2014
Author: rsmith
Date: Sun Jul 20 23:10:40 2014
New Revision: 213498
URL: http://llvm.org/viewvc/llvm-project?rev=213498&view=rev
Log:
[modules] Fix some of the confusion when computing the override set for a macro
introduced by finalization. This is still not entirely correct; more fixes to
follow.
Added:
cfe/trunk/test/Modules/Inputs/macro-hiding/e1.h
cfe/trunk/test/Modules/Inputs/macro-hiding/e2.h
cfe/trunk/test/Modules/macro-reexport/
cfe/trunk/test/Modules/macro-reexport/a1.h
cfe/trunk/test/Modules/macro-reexport/a2.h
cfe/trunk/test/Modules/macro-reexport/b1.h
cfe/trunk/test/Modules/macro-reexport/b2.h
cfe/trunk/test/Modules/macro-reexport/c1.h
cfe/trunk/test/Modules/macro-reexport/d1.h
cfe/trunk/test/Modules/macro-reexport/d2.h
cfe/trunk/test/Modules/macro-reexport/macro-reexport.cpp
cfe/trunk/test/Modules/macro-reexport/module.modulemap
Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Modules/Inputs/macro-hiding/module.modulemap
cfe/trunk/test/Modules/macro-hiding.cpp
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=213498&r1=213497&r2=213498&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sun Jul 20 23:10:40 2014
@@ -3323,8 +3323,7 @@ static void moveMethodToBackOfGlobalList
void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner,
bool FromFinalization) {
// FIXME: Only do this if Owner->NameVisibility == AllVisible.
- for (unsigned I = 0, N = Names.HiddenDecls.size(); I != N; ++I) {
- Decl *D = Names.HiddenDecls[I];
+ for (Decl *D : Names.HiddenDecls) {
bool wasHidden = D->Hidden;
D->Hidden = false;
@@ -3337,10 +3336,8 @@ void ASTReader::makeNamesVisible(const H
assert((FromFinalization || Owner->NameVisibility >= Module::MacrosVisible) &&
"nothing to make visible?");
- for (HiddenMacrosMap::const_iterator I = Names.HiddenMacros.begin(),
- E = Names.HiddenMacros.end();
- I != E; ++I)
- installImportedMacro(I->first, I->second, Owner, FromFinalization);
+ for (const auto &Macro : Names.HiddenMacros)
+ installImportedMacro(Macro.first, Macro.second, Owner, FromFinalization);
}
void ASTReader::makeModuleVisible(Module *Mod,
@@ -3374,9 +3371,12 @@ void ASTReader::makeModuleVisible(Module
// mark them as visible.
HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod);
if (Hidden != HiddenNamesMap.end()) {
- makeNamesVisible(Hidden->second, Hidden->first,
- /*FromFinalization*/false);
+ auto HiddenNames = std::move(*Hidden);
HiddenNamesMap.erase(Hidden);
+ makeNamesVisible(HiddenNames.second, HiddenNames.first,
+ /*FromFinalization*/false);
+ assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() &&
+ "making names visible added hidden names");
}
// Push any exported modules onto the stack to be marked as visible.
@@ -3899,12 +3899,12 @@ void ASTReader::InitializeContext() {
}
void ASTReader::finalizeForWriting() {
- for (HiddenNamesMapType::iterator Hidden = HiddenNamesMap.begin(),
- HiddenEnd = HiddenNamesMap.end();
- Hidden != HiddenEnd; ++Hidden) {
- makeNamesVisible(Hidden->second, Hidden->first, /*FromFinalization*/true);
+ while (!HiddenNamesMap.empty()) {
+ auto HiddenNames = std::move(*HiddenNamesMap.begin());
+ HiddenNamesMap.erase(HiddenNamesMap.begin());
+ makeNamesVisible(HiddenNames.second, HiddenNames.first,
+ /*FromFinalization*/true);
}
- HiddenNamesMap.clear();
}
/// \brief Given a cursor at the start of an AST file, scan ahead and drop the
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=213498&r1=213497&r2=213498&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sun Jul 20 23:10:40 2014
@@ -3034,16 +3034,25 @@ class ASTIdentifierTableTrait {
MacroDirective *getPublicSubmoduleMacro(MacroDirective *MD,
SubmoduleID &ModID,
OverriddenList &Overridden) {
+ Overridden.clear();
if (!MD)
return nullptr;
- Overridden.clear();
SubmoduleID OrigModID = ModID;
Optional<bool> IsPublic;
for (; MD; MD = MD->getPrevious()) {
SubmoduleID ThisModID = getSubmoduleID(MD);
if (ThisModID == 0) {
IsPublic = Optional<bool>();
+
+ // If we have no directive location, this macro was installed when
+ // finalizing the ASTReader.
+ if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD))
+ if (DefMD->getInfo()->getOwningModuleID())
+ return MD;
+ // Skip imports that only produce #undefs for now.
+ // FIXME: We should still re-export them!
+
continue;
}
if (ThisModID != ModID) {
@@ -3068,7 +3077,7 @@ class ASTIdentifierTableTrait {
else
SourceID = Writer.inferSubmoduleIDFromLocation(DefLoc);
}
- if (SourceID != OrigModID)
+ if (OrigModID && SourceID != OrigModID)
Overridden.push_back(SourceID);
}
@@ -3095,17 +3104,7 @@ class ASTIdentifierTableTrait {
}
SubmoduleID getSubmoduleID(MacroDirective *MD) {
- if (MD->getLocation().isValid())
- return Writer.inferSubmoduleIDFromLocation(MD->getLocation());
-
- // If we have no directive location, this macro was installed when
- // finalizing the ASTReader.
- if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD))
- return DefMD->getInfo()->getOwningModuleID();
-
- // Skip imports that only produce #undefs for now.
- // FIXME: We should still re-export them!
- return 0;
+ return Writer.inferSubmoduleIDFromLocation(MD->getLocation());
}
public:
Added: cfe/trunk/test/Modules/Inputs/macro-hiding/e1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macro-hiding/e1.h?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macro-hiding/e1.h (added)
+++ cfe/trunk/test/Modules/Inputs/macro-hiding/e1.h Sun Jul 20 23:10:40 2014
@@ -0,0 +1 @@
+#include "a1.h"
Added: cfe/trunk/test/Modules/Inputs/macro-hiding/e2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macro-hiding/e2.h?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macro-hiding/e2.h (added)
+++ cfe/trunk/test/Modules/Inputs/macro-hiding/e2.h Sun Jul 20 23:10:40 2014
@@ -0,0 +1,2 @@
+#include "a1.h"
+inline void e1() { assert(true); }
Modified: cfe/trunk/test/Modules/Inputs/macro-hiding/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/macro-hiding/module.modulemap?rev=213498&r1=213497&r2=213498&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/macro-hiding/module.modulemap (original)
+++ cfe/trunk/test/Modules/Inputs/macro-hiding/module.modulemap Sun Jul 20 23:10:40 2014
@@ -12,3 +12,7 @@ module c {
module d {
module d1 { header "d1.h" export * }
}
+module e {
+ module e1 { header "e1.h" export * }
+ module e2 { header "e2.h" export * }
+}
Modified: cfe/trunk/test/Modules/macro-hiding.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-hiding.cpp?rev=213498&r1=213497&r2=213498&view=diff
==============================================================================
--- cfe/trunk/test/Modules/macro-hiding.cpp (original)
+++ cfe/trunk/test/Modules/macro-hiding.cpp Sun Jul 20 23:10:40 2014
@@ -62,6 +62,8 @@
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/macro-hiding %s -DA1 -DA2 -DB1 -DB2 -DD1
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/macro-hiding %s -DA1 -DA2 -DB1 -DB2 -DC1
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/macro-hiding %s -DA1 -DA2 -DB1 -DB2 -DC1 -DD1
+//
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/macro-hiding %s -DE1
#ifdef A1
#include "a1.h"
@@ -87,7 +89,15 @@
#include "d1.h"
#endif
-#if defined(A1) || defined(B2) || defined(C1) || defined(D1)
+#ifdef E1
+#include "e1.h"
+#endif
+
+#ifdef E2
+#include "e2.h"
+#endif
+
+#if defined(A1) || defined(B2) || defined(C1) || defined(D1) || defined(E1) || defined(E2)
void h() { assert(true); }
#else
void assert() {}
Added: cfe/trunk/test/Modules/macro-reexport/a1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/a1.h?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/macro-reexport/a1.h (added)
+++ cfe/trunk/test/Modules/macro-reexport/a1.h Sun Jul 20 23:10:40 2014
@@ -0,0 +1 @@
+#define assert(x) a
Added: cfe/trunk/test/Modules/macro-reexport/a2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/a2.h?rev=213498&view=auto
==============================================================================
(empty)
Added: cfe/trunk/test/Modules/macro-reexport/b1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/b1.h?rev=213498&view=auto
==============================================================================
(empty)
Added: cfe/trunk/test/Modules/macro-reexport/b2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/b2.h?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/macro-reexport/b2.h (added)
+++ cfe/trunk/test/Modules/macro-reexport/b2.h Sun Jul 20 23:10:40 2014
@@ -0,0 +1,2 @@
+#include "a2.h"
+#define assert(x) b
Added: cfe/trunk/test/Modules/macro-reexport/c1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/c1.h?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/macro-reexport/c1.h (added)
+++ cfe/trunk/test/Modules/macro-reexport/c1.h Sun Jul 20 23:10:40 2014
@@ -0,0 +1,2 @@
+#include "b1.h"
+#define assert(x) c
Added: cfe/trunk/test/Modules/macro-reexport/d1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/d1.h?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/macro-reexport/d1.h (added)
+++ cfe/trunk/test/Modules/macro-reexport/d1.h Sun Jul 20 23:10:40 2014
@@ -0,0 +1,2 @@
+#include "c1.h"
+#define assert(x) d
Added: cfe/trunk/test/Modules/macro-reexport/d2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/d2.h?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/macro-reexport/d2.h (added)
+++ cfe/trunk/test/Modules/macro-reexport/d2.h Sun Jul 20 23:10:40 2014
@@ -0,0 +1 @@
+#include "b2.h"
Added: cfe/trunk/test/Modules/macro-reexport/macro-reexport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/macro-reexport.cpp?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/macro-reexport/macro-reexport.cpp (added)
+++ cfe/trunk/test/Modules/macro-reexport/macro-reexport.cpp Sun Jul 20 23:10:40 2014
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fsyntax-only -DD2 -I. %s -fmodules-cache-path=%t -verify
+// RUN: %clang_cc1 -fsyntax-only -DD2 -I. -fmodules %s -fmodules-cache-path=%t -verify
+// RUN: %clang_cc1 -fsyntax-only -DC1 -I. %s -fmodules-cache-path=%t -verify
+// RUN: %clang_cc1 -fsyntax-only -DC1 -I. -fmodules %s -fmodules-cache-path=%t -verify
+
+#ifdef D2
+#include "d2.h"
+void f() { return assert(true); } // expected-error {{undeclared identifier 'b'}}
+#else
+#include "c1.h"
+void f() { return assert(true); } // expected-error {{undeclared identifier 'c'}}
+#endif
Added: cfe/trunk/test/Modules/macro-reexport/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/macro-reexport/module.modulemap?rev=213498&view=auto
==============================================================================
--- cfe/trunk/test/Modules/macro-reexport/module.modulemap (added)
+++ cfe/trunk/test/Modules/macro-reexport/module.modulemap Sun Jul 20 23:10:40 2014
@@ -0,0 +1,15 @@
+module b {
+ module b2 { header "b2.h" export * }
+ module b1 { header "b1.h" export * }
+}
+module a {
+ module a1 { header "a1.h" export * }
+ module a2 { header "a2.h" export * }
+}
+module c {
+ module c1 { header "c1.h" export * }
+}
+module d {
+ module d1 { header "d1.h" export * }
+ module d2 { header "d2.h" export * }
+}
More information about the cfe-commits
mailing list