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() {
8383 if (!guarded (x)) {
8484 x = 0 ;
8585 }
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+ }
86112 sink (x); // $ SPURIOUS: ast
87113}
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 {
1111 g .( FunctionCall ) .getTarget ( ) .getName ( ) = "guarded" and
1212 checked = g .( FunctionCall ) .getArgument ( 0 ) and
1313 isTrue = true
14+ or
15+ g .( FunctionCall ) .getTarget ( ) .getName ( ) = "unsafe" and
16+ checked = g .( FunctionCall ) .getArgument ( 0 ) and
17+ isTrue = false
1418 }
1519
1620 /** Common data flow configuration to be used by tests. */
@@ -105,9 +109,13 @@ module IRTest {
105109 predicate testBarrierGuard ( IRGuardCondition g , Expr checked , boolean isTrue ) {
106110 exists ( Call call |
107111 call = g .getUnconvertedResultExpression ( ) and
112+ checked = call .getArgument ( 0 )
113+ |
108114 call .getTarget ( ) .hasName ( "guarded" ) and
109- checked = call .getArgument ( 0 ) and
110115 isTrue = true
116+ or
117+ call .getTarget ( ) .hasName ( "unsafe" ) and
118+ isTrue = false
111119 )
112120 }
113121
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ astFlow
1313| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:64:14:64:14 | x |
1414| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:66:14:66:14 | x |
1515| 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 |
1619| acrossLinkTargets.cpp:19:27:19:32 | call to source | acrossLinkTargets.cpp:12:8:12:8 | x |
1720| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:18:8:18:19 | sourceArray1 |
1821| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:22:8:22:20 | & ... |
@@ -142,6 +145,8 @@ irFlow
142145| BarrierGuard.cpp:49:10:49:15 | call to source | BarrierGuard.cpp:55:13:55:13 | x |
143146| BarrierGuard.cpp:60:11:60:16 | call to source | BarrierGuard.cpp:64:14:64:14 | x |
144147| 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 |
145150| acrossLinkTargets.cpp:19:27:19:32 | call to source | acrossLinkTargets.cpp:12:8:12:8 | x |
146151| clang.cpp:12:9:12:20 | sourceArray1 | clang.cpp:18:8:18:19 | sourceArray1 |
147152| 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