summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2018-05-29 22:43:00 +0000
committerRichard Trieu <rtrieu@google.com>2018-05-29 22:43:00 +0000
commite69acc5d8fd373686f1cb6635d600d160872d43d (patch)
tree4d7ef71f846418d13178ed793856affe23725b8d
parentdd38d931987aceeabe51ed459f4a27aeec82df14 (diff)
downloadbcm5719-llvm-e69acc5d8fd373686f1cb6635d600d160872d43d.tar.gz
bcm5719-llvm-e69acc5d8fd373686f1cb6635d600d160872d43d.zip
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. llvm-svn: 333471
-rw-r--r--clang/lib/Sema/SemaDecl.cpp11
-rw-r--r--clang/test/SemaObjC/arc-repeated-weak.mm3
2 files changed, 9 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e8e3faf7578..9a6a286db78 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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.
diff --git a/clang/test/SemaObjC/arc-repeated-weak.mm b/clang/test/SemaObjC/arc-repeated-weak.mm
index 37b2123ec1c..d153eb9a52e 100644
--- a/clang/test/SemaObjC/arc-repeated-weak.mm
+++ b/clang/test/SemaObjC/arc-repeated-weak.mm
@@ -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 = @"";
OpenPOWER on IntegriCloud