Skip to content

Commit 754a503

Browse files
Adding missing test cases.
1 parent 7cb7fc4 commit 754a503

13 files changed

+167
-13
lines changed

lab6/test/Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
.PRECIOUS: %.ll
1+
.PRECIOUS: %.ll %.opt.ll
22

3-
all: simple0.out simple1.out branch0.out branch1.out branch2.out loop0.out input0.out pointer0.out pointer1.out pointer2.out
3+
all: simple0.out simple1.out branch0.out branch1.out branch2.out branch3.out branch4.out branch5.out branch6.out loop0.out loop1.out input0.out pointer0.out pointer1.out pointer2.out
44

55
%.opt.ll: %.c
66
clang -emit-llvm -S -fno-discard-value-names -Xclang -disable-O0-optnone -c -o $@ $<
7-
opt -mem2reg -S $@ -o $*.opt.ll
87

98
%.out: %.opt.ll
109
opt -load ../build/DataflowPass.so -DivZero $< -disable-output > $@ 2> $*.err

lab6/test/branch2.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#include <stdio.h>
2+
13
void f() {
2-
int x = 0;
4+
int x = fgetc(stdin);
35
int y = 2;
4-
int z;
5-
if (x < 1) {
6-
y = 1;
6+
if (x > 10) {
7+
y = 0;
78
}
8-
z = y / x; // divide-by-zero after branch
9+
int z = x / y; // divide-by-zero after branch
910
}

lab6/test/branch3.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
3+
void f() {
4+
int x = fgetc(stdin);
5+
int y = 0;
6+
if (x > 10) {
7+
y = 1;
8+
} else {
9+
y = 2;
10+
}
11+
int z = x / y;
12+
}

lab6/test/branch4.c

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
3+
void f() {
4+
int in = fgetc(stdin);
5+
unsigned int a = 10;
6+
unsigned int b = 2;
7+
8+
if(in > 0){
9+
b = 0;
10+
}else if(in == 0){
11+
b = 2 - b;
12+
}else{
13+
b = -2 + b;
14+
}
15+
16+
int out = a / b;
17+
}

lab6/test/branch5.c

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
3+
void f() {
4+
int in = fgetc(stdin);
5+
unsigned int a = 10;
6+
unsigned int b = 2;
7+
8+
if(in > 0){
9+
b = in + b;
10+
}else if(in == 0){
11+
b = 0;
12+
}else{
13+
b = in - b;
14+
}
15+
16+
int out = a / b;
17+
}

lab6/test/branch6.c

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
3+
void f() {
4+
int in = fgetc(stdin);
5+
int a = 10;
6+
int b = 2;
7+
8+
if(in > 0){
9+
b = 100 + b;
10+
}else if(in == 0){
11+
b = 1;
12+
}else{
13+
b = a + b;
14+
}
15+
16+
int out = a / b;
17+
}

lab6/test/loop0.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ void f() {
22
int i;
33
int sum = 0;
44
for (i = 0; i < 10; i++) {
5-
sum += i;
5+
sum += 1;
66
}
7-
int y = sum - 55;
8-
int z = i / y;
7+
int z = i / sum;
98
}

lab6/test/loop1.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
void f() {
2+
int i;
3+
int sum = 0;
4+
while(sum < 50){
5+
sum += i;
6+
}
7+
int y = sum - 55;
8+
int z = i / y;
9+
}

lab6/test/pointer0.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
int f(){
2-
int a;
2+
int a = 1;
33
int *c = &a;
44
int *d = &a;
55
*c = 0;
66
int x = 1 / *d;
7-
return 0;
7+
return x;
88
}

lab6/test/pointer3.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
int f(int arg) {
2+
int a = 1;
3+
int b = 1;
4+
int *x;
5+
int *y;
6+
if (arg) {
7+
x = &a;
8+
y = &b;
9+
} else {
10+
x = &b;
11+
y = &a;
12+
}
13+
int *z;
14+
if (arg) {
15+
z = x;
16+
} else {
17+
z = y;
18+
}
19+
int z2 = 1 / *z;
20+
return 0;
21+
}

lab6/test/pointer4.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <stdio.h>
2+
3+
int main(){
4+
int a = 0;
5+
int b = 1;
6+
int* p = &a;
7+
int* q = &b;
8+
9+
*p = *q;
10+
11+
int s = b / *p; //not a div by zero
12+
return 0;
13+
}

lab6/test/pointer5.c

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
3+
int main(){
4+
int in = fgetc(stdin);
5+
int a = 0;
6+
int b = 1;
7+
int* x;
8+
9+
if(in < 10){
10+
x = &a;
11+
}else{
12+
x = &b;
13+
}
14+
15+
int s = b / *x; //divide by zero possible
16+
return 0;
17+
}

lab6/test/pointer6.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
3+
int main(){
4+
int stop = fgetc(stdin);
5+
6+
if (stop > 4){
7+
stop = 2;
8+
}
9+
10+
int* point = NULL;
11+
12+
int a = 1;
13+
int b = 2;
14+
int c = 0;
15+
int d = 3;
16+
17+
if(stop == 0){
18+
point = &a;
19+
}else if(stop == 1){
20+
point = &b;
21+
}else if(stop == 2){
22+
point = &c;
23+
}else{
24+
point = &d;
25+
}
26+
27+
int* e = &a;
28+
int* f = &a;
29+
30+
int y = *f / *point;
31+
return 0;
32+
}

0 commit comments

Comments
 (0)