From 5368fc0b29ec249e564fc87ea8b933a350f76d04 Mon Sep 17 00:00:00 2001 From: xleroy Date: Fri, 1 Mar 2013 15:55:19 +0000 Subject: Testing dense switches git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2130 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- test/regression/Makefile | 2 +- test/regression/Results/switch | 22 ++++++++++++++++++++++ test/regression/switch.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/regression/Results/switch create mode 100644 test/regression/switch.c (limited to 'test') diff --git a/test/regression/Makefile b/test/regression/Makefile index 31ea51b..262da2a 100644 --- a/test/regression/Makefile +++ b/test/regression/Makefile @@ -12,7 +12,7 @@ TESTS=attribs1 bitfields1 bitfields2 bitfields3 bitfields4 \ expr1 expr6 funptr2 initializers volatile1 volatile2 volatile3 \ funct3 expr5 struct7 struct8 struct11 casts1 casts2 char1 \ sizeof1 sizeof2 packedstruct1 packedstruct2 \ - instrsel bool compar + instrsel bool compar switch # Other tests: should compile to .s without errors (but expect warnings) EXTRAS=annot1 commaprec expr2 expr3 expr4 extern1 funct2 funptr1 init1 \ diff --git a/test/regression/Results/switch b/test/regression/Results/switch new file mode 100644 index 0000000..338876f --- /dev/null +++ b/test/regression/Results/switch @@ -0,0 +1,22 @@ +f(-1) = -1 +f(0) = 12 +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 diff --git a/test/regression/switch.c b/test/regression/switch.c new file mode 100644 index 0000000..43ca1da --- /dev/null +++ b/test/regression/switch.c @@ -0,0 +1,39 @@ +/* Testing jump tables */ + +#include + +int f(int x) +{ + switch (x) { + case 0: return 12; + 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; + } +} + +int main(void) +{ + int i; + for (i = -1; i <= 20; i++) { + printf("f(%d) = %d\n", i, f(i)); + } + return 0; +} -- cgit v1.2.3