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 | 87a3180343481a051ca3130969cfbceb41aee96f (patch) | |
tree | e352bfc508e21e647fb94234ec2b07c0dbc8a9c4 /clang/lib/Sema/SemaLookup.cpp | |
parent | 7147f32ec52939f70d54d977a38cedb78c6b94af (diff) | |
download | bcm5719-llvm-87a3180343481a051ca3130969cfbceb41aee96f.tar.gz bcm5719-llvm-87a3180343481a051ca3130969cfbceb41aee96f.zip |
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
llvm-svn: 327334
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index dd54fb4ad9e..692ce111aac 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -4529,7 +4529,8 @@ static void AddKeywordsToConsumer(Sema &SemaRef, if (S && S->getContinueParent()) Consumer.addKeywordResult("continue"); - if (!SemaRef.getCurFunction()->SwitchStack.empty()) { + if (SemaRef.getCurFunction() && + !SemaRef.getCurFunction()->SwitchStack.empty()) { Consumer.addKeywordResult("case"); Consumer.addKeywordResult("default"); } |