Skip to content

Commit 25be9d4

Browse files
committed
C++: Add tests with FPs that need call contexts.
1 parent 36d8678 commit 25be9d4

File tree

1 file changed

+55
-0
lines changed
  • cpp/ql/test/library-tests/dataflow/dataflow-tests

1 file changed

+55
-0
lines changed

cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,3 +734,58 @@ void test_does_not_write_source_to_dereference()
734734
does_not_write_source_to_dereference(&x);
735735
sink(x); // $ ast,ir=733:7 SPURIOUS: ast,ir=726:11
736736
}
737+
738+
void sometimes_calls_sink_eq(int x, int n) {
739+
if(n == 0) {
740+
sink(x); // $ ast,ir=751:27 ast,ir=755:32 SPURIOUS: ast,ir=749:27 ast,ir=753:32
741+
}
742+
}
743+
744+
void call_sometimes_calls_sink_eq(int x, int n) {
745+
sometimes_calls_sink_eq(x, n);
746+
}
747+
748+
void test_sometimes_calls_sink_eq_1() {
749+
sometimes_calls_sink_eq(source(), 1);
750+
sometimes_calls_sink_eq(0, 0);
751+
sometimes_calls_sink_eq(source(), 0);
752+
753+
call_sometimes_calls_sink_eq(source(), 1);
754+
call_sometimes_calls_sink_eq(0, 0);
755+
call_sometimes_calls_sink_eq(source(), 0);
756+
}
757+
758+
void sometimes_calls_sink_lt(int x, int n) {
759+
if(n < 10) {
760+
sink(x); // $ ast,ir=771:27 ast,ir=775:32 SPURIOUS: ast,ir=769:27 ast,ir=773:32
761+
}
762+
}
763+
764+
void call_sometimes_calls_sink_lt(int x, int n) {
765+
sometimes_calls_sink_lt(x, n);
766+
}
767+
768+
void test_sometimes_calls_sink_lt() {
769+
sometimes_calls_sink_lt(source(), 10);
770+
sometimes_calls_sink_lt(0, 0);
771+
sometimes_calls_sink_lt(source(), 2);
772+
773+
call_sometimes_calls_sink_lt(source(), 10);
774+
call_sometimes_calls_sink_lt(0, 0);
775+
call_sometimes_calls_sink_lt(source(), 2);
776+
777+
}
778+
779+
void sometimes_calls_sink_switch(int x, int n) {
780+
switch(n) {
781+
case 0:
782+
sink(x); // $ ast,ir=790:31 SPURIOUS: ast,ir=788:31
783+
break;
784+
}
785+
}
786+
787+
void test_sometimes_calls_sink_switch() {
788+
sometimes_calls_sink_switch(source(), 1);
789+
sometimes_calls_sink_switch(0, 0);
790+
sometimes_calls_sink_switch(source(), 0);
791+
}

0 commit comments

Comments
 (0)