diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2014-08-17 07:53:43 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2014-08-17 07:53:43 +0000 |
commit | 34a2dec2f1fab835aec0799f5b4758df31e688ff (patch) | |
tree | 379302c07e9d167101053a30cb5ca36f16c67fe7 /test/regression | |
parent | 17f519651feb4a09aa90c89c949469e8a5ab0e88 (diff) |
Add some tests for "switch" over 32 and 64-bit integers.
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2566 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/regression')
-rw-r--r-- | test/regression/Makefile | 2 | ||||
-rw-r--r-- | test/regression/Results/switch2 | 47 | ||||
-rw-r--r-- | test/regression/switch2.c | 61 |
3 files changed, 109 insertions, 1 deletions
diff --git a/test/regression/Makefile b/test/regression/Makefile index 3583676..4cf9470 100644 --- a/test/regression/Makefile +++ b/test/regression/Makefile @@ -16,7 +16,7 @@ TESTS=int32 int64 floats floats-basics \ expr1 expr6 funptr2 initializers initializers2 initializers3 \ volatile1 volatile2 volatile3 \ funct3 expr5 struct7 struct8 struct11 casts1 casts2 char1 \ - sizeof1 sizeof2 binops bool for1 + sizeof1 sizeof2 binops bool for1 switch switch2 # Can run, but only in compiled mode, and have reference output in Results diff --git a/test/regression/Results/switch2 b/test/regression/Results/switch2 new file mode 100644 index 0000000..dfbaff2 --- /dev/null +++ b/test/regression/Results/switch2 @@ -0,0 +1,47 @@ +f(-1) = -1 +f(0) = -1 +f(1) = 34 +f(2) = 56 +f(3) = 78 +f(4) = 123 +f(5) = 456 +f(6) = 789 +f(7) = 11 +f(8) = 22 +f(9) = 33 +f(10) = 44 +f(11) = 55 +f(12) = 66 +f(13) = 77 +f(14) = 88 +f(15) = 99 +f(16) = 321 +f(17) = 654 +f(18) = 987 +f(19) = 1001 +f(20) = -1 +g(9223372036854775807) = 1 +g(-9223372036854775808) = 2 +g(1249835483136) = -1 +g(-1) = -1 +g(0) = 3 +g(1) = -1 +g(2) = -1 +g(3) = -1 +g(4) = 4 +g(5) = -1 +g(6) = -1 +g(7) = -1 +g(8) = -1 +g(9) = -1 +g(10) = -1 +g(11) = -1 +g(12) = -1 +g(13) = 5 +g(14) = -1 +g(15) = -1 +g(16) = -1 +g(17) = -1 +g(18) = -1 +g(19) = -1 +g(20) = -1 diff --git a/test/regression/switch2.c b/test/regression/switch2.c new file mode 100644 index 0000000..db74174 --- /dev/null +++ b/test/regression/switch2.c @@ -0,0 +1,61 @@ +/* switch over long long */ + +#include <stdio.h> + +/* Jumptable */ + +int f(long long x) +{ + switch (x) { + case 1: return 34; + case 2: return 56; + case 3: return 78; + case 4: return 123; + case 5: return 456; + case 6: return 789; + case 7: return 11; + case 8: return 22; + case 9: return 33; + case 10: return 44; + case 11: return 55; + case 12: return 66; + case 13: return 77; + case 14: return 88; + case 15: return 99; + case 16: return 321; + case 17: return 654; + case 18: return 987; + case 19: return 1001; + default: return -1; + } +} + +/* Decision tree */ + +int g(long long x) +{ + switch(x) { + case 0x7FFFFFFFFFFFFFFFLL: return 1; + case -0x8000000000000000LL: return 2; + case 0: return 3; + case 4: return 4; + case 13: return 5; + default: return -1; + } +} + +int main(void) +{ + int i; + for (i = -1; i <= 20; i++) { + printf("f(%d) = %d\n", i, f(i)); + } + long long j; + j = 0x7FFFFFFFFFFFFFFFLL; printf("g(%lld) = %d\n", j, g(j)); + j = -0x8000000000000000LL; printf("g(%lld) = %d\n", j, g(j)); + j = 0x12300000000LL; printf("g(%lld) = %d\n", j, g(j)); + for (i = -1; i <= 20; i++) { + printf("g(%d) = %d\n", i, g(i)); + } + return 0; +} |