Author: rtrieu Date: Tue May 29 15:43:00 2018 New Revision: 333471 URL: http://llvm.org/viewvc/llvm-project?rev=333471&view=rev Log: Check pointer null-ness before dereferencing it.
-Warc-repeated-use-of-weak may trigger a segmentation fault when the Decl being checked is outside of a function scope, leaving the current function info pointer null. This adds a check before using the function info. Modified: cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/SemaObjC/arc-repeated-weak.mm Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=333471&r1=333470&r2=333471&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue May 29 15:43:00 2018 @@ -10799,11 +10799,12 @@ void Sema::AddInitializerToDecl(Decl *Re // we do not warn to warn spuriously when 'x' and 'y' are on separate // paths through the function. This should be revisited if // -Wrepeated-use-of-weak is made flow-sensitive. - if ((VDecl->getType().getObjCLifetime() == Qualifiers::OCL_Strong || - VDecl->getType().isNonWeakInMRRWithObjCWeak(Context)) && - !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, - Init->getLocStart())) - getCurFunction()->markSafeWeakUse(Init); + if (FunctionScopeInfo *FSI = getCurFunction()) + if ((VDecl->getType().getObjCLifetime() == Qualifiers::OCL_Strong || + VDecl->getType().isNonWeakInMRRWithObjCWeak(Context)) && + !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, + Init->getLocStart())) + FSI->markSafeWeakUse(Init); } // The initialization is usually a full-expression. Modified: cfe/trunk/test/SemaObjC/arc-repeated-weak.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-repeated-weak.mm?rev=333471&r1=333470&r2=333471&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/arc-repeated-weak.mm (original) +++ cfe/trunk/test/SemaObjC/arc-repeated-weak.mm Tue May 29 15:43:00 2018 @@ -479,3 +479,6 @@ void foo1() { // expected-error@-2{{cast of 'E' to 'INTFPtrTy' (aka 'INTF *') is disallowed with ARC}} #endif } + +@class NSString; +static NSString* const kGlobal = @""; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits