diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 4765db074115..fc31d3c1fb57 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -141,6 +141,8 @@ const Expr *bugreporter::getDerefExpr(const Stmt *S) { E = AE->getBase(); } else if (const auto *PE = dyn_cast(E)) { E = PE->getSubExpr(); + } else if (const auto *EWC = dyn_cast(E)) { + E = EWC->getSubExpr(); } else { // Other arbitrary stuff. break; diff --git a/clang/test/Analysis/inlining/inline-defensive-checks.cpp b/clang/test/Analysis/inlining/inline-defensive-checks.cpp index eaae8d2ae28f..6fb0e1cd70b0 100644 --- a/clang/test/Analysis/inlining/inline-defensive-checks.cpp +++ b/clang/test/Analysis/inlining/inline-defensive-checks.cpp @@ -84,3 +84,20 @@ void testRefToField(Bar *b) { int &x = b->x; // no-warning x = 5; } + +namespace get_deref_expr_with_cleanups { +struct S { +~S(); +}; +S *conjure(); +// The argument won't be used, but it'll cause cleanups +// to appear around the call site. +S *get_conjured(S _) { + S *s = conjure(); + if (s) {} + return s; +} +void test_conjured() { + S &s = *get_conjured(S()); // no-warning +} +} // namespace get_deref_expr_with_cleanups