mirror of https://github.com/microsoft/clang.git
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333471 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
77a37b6cca
commit
67a7d38746
|
@ -10799,11 +10799,12 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
|
|||
// 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.
|
||||
|
|
|
@ -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 = @"";
|
||||
|
|
Loading…
Reference in New Issue