diff options
Diffstat (limited to 'test/CodeGen/switch.c')
-rw-r--r-- | test/CodeGen/switch.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/test/CodeGen/switch.c b/test/CodeGen/switch.c index 519ccba..dc2d27b 100644 --- a/test/CodeGen/switch.c +++ b/test/CodeGen/switch.c @@ -100,3 +100,97 @@ void foo7(){ } } + +// CHECK: define i32 @f8( +// CHECK: ret i32 3 +// CHECK: } +int f8(unsigned x) { + switch(x) { + default: + return 3; + case 0xFFFFFFFF ... 1: // This range should be empty because x is unsigned. + return 0; + } +} + +// Ensure that default after a case range is not ignored. +// +// CHECK: define i32 @f9() +// CHECK: ret i32 10 +// CHECK: } +static int f9_0(unsigned x) { + switch(x) { + case 10 ... 0xFFFFFFFF: + return 0; + default: + return 10; + } +} +int f9() { + return f9_0(2); +} + +// Ensure that this doesn't compile to infinite loop in g() due to +// miscompilation of fallthrough from default to a (tested) case +// range. +// +// CHECK: define i32 @f10() +// CHECK: ret i32 10 +// CHECK: } +static int f10_0(unsigned x) { + switch(x) { + default: + x += 1; + case 10 ... 0xFFFFFFFF: + return 0; + } +} + +int f10() { + f10_0(1); + return 10; +} + +// This generated incorrect code because of poor switch chaining. +// +// CHECK: define i32 @f11( +// CHECK: ret i32 3 +// CHECK: } +int f11(int x) { + switch(x) { + default: + return 3; + case 10 ... 0xFFFFFFFF: + return 0; + } +} + +// This just asserted because of the way case ranges were calculated. +// +// CHECK: define i32 @f12( +// CHECK: ret i32 3 +// CHECK: } +int f12(int x) { + switch (x) { + default: + return 3; + case 10 ... -1: + return 0; + } +} + +// Make sure return is not constant (if empty range is skipped or miscompiled) +// +// CHECK: define i32 @f13( +// CHECK: ret i32 % +// CHECK: } +int f13(unsigned x) { + switch(x) { + case 2: + // fallthrough empty range + case 10 ... 9: + return 10; + default: + return 0; + } +} |