summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Wennborg <hans@chromium.org>2019-12-02 16:25:23 +0100
committerHans Wennborg <hans@chromium.org>2019-12-04 13:13:41 +0100
commit92ce2aff680e31a726c17267e36ff13a1ef31696 (patch)
tree394f03abf97544cbfb3d967cd73e031089a05086
parent201d91daad4fe9c0b0233a2fa15f8c5fbccea2d9 (diff)
downloadbcm5719-llvm-92ce2aff680e31a726c17267e36ff13a1ef31696.tar.gz
bcm5719-llvm-92ce2aff680e31a726c17267e36ff13a1ef31696.zip
Actually delay processing DelayedDllExportClasses until the outermost class is finished (PR40006)
This was already the intention of DelayedDllExportClasses, but code such as this would break it: template<typename> struct Tmpl {}; struct Outer { struct Inner { __declspec(dllexport) Inner() = default; unsigned int x = 0; }; Tmpl<Inner> y; }; ActOnFinishCXXNonNestedClass() would get called when the instantiation of Templ<Inner> is finished, even though the compiler is still not finished with Outer, causing the compile fail. This hooks into Sema::{Push,Pop}ParsingClass() to avoid calling ActOnFinishCXXNonNestedClass() for template instantiations while a class is being parsed. Differential revision: https://reviews.llvm.org/D70905
-rw-r--r--clang/include/clang/Sema/Sema.h10
-rw-r--r--clang/lib/Parse/ParseDeclCXX.cpp2
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp2
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiate.cpp6
-rw-r--r--clang/test/CodeGenCXX/dllexport.cpp14
5 files changed, 25 insertions, 9 deletions
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bb8fd4c9c85..d666321da66 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4338,9 +4338,11 @@ public:
typedef ProcessingContextState ParsingClassState;
ParsingClassState PushParsingClass() {
+ ParsingClassDepth++;
return DelayedDiagnostics.pushUndelayed();
}
void PopParsingClass(ParsingClassState state) {
+ ParsingClassDepth--;
DelayedDiagnostics.popUndelayed(state);
}
@@ -6385,7 +6387,7 @@ public:
SourceLocation RBrac,
const ParsedAttributesView &AttrList);
void ActOnFinishCXXMemberDecls();
- void ActOnFinishCXXNonNestedClass(Decl *D);
+ void ActOnFinishCXXNonNestedClass();
void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param);
unsigned ActOnReenterTemplateScope(Scope *S, Decl *Template);
@@ -11547,6 +11549,8 @@ public:
SmallVector<CXXMethodDecl*, 4> DelayedDllExportMemberFunctions;
private:
+ int ParsingClassDepth = 0;
+
class SavePendingParsedClassStateRAII {
public:
SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); }
@@ -11556,8 +11560,6 @@ private:
"there shouldn't be any pending delayed exception spec checks");
assert(S.DelayedEquivalentExceptionSpecChecks.empty() &&
"there shouldn't be any pending delayed exception spec checks");
- assert(S.DelayedDllExportClasses.empty() &&
- "there shouldn't be any pending delayed DLL export classes");
swapSavedState();
}
@@ -11567,14 +11569,12 @@ private:
SavedOverridingExceptionSpecChecks;
decltype(DelayedEquivalentExceptionSpecChecks)
SavedEquivalentExceptionSpecChecks;
- decltype(DelayedDllExportClasses) SavedDllExportClasses;
void swapSavedState() {
SavedOverridingExceptionSpecChecks.swap(
S.DelayedOverridingExceptionSpecChecks);
SavedEquivalentExceptionSpecChecks.swap(
S.DelayedEquivalentExceptionSpecChecks);
- SavedDllExportClasses.swap(S.DelayedDllExportClasses);
}
};
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index c6ffbfc968d..fe409327bfb 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3367,7 +3367,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
// We've finished parsing everything, including default argument
// initializers.
- Actions.ActOnFinishCXXNonNestedClass(TagDecl);
+ Actions.ActOnFinishCXXNonNestedClass();
}
if (TagDecl)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 36f7bb320e0..cc3510b0d47 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11829,7 +11829,7 @@ void Sema::ActOnFinishCXXMemberDecls() {
}
}
-void Sema::ActOnFinishCXXNonNestedClass(Decl *D) {
+void Sema::ActOnFinishCXXNonNestedClass() {
referenceDLLExportedClassMethods();
if (!DelayedDllExportMemberFunctions.empty()) {
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index d75be4be988..701be0411f7 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2226,8 +2226,10 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
CheckCompletedCXXClass(Instantiation);
// Default arguments are parsed, if not instantiated. We can go instantiate
- // default arg exprs for default constructors if necessary now.
- ActOnFinishCXXNonNestedClass(Instantiation);
+ // default arg exprs for default constructors if necessary now. Unless we're
+ // parsing a class, in which case wait until that's finished.
+ if (ParsingClassDepth == 0)
+ ActOnFinishCXXNonNestedClass();
// Instantiate late parsed attributes, and attach them to their decls.
// See Sema::InstantiateAttrs
diff --git a/clang/test/CodeGenCXX/dllexport.cpp b/clang/test/CodeGenCXX/dllexport.cpp
index 6c4077a5b9a..045cb450b75 100644
--- a/clang/test/CodeGenCXX/dllexport.cpp
+++ b/clang/test/CodeGenCXX/dllexport.cpp
@@ -860,6 +860,20 @@ struct PR40006 {
};
// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::PR40006"* @"??0PR40006@InClassInits@@QAE@XZ"
+namespace pr40006 {
+// Delay emitting the method also past the instantiation of Tmpl<Inner>, i.e.
+// until the top-level class Outer is completely finished.
+template<typename> struct Tmpl {};
+struct Outer {
+ struct Inner {
+ __declspec(dllexport) Inner() = default;
+ unsigned int x = 0;
+ };
+ Tmpl<Inner> y;
+};
+// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::pr40006::Outer::Inner"* @"??0Inner@Outer@pr40006@InClassInits@@QAE@XZ"
+}
+
// PR42857: Clang would try to emit the non-trivial explicitly defaulted
// dllexport ctor twice when doing an explicit instantiation definition.
struct Qux { Qux(); };
OpenPOWER on IntegriCloud