aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2010-07-08 08:57:32 +0000
committerxleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2010-07-08 08:57:32 +0000
commit118c148ec89dc0b53bb377cf637cfdcd800f06e5 (patch)
tree7dd709dee9152e1dd98cc220c221793efedf6107
parent0f5acbd9a9fbb0f1bfc1500cf76524d6e7a5e702 (diff)
downloadcompcert-kvx-118c148ec89dc0b53bb377cf637cfdcd800f06e5.tar.gz
compcert-kvx-118c148ec89dc0b53bb377cf637cfdcd800f06e5.zip
Bug in cparser/AddCasts.ml.
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1376 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
-rw-r--r--cparser/AddCasts.ml7
-rw-r--r--test/regression/Makefile2
-rw-r--r--test/regression/Results/casts21
-rw-r--r--test/regression/casts2.c16
4 files changed, 22 insertions, 4 deletions
diff --git a/cparser/AddCasts.ml b/cparser/AddCasts.ml
index 9ec128d9..eb3fa08a 100644
--- a/cparser/AddCasts.ml
+++ b/cparser/AddCasts.ml
@@ -26,7 +26,8 @@ open Transform
(* We have the option of materializing all casts or leave "widening"
casts implicit. Widening casts are:
- from a small integer type to a larger integer type,
-- from a small float type to a larger float type,
+ provided both types have the same signedness;
+- from a small float type to a larger float type;
- from a pointer type to void *.
*)
@@ -35,8 +36,8 @@ let omit_widening_casts = ref false
let widening_cast env tfrom tto =
begin match unroll env tfrom, unroll env tto with
| TInt(k1, _), TInt(k2, _) ->
- let r1 = integer_rank k1 and r2 = integer_rank k2 in
- r1 < r2 || (r1 = r2 && is_signed_ikind k1 = is_signed_ikind k2)
+ integer_rank k1 <= integer_rank k2
+ && is_signed_ikind k1 = is_signed_ikind k2
| TFloat(k1, _), TFloat(k2, _) ->
float_rank k1 <= float_rank k2
| TPtr(ty1, _), TPtr(ty2, _) -> is_void_type env ty2
diff --git a/test/regression/Makefile b/test/regression/Makefile
index 4581bac8..4ebf042d 100644
--- a/test/regression/Makefile
+++ b/test/regression/Makefile
@@ -8,7 +8,7 @@ LIBS=$(LIBMATH)
# Can run and have reference output in Results
TESTS=bitfields1 bitfields2 bitfields3 expr1 initializers volatile2 \
- funct3 expr5 struct7 struct8 casts1
+ funct3 expr5 struct7 struct8 casts1 casts2
# Other tests: should compile to .s without errors (but expect warnings)
EXTRAS=commaprec expr2 expr3 expr4 extern1 funct2 funptr1 init1 \
diff --git a/test/regression/Results/casts2 b/test/regression/Results/casts2
new file mode 100644
index 00000000..36866313
--- /dev/null
+++ b/test/regression/Results/casts2
@@ -0,0 +1 @@
+t_3 = 65440
diff --git a/test/regression/casts2.c b/test/regression/casts2.c
new file mode 100644
index 00000000..b7620764
--- /dev/null
+++ b/test/regression/casts2.c
@@ -0,0 +1,16 @@
+#include <stdint.h>
+#include <stdio.h>
+
+uint16_t func_46(void)
+{
+ int8_t l_48 = 0xA0;
+ return l_48;
+}
+
+int main(void)
+{
+ int32_t t_3 = 0;
+ t_3 = func_46();
+ printf("t_3 = %d\n", t_3);
+ return 0;
+}