diff options
author | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2022-09-30 17:14:00 +0200 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2022-10-01 11:16:39 +0200 |
commit | 995f654c43092ceb258f7c0799a4101ed6e570af (patch) | |
tree | 15439bf51a2a3481181113d7f325b461b62c2f79 | |
parent | 634b136e5af1adafd8af7e5390aacdac2eb25be3 (diff) | |
download | compcert-995f654c43092ceb258f7c0799a4101ed6e570af.tar.gz compcert-995f654c43092ceb258f7c0799a4101ed6e570af.zip |
Add test for nested conditional, &&, || expressions
-rw-r--r-- | test/regression/Makefile | 2 | ||||
-rw-r--r-- | test/regression/Results/telescopes | 7 | ||||
-rw-r--r-- | test/regression/telescopes.c | 47 |
3 files changed, 55 insertions, 1 deletions
diff --git a/test/regression/Makefile b/test/regression/Makefile index 536b7264..da31c7d7 100644 --- a/test/regression/Makefile +++ b/test/regression/Makefile @@ -15,7 +15,7 @@ TESTS=int32 int64 floats floats-basics floats-lit \ volatile1 volatile2 volatile3 volatile4 \ funct3 expr5 struct7 struct8 struct11 struct12 casts1 casts2 char1 \ sizeof1 sizeof2 binops bool for1 for2 switch switch2 compound \ - decl1 bitfields9 ptrs3 \ + decl1 bitfields9 ptrs3 telescopes \ parsing krfun ifconv generic # stringlit charlit # temporarily removed diff --git a/test/regression/Results/telescopes b/test/regression/Results/telescopes new file mode 100644 index 00000000..042e45bd --- /dev/null +++ b/test/regression/Results/telescopes @@ -0,0 +1,7 @@ +orand: 1 0 0 1 +andor: 0 1 1 0 +choose: 23 45 +choose2: 23 45 89 67 +choosed: 23.32 45.54 +choose2d: 23 45 89 67.76 +chooseandl: 23 0 0 1 diff --git a/test/regression/telescopes.c b/test/regression/telescopes.c new file mode 100644 index 00000000..02ff3b60 --- /dev/null +++ b/test/regression/telescopes.c @@ -0,0 +1,47 @@ +/* Nested `||`, `&&` and ` ? : ` expressions. */ + +#include <stdio.h> + +int orand(int x, int y, int z) { return x || (y && z); } + +int andor(int x, int y, int z) { return (x || y) && z; } + +int choose(int x, int y, int z) { return x ? y : z; } + +int choose2(int a, int x1, int y1, int z1, int x2, int y2, int z2) +{ return a ? (x1 ? y1 : z1) : (x2 ? y2 : z2); } + +double choosed(int x, double y, double z) { return x ? y : z; } + +double choose2d(int a, int x1, long long y1, int z1, int x2, double y2, long long z2) +{ return a ? (x1 ? y1 : z1) : (x2 ? y2 : z2); } + +long long chooseandl(int a, long long x, int y, int z) +{ return a ? x : y && z; } + +int main() +{ + printf("orand: %d %d %d %d\n", + orand(1,0,0), orand(0,1,0), orand(0,0,1), orand(0,1,1)); + printf("andor: %d %d %d %d\n", + andor(0,0,1), andor(1,0,1), andor(0,1,1), andor(1,1,0)); + printf("choose: %d %d\n", + choose(1, 23, 45), choose(0, 23, 45)); + printf("choose2: %d %d %d %d\n", + choose2(1, 1, 23, 45, 0, 67, 89), + choose2(1, 0, 23, 45, 0, 67, 89), + choose2(0, 0, 23, 45, 0, 67, 89), + choose2(0, 0, 23, 45, 1, 67, 89)); + printf("choosed: %g %g\n", + choosed(1, 23.32, 45.54), choosed(0, 23.32, 45.54)); + printf("choose2d: %g %g %g %g\n", + choose2d(1, 1, 23, 45, 0, 67.76, 89), + choose2d(1, 0, 23, 45, 0, 67.76, 89), + choose2d(0, 0, 23, 45, 0, 67.76, 89), + choose2d(0, 0, 23, 45, 1, 67.76, 89)); + printf("chooseandl: %lld %lld %lld %lld\n", + chooseandl(1, 23, 0, 0), + chooseandl(0, 23, 0, 1), + chooseandl(0, 23, 1, 0), + chooseandl(0, 23, 1, 1)); +} |