Fix an assertion failure instantiating a constexpr function from within a -dealloc method. PR13401.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161135 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Sema/ScopeInfo.h b/include/clang/Sema/ScopeInfo.h
index 37d7cae..b4752f5 100644
--- a/include/clang/Sema/ScopeInfo.h
+++ b/include/clang/Sema/ScopeInfo.h
@@ -84,6 +84,14 @@
/// \brief Whether this function contains any indirect gotos.
bool HasIndirectGoto;
+ /// A flag that is set when parsing a -dealloc method and no [super dealloc]
+ /// call was found yet.
+ bool ObjCShouldCallSuperDealloc;
+
+ /// A flag that is set when parsing a -finalize method and no [super finalize]
+ /// call was found yet.
+ bool ObjCShouldCallSuperFinalize;
+
/// \brief Used to determine if errors occurred in this function or block.
DiagnosticErrorTrap ErrorTrap;
@@ -127,6 +135,8 @@
HasBranchProtectedScope(false),
HasBranchIntoScope(false),
HasIndirectGoto(false),
+ ObjCShouldCallSuperDealloc(false),
+ ObjCShouldCallSuperFinalize(false),
ErrorTrap(Diag) { }
virtual ~FunctionScopeInfo();
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index bce285d..c0de5f7 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -542,13 +542,6 @@
/// have been declared.
bool GlobalNewDeleteDeclared;
- /// A flag that is set when parsing a -dealloc method and no [super dealloc]
- /// call was found yet.
- bool ObjCShouldCallSuperDealloc;
- /// A flag that is set when parsing a -finalize method and no [super finalize]
- /// call was found yet.
- bool ObjCShouldCallSuperFinalize;
-
/// \brief Describes how the expressions currently being parsed are
/// evaluated at run-time, if at all.
enum ExpressionEvaluationContext {
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 0569a37..7f79f0c 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -97,8 +97,6 @@
NSArrayDecl(0), ArrayWithObjectsMethod(0),
NSDictionaryDecl(0), DictionaryWithObjectsMethod(0),
GlobalNewDeleteDeclared(false),
- ObjCShouldCallSuperDealloc(false),
- ObjCShouldCallSuperFinalize(false),
TUKind(TUKind),
NumSFINAEErrors(0), InFunctionDeclarator(0),
AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 0063a37..eb5b0cd 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -7715,22 +7715,24 @@
if (Body)
computeNRVO(Body, getCurFunction());
}
- if (ObjCShouldCallSuperDealloc) {
+ if (getCurFunction()->ObjCShouldCallSuperDealloc) {
Diag(MD->getLocEnd(), diag::warn_objc_missing_super_dealloc);
- ObjCShouldCallSuperDealloc = false;
+ getCurFunction()->ObjCShouldCallSuperDealloc = false;
}
- if (ObjCShouldCallSuperFinalize) {
+ if (getCurFunction()->ObjCShouldCallSuperFinalize) {
Diag(MD->getLocEnd(), diag::warn_objc_missing_super_finalize);
- ObjCShouldCallSuperFinalize = false;
+ getCurFunction()->ObjCShouldCallSuperFinalize = false;
}
} else {
return 0;
}
- assert(!ObjCShouldCallSuperDealloc && "This should only be set for "
- "ObjC methods, which should have been handled in the block above.");
- assert(!ObjCShouldCallSuperFinalize && "This should only be set for "
- "ObjC methods, which should have been handled in the block above.");
+ assert(!getCurFunction()->ObjCShouldCallSuperDealloc &&
+ "This should only be set for ObjC methods, which should have been "
+ "handled in the block above.");
+ assert(!getCurFunction()->ObjCShouldCallSuperFinalize &&
+ "This should only be set for ObjC methods, which should have been "
+ "handled in the block above.");
// Verify and clean out per-function state.
if (Body) {
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 52ca335..a1014f7 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -380,11 +380,11 @@
// Finally, in ActOnFinishFunctionBody() (SemaDecl), warn if flag is set.
// Only do this if the current class actually has a superclass.
if (IC->getSuperClass()) {
- ObjCShouldCallSuperDealloc =
+ getCurFunction()->ObjCShouldCallSuperDealloc =
!(Context.getLangOpts().ObjCAutoRefCount ||
Context.getLangOpts().getGC() == LangOptions::GCOnly) &&
MDecl->getMethodFamily() == OMF_dealloc;
- ObjCShouldCallSuperFinalize =
+ getCurFunction()->ObjCShouldCallSuperFinalize =
Context.getLangOpts().getGC() != LangOptions::NonGC &&
MDecl->getMethodFamily() == OMF_finalize;
}
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 638a30f..0aabf8b 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -1778,9 +1778,9 @@
// is acting as a keyword.
if (Method->isInstanceMethod()) {
if (Sel.getMethodFamily() == OMF_dealloc)
- ObjCShouldCallSuperDealloc = false;
+ getCurFunction()->ObjCShouldCallSuperDealloc = false;
if (Sel.getMethodFamily() == OMF_finalize)
- ObjCShouldCallSuperFinalize = false;
+ getCurFunction()->ObjCShouldCallSuperFinalize = false;
// Since we are in an instance method, this is an instance
// message to the superclass instance.
diff --git a/test/SemaObjCXX/warn-missing-super.mm b/test/SemaObjCXX/warn-missing-super.mm
new file mode 100644
index 0000000..cd2a6cc
--- /dev/null
+++ b/test/SemaObjCXX/warn-missing-super.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// PR13401
+
+__attribute((objc_root_class)) @interface NSObject
+@end
+
+@interface Dummy : NSObject
+@end
+
+template<typename T> struct shared_ptr {
+ constexpr shared_ptr() {}
+};
+
+@implementation Dummy
+- (void)dealloc
+{
+ constexpr shared_ptr<int> dummy;
+} // expected-warning {{method possibly missing a [super dealloc] call}}
+@end