r360202 - [analyzer] Fix a crash when doing RVO from within blocks.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue May 7 15:33:15 PDT 2019


Author: dergachev
Date: Tue May  7 15:33:13 2019
New Revision: 360202

URL: http://llvm.org/viewvc/llvm-project?rev=360202&view=rev
Log:
[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

Added:
    cfe/trunk/test/Analysis/copy-elision.mm
Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=360202&r1=360201&r2=360202&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Tue May  7 15:33:13 2019
@@ -196,6 +196,12 @@ std::pair<ProgramStateRef, SVal> ExprEng
           // able to find construction context at all.
           break;
         }
+        if (isa<BlockInvocationContext>(CallerLCtx)) {
+          // Unwrap block invocation contexts. They're mostly part of
+          // the current stack frame.
+          CallerLCtx = CallerLCtx->getParent();
+          assert(!isa<BlockInvocationContext>(CallerLCtx));
+        }
         return prepareForObjectConstruction(
             cast<Expr>(SFC->getCallSite()), State, CallerLCtx,
             RTC->getConstructionContext(), CallOpts);

Added: cfe/trunk/test/Analysis/copy-elision.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/copy-elision.mm?rev=360202&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/copy-elision.mm (added)
+++ cfe/trunk/test/Analysis/copy-elision.mm Tue May  7 15:33:13 2019
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -fblocks -verify %s
+
+// expected-no-diagnostics
+
+namespace block_rvo_crash {
+struct A {};
+
+A getA();
+void use(A a) {}
+
+void foo() {
+  // This used to crash when finding construction context for getA()
+  // (which is use()'s argument due to RVO).
+  use(^{
+    return getA();  // no-crash
+  }());
+}
+} // namespace block_rvo_crash




More information about the cfe-commits mailing list