diff options
author | Reid Kleckner <rnk@google.com> | 2018-03-12 21:43:02 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-03-12 21:43:02 +0000 |
commit | 49c32abef3432696ce360d7576ea09a5ae08e7a7 (patch) | |
tree | fc94b0b3a5de71ac8c0b42d11a08bef70e8a003b /lib/Sema/SemaStmt.cpp | |
parent | 07fe671aaad3e93b9f7178ae1309304a73a3b3bf (diff) | |
download | clang-49c32abef3432696ce360d7576ea09a5ae08e7a7.tar.gz |
Re-land "[Sema] Make getCurFunction() return null outside function parsing"
This relands r326965.
There was a null dereference in typo correction that was triggered in
Sema/diagnose_if.c. We are not always in a function scope when doing
typo correction. The fix is to add a null check.
LLVM's optimizer made it hard to find this bug. I wrote it up in a
not-very-well-editted blog post here:
http://qinsb.blogspot.com/2018/03/ub-will-delete-your-null-checks.html
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327334 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 08af3fa676..918dc92f2b 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -557,7 +557,7 @@ StmtResult Sema::BuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, return StmtError(); if (IsConstexpr || isa<ObjCAvailabilityCheckExpr>(Cond.get().second)) - getCurFunction()->setHasBranchProtectedScope(); + setFunctionHasBranchProtectedScope(); DiagnoseUnusedExprResult(thenStmt); DiagnoseUnusedExprResult(elseStmt); @@ -688,7 +688,7 @@ StmtResult Sema::ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, if (Cond.isInvalid()) return StmtError(); - getCurFunction()->setHasBranchIntoScope(); + setFunctionHasBranchIntoScope(); SwitchStmt *SS = new (Context) SwitchStmt(Context, InitStmt, Cond.get().first, Cond.get().second); @@ -1873,7 +1873,7 @@ StmtResult Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc) { - getCurFunction()->setHasBranchProtectedScope(); + setFunctionHasBranchProtectedScope(); ExprResult CollectionExprResult = CheckObjCForCollectionOperand(ForLoc, collection); @@ -2784,7 +2784,7 @@ StmtResult Sema::FinishCXXForRangeStmt(Stmt *S, Stmt *B) { StmtResult Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl) { - getCurFunction()->setHasBranchIntoScope(); + setFunctionHasBranchIntoScope(); TheDecl->markUsed(Context); return new (Context) GotoStmt(TheDecl, GotoLoc, LabelLoc); } @@ -2811,7 +2811,7 @@ Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, return StmtError(); E = ExprRes.get(); - getCurFunction()->setHasIndirectGoto(); + setFunctionHasIndirectGoto(); return new (Context) IndirectGotoStmt(GotoLoc, StarLoc, E); } @@ -3607,7 +3607,7 @@ Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, if (!getLangOpts().ObjCExceptions) Diag(AtLoc, diag::err_objc_exceptions_disabled) << "@try"; - getCurFunction()->setHasBranchProtectedScope(); + setFunctionHasBranchProtectedScope(); unsigned NumCatchStmts = CatchStmts.size(); return ObjCAtTryStmt::Create(Context, AtLoc, Try, CatchStmts.data(), NumCatchStmts, Finally); @@ -3698,7 +3698,7 @@ StmtResult Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SyncExpr, Stmt *SyncBody) { // We can't jump into or indirect-jump out of a @synchronized block. - getCurFunction()->setHasBranchProtectedScope(); + setFunctionHasBranchProtectedScope(); return new (Context) ObjCAtSynchronizedStmt(AtLoc, SyncExpr, SyncBody); } @@ -3714,7 +3714,7 @@ Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, StmtResult Sema::ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body) { - getCurFunction()->setHasBranchProtectedScope(); + setFunctionHasBranchProtectedScope(); return new (Context) ObjCAutoreleasePoolStmt(AtLoc, Body); } |