summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-07-16 16:17:08 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-07-16 16:17:08 +0000
commita335e621aaa85a7f73b16c121261dbecf8e68340 (patch)
tree31312a22aafc7f66818c0c82f4c96e88ff391595 /test
parent93b89122000e42ac57abc39734fdf05d3a89e83c (diff)
In conditional expressions e1 ? e2 : e3, cast the results of e2 and e3 to the type of the whole conditional expression.
Replaced predicates "cast", "is_true" and "is_false" by functions "sem_cast" and "bool_val". git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1684 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test')
-rw-r--r--test/regression/Makefile2
-rw-r--r--test/regression/Results/expr611
-rw-r--r--test/regression/expr6.c50
3 files changed, 62 insertions, 1 deletions
diff --git a/test/regression/Makefile b/test/regression/Makefile
index 3faec8d..c04788f 100644
--- a/test/regression/Makefile
+++ b/test/regression/Makefile
@@ -10,7 +10,7 @@ LIBS=$(LIBMATH)
TESTS=attribs1 bitfields1 bitfields2 bitfields3 bitfields4 \
bitfields5 bitfields6 bitfields7 \
- expr1 initializers volatile2 \
+ expr1 expr6 initializers volatile2 \
funct3 expr5 struct7 struct8 casts1 casts2 char1 \
sizeof1 sizeof2 packedstruct1
diff --git a/test/regression/Results/expr6 b/test/regression/Results/expr6
new file mode 100644
index 0000000..9b91e23
--- /dev/null
+++ b/test/regression/Results/expr6
@@ -0,0 +1,11 @@
+f(42) = 42
+f(-1) = 1
+g(1,2,3.14) = 2.00
+g(0,2,3.14) = 3.14
+h(1,2) = true
+h(0,2) = false
+h(1,0) = false
+k(1,2,3.14) = true
+k(0,2,3.14) = true
+k(1,0,3.14) = false
+k(0,2,0.00) = false
diff --git a/test/regression/expr6.c b/test/regression/expr6.c
new file mode 100644
index 0000000..4b789a9
--- /dev/null
+++ b/test/regression/expr6.c
@@ -0,0 +1,50 @@
+/* Conditional expressions */
+
+#include <stdio.h>
+
+int f(int x)
+{
+ return x >= 0 ? x : -x;
+}
+
+double g(int x, int y, double z)
+{
+ return x ? y : z;
+}
+
+void h(int x, int y)
+{
+ while (1) {
+ if (x && y) break;
+ printf("false\n");
+ return;
+ }
+ printf("true\n");
+}
+
+void k(int x, int y, double z)
+{
+ while (1) {
+ if (x ? y : z) break;
+ printf("false\n");
+ return;
+ }
+ printf("true\n");
+}
+
+int main()
+{
+ printf("f(42) = %d\n", f(42));
+ printf("f(-1) = %d\n", f(-1));
+ printf("g(1,2,3.14) = %.2f\n", g(1,2,3.14));
+ printf("g(0,2,3.14) = %.2f\n", g(0,2,3.14));
+ printf("h(1,2) = "); h(1,2);
+ printf("h(0,2) = "); h(0,2);
+ printf("h(1,0) = "); h(1,0);
+ printf("k(1,2,3.14) = "); k(1,2,3.14);
+ printf("k(0,2,3.14) = "); k(0,2,3.14);
+ printf("k(1,0,3.14) = "); k(1,0,3.14);
+ printf("k(0,2,0.00) = "); k(0,2,0.00);
+ return 0;
+}
+