[PATCH] D102835: [analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr
Tomasz KamiĆski via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 20 02:49:27 PDT 2021
tomasz-kaminski-sonarsource created this revision.
tomasz-kaminski-sonarsource added a reviewer: dcoughlin.
Herald added subscribers: manas, steakhal, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
tomasz-kaminski-sonarsource requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Previously, information about ConstructionContextLayer was not propagated thru causing the expression like:
Var c = (createVar());
To produce unrelated temporary for the createVar() result and conjure new symbol for value of c in C++17 mode.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102835
Files:
clang/lib/Analysis/CFG.cpp
clang/test/Analysis/NewDelete-checker-test.cpp
Index: clang/test/Analysis/NewDelete-checker-test.cpp
===================================================================
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -26,6 +26,35 @@
// RUN: -verify=expected,leak \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN: -verify=expected,newdelete \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=cplusplus.NewDelete
+//
+// RUN: %clang_analyze_cc1 -DLEAKS -std=c++17 -fblocks %s \
+// RUN: -verify=expected,newdelete,leak \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=cplusplus.NewDelete \
+// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks %s \
+// RUN: -verify=expected,newdelete \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=cplusplus.NewDelete \
+// RUN: -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN: -verify=expected,newdelete,leak \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=cplusplus.NewDelete \
+// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks \
+// RUN: -analyzer-config c++-allocator-inlining=true
+//
+// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
+// RUN: -verify=expected,leak \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks
#include "Inputs/system-header-simulator-cxx.h"
@@ -288,7 +317,7 @@
explicit shared_ptr(T *p) : p(p), control(new control_block) {
control->retain();
}
- shared_ptr(shared_ptr &other) : p(other.p), control(other.control) {
+ shared_ptr(const shared_ptr &other) : p(other.p), control(other.control) {
if (control)
control->retain();
}
@@ -314,11 +343,26 @@
}
};
+ template <typename T, typename... Args>
+ shared_ptr<T> make_shared(Args &&...args) {
+ return shared_ptr<T>(new T(static_cast<Args &&>(args)...));
+ }
+
void testSingle() {
shared_ptr<int> a(new int);
*a = 1;
}
+ void testMake() {
+ shared_ptr<int> a = make_shared<int>();
+ *a = 1;
+ }
+
+ void testMakeInParens() {
+ shared_ptr<int> a = (make_shared<int>());
+ *a = 1;
+ }
+
void testDouble() {
shared_ptr<int> a(new int);
shared_ptr<int> b = a;
Index: clang/lib/Analysis/CFG.cpp
===================================================================
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -1456,6 +1456,13 @@
// TODO: Handle other cases. For now, fail to find construction contexts.
break;
}
+ case Stmt::ParenExprClass: {
+ // If expression is placed into parenthesis we should propagate the parent
+ // construction context to subexpressions.
+ auto *PE = cast<ParenExpr>(Child);
+ findConstructionContexts(Layer, PE->getSubExpr());
+ break;
+ }
default:
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102835.346673.patch
Type: text/x-patch
Size: 3051 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210520/15777ebe/attachment.bin>
More information about the cfe-commits
mailing list