diff options
| author | Richard Trieu <rtrieu@google.com> | 2018-05-29 22:43:00 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2018-05-29 22:43:00 +0000 |
| commit | e69acc5d8fd373686f1cb6635d600d160872d43d (patch) | |
| tree | 4d7ef71f846418d13178ed793856affe23725b8d /clang/lib/Sema/SemaDecl.cpp | |
| parent | dd38d931987aceeabe51ed459f4a27aeec82df14 (diff) | |
| download | bcm5719-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
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 11 |
1 files changed, 6 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. |

