File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed
cpp/ql/test/library-tests/dataflow/dataflow-tests Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -83,5 +83,46 @@ void test_guard_and_reassign() {
83
83
if (!guarded (x)) {
84
84
x = 0 ;
85
85
}
86
+ sink (x); // $ SPURIOUS: ast,ir
87
+ }
88
+
89
+ void test_phi_read_guard (bool b) {
90
+ int x = source ();
91
+
92
+ if (b) {
93
+ if (!guarded (x))
94
+ return ;
95
+ }
96
+ else {
97
+ if (!guarded (x))
98
+ return ;
99
+ }
100
+
101
+ sink (x); // $ SPURIOUS: ast,ir
102
+ }
103
+
104
+ bool unsafe (int );
105
+
106
+ void test_guard_and_reassign_2 () {
107
+ int x = source ();
108
+
109
+ if (unsafe (x)) {
110
+ x = 0 ;
111
+ }
86
112
sink (x); // $ SPURIOUS: ast
87
113
}
114
+
115
+ void test_phi_read_guard_2 (bool b) {
116
+ int x = source ();
117
+
118
+ if (b) {
119
+ if (unsafe (x))
120
+ return ;
121
+ }
122
+ else {
123
+ if (unsafe (x))
124
+ return ;
125
+ }
126
+
127
+ sink (x); // $ SPURIOUS: ast
128
+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ module AstTest {
11
11
g .( FunctionCall ) .getTarget ( ) .getName ( ) = "guarded" and
12
12
checked = g .( FunctionCall ) .getArgument ( 0 ) and
13
13
isTrue = true
14
+ or
15
+ g .( FunctionCall ) .getTarget ( ) .getName ( ) = "unsafe" and
16
+ checked = g .( FunctionCall ) .getArgument ( 0 ) and
17
+ isTrue = false
14
18
}
15
19
16
20
/** Common data flow configuration to be used by tests. */
@@ -105,9 +109,13 @@ module IRTest {
105
109
predicate testBarrierGuard ( IRGuardCondition g , Expr checked , boolean isTrue ) {
106
110
exists ( Call call |
107
111
call = g .getUnconvertedResultExpression ( ) and
112
+ checked = call .getArgument ( 0 )
113
+ |
108
114
call .getTarget ( ) .hasName ( "guarded" ) and
109
- checked = call .getArgument ( 0 ) and
110
115
isTrue = true
116
+ or
117
+ call .getTarget ( ) .hasName ( "unsafe" ) and
118
+ isTrue = false
111
119
)
112
120
}
113
121
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ astFlow
13
13
| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:64:14:64:14 | x |
14
14
| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:66:14:66:14 | x |
15
15
| BarrierGuard.cpp:81:11:81:16 | call to source | BarrierGuard.cpp:86:8:86:8 | x |
16
+ | BarrierGuard.cpp:90:11:90:16 | call to source | BarrierGuard.cpp:101:8:101:8 | x |
17
+ | BarrierGuard.cpp:107:11:107:16 | call to source | BarrierGuard.cpp:112:8:112:8 | x |
18
+ | BarrierGuard.cpp:116:11:116:16 | call to source | BarrierGuard.cpp:127:8:127:8 | x |
16
19
| acrossLinkTargets.cpp:19:27:19:32 | call to source | acrossLinkTargets.cpp:12:8:12:8 | x |
17
20
| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:18:8:18:19 | sourceArray1 |
18
21
| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:22:8:22:20 | & ... |
@@ -142,6 +145,8 @@ irFlow
142
145
| BarrierGuard.cpp:49:10:49:15 | call to source | BarrierGuard.cpp:55:13:55:13 | x |
143
146
| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:64:14:64:14 | x |
144
147
| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:66:14:66:14 | x |
148
+ | BarrierGuard.cpp:81:11:81:16 | call to source | BarrierGuard.cpp:86:8:86:8 | x |
149
+ | BarrierGuard.cpp:90:11:90:16 | call to source | BarrierGuard.cpp:101:8:101:8 | x |
145
150
| acrossLinkTargets.cpp:19:27:19:32 | call to source | acrossLinkTargets.cpp:12:8:12:8 | x |
146
151
| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:18:8:18:19 | sourceArray1 |
147
152
| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:23:17:23:29 | *& ... |
You can’t perform that action at this time.
0 commit comments