Skip to content

Commit b3fc9df

Browse files
committedMay 7, 2019
[analyzer] Fix a crash when doing RVO from within blocks.
When looking for the location context of the call site, unwrap block invocation contexts because they are attached to the current AnalysisDeclContext while what we need is the previous AnalysisDeclContext. Differential Revision: https://reviews.llvm.org/D61545 llvm-svn: 360202
1 parent 2e977c0 commit b3fc9df

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ std::pair<ProgramStateRef, SVal> ExprEngine::prepareForObjectConstruction(
196196
// able to find construction context at all.
197197
break;
198198
}
199+
if (isa<BlockInvocationContext>(CallerLCtx)) {
200+
// Unwrap block invocation contexts. They're mostly part of
201+
// the current stack frame.
202+
CallerLCtx = CallerLCtx->getParent();
203+
assert(!isa<BlockInvocationContext>(CallerLCtx));
204+
}
199205
return prepareForObjectConstruction(
200206
cast<Expr>(SFC->getCallSite()), State, CallerLCtx,
201207
RTC->getConstructionContext(), CallOpts);

‎clang/test/Analysis/copy-elision.mm

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core -fblocks -verify %s
2+
3+
// expected-no-diagnostics
4+
5+
namespace block_rvo_crash {
6+
struct A {};
7+
8+
A getA();
9+
void use(A a) {}
10+
11+
void foo() {
12+
// This used to crash when finding construction context for getA()
13+
// (which is use()'s argument due to RVO).
14+
use(^{
15+
return getA(); // no-crash
16+
}());
17+
}
18+
} // namespace block_rvo_crash

0 commit comments

Comments
 (0)