[cfe-commits] r161135 - in /cfe/trunk: include/clang/Sema/ScopeInfo.h include/clang/Sema/Sema.h lib/Sema/Sema.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjCXX/warn-missing-super.mm

Jordan Rose jordan_rose at apple.com
Wed Aug 1 20:19:51 PDT 2012


This is unrelated to the commit itself, but why do we have two separate flags for [super dealloc] and [super finalize]? We can easily figure out which method we're in from the decl.


On Aug 1, 2012, at 2:02 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> Author: efriedma
> Date: Wed Aug  1 16:02:59 2012
> New Revision: 161135
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=161135&view=rev
> Log:
> Fix an assertion failure instantiating a constexpr function from within a -dealloc method.  PR13401.
> 
> 
> Added:
>    cfe/trunk/test/SemaObjCXX/warn-missing-super.mm
> Modified:
>    cfe/trunk/include/clang/Sema/ScopeInfo.h
>    cfe/trunk/include/clang/Sema/Sema.h
>    cfe/trunk/lib/Sema/Sema.cpp
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
>    cfe/trunk/lib/Sema/SemaExprObjC.cpp
> 
> Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=161135&r1=161134&r2=161135&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
> +++ cfe/trunk/include/clang/Sema/ScopeInfo.h Wed Aug  1 16:02:59 2012
> @@ -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();
> 
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=161135&r1=161134&r2=161135&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Wed Aug  1 16:02:59 2012
> @@ -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 {
> 
> Modified: cfe/trunk/lib/Sema/Sema.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=161135&r1=161134&r2=161135&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.cpp (original)
> +++ cfe/trunk/lib/Sema/Sema.cpp Wed Aug  1 16:02:59 2012
> @@ -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),
> 
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=161135&r1=161134&r2=161135&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Aug  1 16:02:59 2012
> @@ -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) {
> 
> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=161135&r1=161134&r2=161135&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Aug  1 16:02:59 2012
> @@ -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;
>     }
> 
> Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=161135&r1=161134&r2=161135&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Aug  1 16:02:59 2012
> @@ -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.
> 
> Added: cfe/trunk/test/SemaObjCXX/warn-missing-super.mm
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/warn-missing-super.mm?rev=161135&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaObjCXX/warn-missing-super.mm (added)
> +++ cfe/trunk/test/SemaObjCXX/warn-missing-super.mm Wed Aug  1 16:02:59 2012
> @@ -0,0 +1,19 @@
> +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
> +// PR13401
> +
> +__attribute((objc_root_class)) @interface NSObject
> + at end
> +
> + at interface Dummy : NSObject
> + at end
> +
> +template<typename T> struct shared_ptr {
> +  constexpr shared_ptr() {}
> +};
> +
> + at implementation Dummy
> +- (void)dealloc
> +{
> +	constexpr shared_ptr<int> dummy;
> +} // expected-warning {{method possibly missing a [super dealloc] call}}
> + at end
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list