C++: Add tests.

This commit is contained in:
Mathias Vorreiter Pedersen
2023-11-15 14:19:50 +00:00
parent f05c86239f
commit 1753a7e146
3 changed files with 70 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ uniquePostUpdate
postIsInSameCallable
reverseRead
argHasPostUpdate
| flowOut.cpp:55:14:55:16 | * ... | ArgumentNode is missing PostUpdateNode. |
| lambdas.cpp:18:7:18:7 | a | ArgumentNode is missing PostUpdateNode. |
| lambdas.cpp:25:2:25:2 | b | ArgumentNode is missing PostUpdateNode. |
| lambdas.cpp:32:2:32:2 | c | ArgumentNode is missing PostUpdateNode. |
@@ -51,7 +52,12 @@ postWithInFlow
| example.c:28:23:28:25 | pos [inner post update] | PostUpdateNode should not be the target of local flow. |
| flowOut.cpp:5:5:5:12 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
| flowOut.cpp:5:6:5:12 | toTaint [inner post update] | PostUpdateNode should not be the target of local flow. |
| flowOut.cpp:8:5:8:12 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
| flowOut.cpp:8:6:8:12 | toTaint [inner post update] | PostUpdateNode should not be the target of local flow. |
| flowOut.cpp:18:17:18:17 | x [inner post update] | PostUpdateNode should not be the target of local flow. |
| flowOut.cpp:30:12:30:12 | x [inner post update] | PostUpdateNode should not be the target of local flow. |
| flowOut.cpp:37:5:37:6 | p2 [inner post update] | PostUpdateNode should not be the target of local flow. |
| flowOut.cpp:37:5:37:9 | access to array [post update] | PostUpdateNode should not be the target of local flow. |
| globals.cpp:13:5:13:19 | flowTestGlobal1 [post update] | PostUpdateNode should not be the target of local flow. |
| globals.cpp:23:5:23:19 | flowTestGlobal2 [post update] | PostUpdateNode should not be the target of local flow. |
| lambdas.cpp:23:3:23:14 | v [post update] | PostUpdateNode should not be the target of local flow. |

View File

@@ -1,20 +1,74 @@
int source();
void sink(int);
int source(); char source(bool);
void sink(int); void sink(char);
void source_ref(int *toTaint) { // $ ir-def=*toTaint ast-def=toTaint
*toTaint = source();
}
void source_ref(char *toTaint) { // $ ir-def=*toTaint ast-def=toTaint
*toTaint = source();
}
void modify_copy(int* ptr) { // $ ast-def=ptr
int deref = *ptr;
int* other = &deref;
source_ref(other);
}
void test_output() {
void test_output_copy() {
int x = 0;
modify_copy(&x);
sink(x); // $ SPURIOUS: ir
}
void modify(int* ptr) { // $ ast-def=ptr
int* deref = ptr;
int* other = &*deref;
source_ref(other);
}
void test_output() {
int x = 0;
modify(&x);
sink(x); // $ SPURIOUS: ir MISSING: ast
}
void modify_copy_of_pointer(int* p, unsigned len) { // $ ast-def=p
int* p2 = new int[len];
for(unsigned i = 0; i < len; ++i) {
p2[i] = p[i];
}
source_ref(p2);
}
void test_modify_copy_of_pointer() {
int x[10];
modify_copy_of_pointer(x, 10);
sink(x[0]); // $ SPURIOUS: ir,ast
}
void modify_pointer(int* p, unsigned len) { // $ ast-def=p
int** p2 = &p;
for(unsigned i = 0; i < len; ++i) {
*p2[i] = p[i];
}
source_ref(*p2);
}
void test_modify_of_pointer() {
int x[10];
modify_pointer(x, 10);
sink(x[0]); // $ ast,ir
}
char* strdup(const char* p);
void modify_copy_via_strdup(char* p) { // $ ast-def=p
char* p2 = strdup(p);
source_ref(p2);
}
void test_modify_copy_via_strdup(char* p) { // $ ast-def=p
modify_copy_via_strdup(p);
sink(*p); // $ SPURIOUS: ir
}

View File

@@ -1,3 +1,7 @@
| flowOut.cpp:44:7:44:7 | x | flowOut.cpp:45:26:45:26 | x |
| flowOut.cpp:44:7:44:7 | x | flowOut.cpp:46:8:46:8 | x |
| flowOut.cpp:59:7:59:7 | x | flowOut.cpp:60:18:60:18 | x |
| flowOut.cpp:59:7:59:7 | x | flowOut.cpp:61:8:61:8 | x |
| ref.cpp:53:9:53:10 | x1 | ref.cpp:55:19:55:20 | x1 |
| ref.cpp:53:9:53:10 | x1 | ref.cpp:56:10:56:11 | x1 |
| ref.cpp:53:13:53:14 | x2 | ref.cpp:58:15:58:16 | x2 |