forked from OSchip/llvm-project
[analyzer] Correctly propagate ConstructionContextLayer thru ParenExpr
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 a new symbol for the value of `c` in C++17 mode. Reviewed By: steakhal Patch By: tomasz-kaminski-sonarsource! Differential Revision: https://reviews.llvm.org/D102835
This commit is contained in:
parent
6caea8a7fa
commit
058f384ae9
|
@ -1456,6 +1456,13 @@ void CFGBuilder::findConstructionContexts(
|
|||
// 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;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<key>kind</key><string>event</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>line</key><integer>19</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -20,12 +20,12 @@
|
|||
<array>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>line</key><integer>19</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>line</key><integer>19</integer>
|
||||
<key>col</key><integer>10</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -45,12 +45,12 @@
|
|||
<key>start</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>17</integer>
|
||||
<key>line</key><integer>12</integer>
|
||||
<key>col</key><integer>1</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>17</integer>
|
||||
<key>line</key><integer>12</integer>
|
||||
<key>col</key><integer>4</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -58,12 +58,12 @@
|
|||
<key>end</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>18</integer>
|
||||
<key>line</key><integer>13</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>18</integer>
|
||||
<key>line</key><integer>13</integer>
|
||||
<key>col</key><integer>5</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -75,7 +75,7 @@
|
|||
<key>kind</key><string>event</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>18</integer>
|
||||
<key>line</key><integer>13</integer>
|
||||
<key>col</key><integer>12</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -83,12 +83,12 @@
|
|||
<array>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>18</integer>
|
||||
<key>line</key><integer>13</integer>
|
||||
<key>col</key><integer>12</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>18</integer>
|
||||
<key>line</key><integer>13</integer>
|
||||
<key>col</key><integer>18</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -108,12 +108,12 @@
|
|||
<key>start</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>18</integer>
|
||||
<key>line</key><integer>13</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>18</integer>
|
||||
<key>line</key><integer>13</integer>
|
||||
<key>col</key><integer>5</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -121,12 +121,12 @@
|
|||
<key>end</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>20</integer>
|
||||
<key>line</key><integer>15</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>20</integer>
|
||||
<key>line</key><integer>15</integer>
|
||||
<key>col</key><integer>4</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -142,12 +142,12 @@
|
|||
<key>start</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>20</integer>
|
||||
<key>line</key><integer>15</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>20</integer>
|
||||
<key>line</key><integer>15</integer>
|
||||
<key>col</key><integer>4</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -155,12 +155,12 @@
|
|||
<key>end</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>21</integer>
|
||||
<key>line</key><integer>16</integer>
|
||||
<key>col</key><integer>5</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>21</integer>
|
||||
<key>line</key><integer>16</integer>
|
||||
<key>col</key><integer>10</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -172,7 +172,7 @@
|
|||
<key>kind</key><string>event</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>21</integer>
|
||||
<key>line</key><integer>16</integer>
|
||||
<key>col</key><integer>5</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -180,12 +180,12 @@
|
|||
<array>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>21</integer>
|
||||
<key>line</key><integer>16</integer>
|
||||
<key>col</key><integer>5</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>21</integer>
|
||||
<key>line</key><integer>16</integer>
|
||||
<key>col</key><integer>12</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -205,12 +205,12 @@
|
|||
<key>start</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>21</integer>
|
||||
<key>line</key><integer>16</integer>
|
||||
<key>col</key><integer>5</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>21</integer>
|
||||
<key>line</key><integer>16</integer>
|
||||
<key>col</key><integer>10</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -218,12 +218,12 @@
|
|||
<key>end</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>line</key><integer>19</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>line</key><integer>19</integer>
|
||||
<key>col</key><integer>8</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -243,7 +243,7 @@
|
|||
<key>issue_hash_function_offset</key><string>7</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>line</key><integer>19</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -251,11 +251,11 @@
|
|||
<dict>
|
||||
<key>0</key>
|
||||
<array>
|
||||
<integer>17</integer>
|
||||
<integer>18</integer>
|
||||
<integer>20</integer>
|
||||
<integer>21</integer>
|
||||
<integer>24</integer>
|
||||
<integer>12</integer>
|
||||
<integer>13</integer>
|
||||
<integer>15</integer>
|
||||
<integer>16</integer>
|
||||
<integer>19</integer>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
|
@ -266,7 +266,7 @@
|
|||
<key>kind</key><string>event</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>35</integer>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -274,12 +274,12 @@
|
|||
<array>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>35</integer>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>35</integer>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>col</key><integer>12</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -295,7 +295,7 @@
|
|||
<key>kind</key><string>event</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>29</integer>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -313,12 +313,12 @@
|
|||
<key>start</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>29</integer>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>29</integer>
|
||||
<key>line</key><integer>24</integer>
|
||||
<key>col</key><integer>5</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -326,12 +326,12 @@
|
|||
<key>end</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>line</key><integer>25</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>line</key><integer>25</integer>
|
||||
<key>col</key><integer>8</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -343,7 +343,7 @@
|
|||
<key>kind</key><string>event</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>line</key><integer>25</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -351,12 +351,12 @@
|
|||
<array>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>line</key><integer>25</integer>
|
||||
<key>col</key><integer>3</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>line</key><integer>25</integer>
|
||||
<key>col</key><integer>13</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -372,7 +372,7 @@
|
|||
<key>kind</key><string>event</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>35</integer>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -380,12 +380,12 @@
|
|||
<array>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>35</integer>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>35</integer>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>col</key><integer>12</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -405,12 +405,12 @@
|
|||
<key>start</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>35</integer>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>35</integer>
|
||||
<key>line</key><integer>30</integer>
|
||||
<key>col</key><integer>4</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -418,12 +418,12 @@
|
|||
<key>end</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>37</integer>
|
||||
<key>line</key><integer>32</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>37</integer>
|
||||
<key>line</key><integer>32</integer>
|
||||
<key>col</key><integer>7</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -435,7 +435,7 @@
|
|||
<key>kind</key><string>event</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>37</integer>
|
||||
<key>line</key><integer>32</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -443,12 +443,12 @@
|
|||
<array>
|
||||
<array>
|
||||
<dict>
|
||||
<key>line</key><integer>37</integer>
|
||||
<key>line</key><integer>32</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>line</key><integer>37</integer>
|
||||
<key>line</key><integer>32</integer>
|
||||
<key>col</key><integer>11</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -472,7 +472,7 @@
|
|||
<key>issue_hash_function_offset</key><string>3</string>
|
||||
<key>location</key>
|
||||
<dict>
|
||||
<key>line</key><integer>37</integer>
|
||||
<key>line</key><integer>32</integer>
|
||||
<key>col</key><integer>2</integer>
|
||||
<key>file</key><integer>0</integer>
|
||||
</dict>
|
||||
|
@ -480,11 +480,11 @@
|
|||
<dict>
|
||||
<key>0</key>
|
||||
<array>
|
||||
<integer>24</integer>
|
||||
<integer>25</integer>
|
||||
<integer>29</integer>
|
||||
<integer>30</integer>
|
||||
<integer>34</integer>
|
||||
<integer>35</integer>
|
||||
<integer>37</integer>
|
||||
<integer>32</integer>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
|
|
|
@ -9,20 +9,23 @@
|
|||
// RUN: -analyzer-checker=cplusplus.NewDelete \
|
||||
// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks
|
||||
//
|
||||
// RUN: %clang_analyze_cc1 -std=c++11 -fblocks %s \
|
||||
// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
|
||||
// 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: -analyzer-config c++-allocator-inlining=true
|
||||
// RUN: -analyzer-checker=cplusplus.NewDelete
|
||||
//
|
||||
// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
|
||||
// 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: -analyzer-config c++-allocator-inlining=true
|
||||
// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks
|
||||
//
|
||||
// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -verify %s \
|
||||
// RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
|
||||
// RUN: -verify=expected,leak \
|
||||
// RUN: -analyzer-checker=core \
|
||||
// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks
|
||||
|
@ -288,7 +291,7 @@ namespace reference_count {
|
|||
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 +317,26 @@ namespace reference_count {
|
|||
}
|
||||
};
|
||||
|
||||
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>()); // no warn
|
||||
*a = 1;
|
||||
}
|
||||
|
||||
void testDouble() {
|
||||
shared_ptr<int> a(new int);
|
||||
shared_ptr<int> b = a;
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
// RUN: -analyzer-output=text -verify %s
|
||||
// RUN: %clang_analyze_cc1 \
|
||||
// RUN: -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
|
||||
// RUN: -analyzer-config c++-allocator-inlining=true \
|
||||
// RUN: -analyzer-config add-pop-up-notes=false \
|
||||
// RUN: -analyzer-output=text -verify %s
|
||||
// RUN: %clang_analyze_cc1 \
|
||||
// RUN: -analyzer-checker=cplusplus.NewDelete,unix.Malloc \
|
||||
// RUN: -analyzer-config add-pop-up-notes=false \
|
||||
// RUN: -analyzer-output=plist %s -o %t.plist
|
||||
// RUN: %normalize_plist <%t.plist | diff -ub \
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -verify %s
|
||||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -analyzer-config c++-allocator-inlining=true -verify %s
|
||||
|
||||
class A0 {};
|
||||
|
||||
|
|
Loading…
Reference in New Issue