aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-04-02 16:42:29 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-11-11 14:16:35 +0100
commitf531c014b21523d475373a4dd0b5b60546b03527 (patch)
tree4ab7dd7aeb300f1d5a27ba0bc7d987b114ccde98 /validation
parent90859bb4e3f9ad11f76ad42e3dce84043bdc3176 (diff)
downloadsparse-dev-f531c014b21523d475373a4dd0b5b60546b03527.tar.gz
fix 'simplification' of float-to-int casts
Currently, simplify_cast() don't really take floating-points in account and happily simplify away a float-to-int cast if both types have the same size. Fix this by not touching such casts. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/cast-kinds.c12
-rw-r--r--validation/fp2i-cast.c30
2 files changed, 38 insertions, 4 deletions
diff --git a/validation/cast-kinds.c b/validation/cast-kinds.c
index 697f9735..e686c01e 100644
--- a/validation/cast-kinds.c
+++ b/validation/cast-kinds.c
@@ -92,7 +92,8 @@ iptr_2_int:
float_2_int:
.L10:
<entry-point>
- ret.32 %arg1
+ cast.32 %r17 <- (32) %arg1
+ ret.32 %r17
double_2_int:
@@ -139,7 +140,8 @@ iptr_2_uint:
float_2_uint:
.L24:
<entry-point>
- ret.32 %arg1
+ cast.32 %r38 <- (32) %arg1
+ ret.32 %r38
double_2_uint:
@@ -193,7 +195,8 @@ float_2_long:
double_2_long:
.L40:
<entry-point>
- ret.64 %arg1
+ cast.64 %r62 <- (64) %arg1
+ ret.64 %r62
int_2_ulong:
@@ -240,7 +243,8 @@ float_2_ulong:
double_2_ulong:
.L54:
<entry-point>
- ret.64 %arg1
+ cast.64 %r83 <- (64) %arg1
+ ret.64 %r83
int_2_vptr:
diff --git a/validation/fp2i-cast.c b/validation/fp2i-cast.c
new file mode 100644
index 00000000..08f8c925
--- /dev/null
+++ b/validation/fp2i-cast.c
@@ -0,0 +1,30 @@
+#if __SIZEOF_INT__ == __SIZEOF_FLOAT__
+typedef signed int si;
+typedef unsigned int ui;
+#else
+#error "no float-sized integer type"
+#endif
+
+#if __SIZEOF_LONG_LONG__ == __SIZEOF_DOUBLE__
+typedef signed long long sl;
+typedef unsigned long long ul;
+#else
+#error "no double-sized integer type"
+#endif
+
+si f2si(float a) { return a; }
+ui f2ui(float a) { return a; }
+sl f2sl(float a) { return a; }
+ul f2ul(float a) { return a; }
+si d2si(double a) { return a; }
+ui d2ui(double a) { return a; }
+sl d2sl(double a) { return a; }
+ul d2ul(double a) { return a; }
+
+/*
+ * check-name: fp2i cast
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern-8-times: cast\\.
+ */