summaryrefslogtreecommitdiff
path: root/clang/test/Analysis/domtest.c
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/Analysis/domtest.c
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/Analysis/domtest.c')
-rw-r--r--clang/test/Analysis/domtest.c165
1 files changed, 165 insertions, 0 deletions
diff --git a/clang/test/Analysis/domtest.c b/clang/test/Analysis/domtest.c
new file mode 100644
index 0000000..245186a
--- /dev/null
+++ b/clang/test/Analysis/domtest.c
@@ -0,0 +1,165 @@
+// RUN: %clang -cc1 -analyze -analyzer-checker=debug.DumpDominators %s 2>&1 | FileCheck %s
+
+// Test the DominatorsTree implementation with various control flows
+int test1()
+{
+ int x = 6;
+ int y = x/2;
+ int z;
+
+ while(y > 0) {
+ if(y < x) {
+ x = x/y;
+ y = y-1;
+ }else{
+ z = x - y;
+ }
+ x = x - 1;
+ x = x - 1;
+ }
+ z = x+y;
+ z = 3;
+ return 0;
+}
+
+// CHECK: Immediate dominance tree (Node#,IDom#):
+// CHECK: (0,1)
+// CHECK: (1,2)
+// CHECK: (2,8)
+// CHECK: (3,4)
+// CHECK: (4,7)
+// CHECK: (5,7)
+// CHECK: (6,7)
+// CHECK: (7,2)
+// CHECK: (8,9)
+// CHECK: (9,9)
+
+int test2()
+{
+ int x,y,z;
+
+ x = 10; y = 100;
+ if(x > 0){
+ y = 1;
+ }else{
+ while(x<=0){
+ x++;
+ y++;
+ }
+ }
+ z = y;
+
+ return 0;
+}
+
+// CHECK: Immediate dominance tree (Node#,IDom#):
+// CHECK: (0,1)
+// CHECK: (1,6)
+// CHECK: (2,6)
+// CHECK: (3,4)
+// CHECK: (4,2)
+// CHECK: (5,6)
+// CHECK: (6,7)
+// CHECK: (7,7)
+
+int test3()
+{
+ int x,y,z;
+
+ x = y = z = 1;
+ if(x>0) {
+ while(x>=0){
+ while(y>=x) {
+ x = x-1;
+ y = y/2;
+ }
+ }
+ }
+ z = y;
+
+ return 0;
+}
+
+// CHECK: Immediate dominance tree (Node#,IDom#):
+// CHECK: (0,1)
+// CHECK: (1,7)
+// CHECK: (2,7)
+// CHECK: (3,4)
+// CHECK: (4,2)
+// CHECK: (5,6)
+// CHECK: (6,4)
+// CHECK: (7,8)
+// CHECK: (8,8)
+
+int test4()
+{
+ int y = 3;
+ while(y > 0) {
+ if(y < 3) {
+ while(y>0)
+ y ++;
+ }else{
+ while(y<10)
+ y ++;
+ }
+ }
+ return 0;
+}
+
+// CHECK: Immediate dominance tree (Node#,IDom#):
+// CHECK: (0,1)
+// CHECK: (1,2)
+// CHECK: (2,11)
+// CHECK: (3,10)
+// CHECK: (4,10)
+// CHECK: (5,6)
+// CHECK: (6,4)
+// CHECK: (7,10)
+// CHECK: (8,9)
+// CHECK: (9,7)
+// CHECK: (10,2)
+// CHECK: (11,12)
+// CHECK: (12,12)
+
+int test5()
+{
+ int x,y,z,a,b,c;
+ x = 1;
+ y = 2;
+ z = 3;
+ a = 4;
+ b = 5;
+ c = 6;
+ if ( x < 10 ) {
+ if ( y < 10 ) {
+ if ( z < 10 ) {
+ x = 4;
+ } else {
+ x = 5;
+ }
+ a = 10;
+ } else {
+ x = 6;
+ }
+ b = 10;
+ } else {
+ x = 7;
+ }
+ c = 11;
+ return 0;
+}
+
+// CHECK: Immediate dominance tree (Node#,IDom#):
+// CHECK: (0,1)
+// CHECK: (1,10)
+// CHECK: (2,10)
+// CHECK: (3,9)
+// CHECK: (4,9)
+// CHECK: (5,8)
+// CHECK: (6,8)
+// CHECK: (7,8)
+// CHECK: (8,9)
+// CHECK: (9,10)
+// CHECK: (10,11)
+// CHECK: (11,11)
+