aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/linear
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-12-11 13:33:13 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-06-23 07:46:39 +0200
commit86af2a17d26712bce69759120c290c5ede88f677 (patch)
treec29b24b7dde23233b88a99fe3fc29538bd18bb5d /validation/linear
parent3e7e84decfebec22936e288e66fd7a5a51f01fc7 (diff)
downloadsparse-dev-86af2a17d26712bce69759120c290c5ede88f677.tar.gz
cast: reorg testcases related to casts
* merge the tests about implicit & explicit casts in a single file as there was a lot of redundancy. * shuffle the tests to linear/ or optim/ Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/linear')
-rw-r--r--validation/linear/bool-cast.c32
-rw-r--r--validation/linear/cast-constant-to-float.c35
-rw-r--r--validation/linear/cast-constants.c357
-rw-r--r--validation/linear/cast-kinds.c391
-rw-r--r--validation/linear/fp-vs-ptrcast.c13
-rw-r--r--validation/linear/fp2i-cast.c30
6 files changed, 858 insertions, 0 deletions
diff --git a/validation/linear/bool-cast.c b/validation/linear/bool-cast.c
new file mode 100644
index 00000000..981e9f83
--- /dev/null
+++ b/validation/linear/bool-cast.c
@@ -0,0 +1,32 @@
+extern int fun(void);
+typedef unsigned int u32;
+typedef int s32;
+typedef void *vdp;
+typedef int *sip;
+typedef double dbl;
+typedef unsigned short __attribute__((bitwise)) le16;
+
+static _Bool fs32_i(s32 a) { return a; }
+static _Bool fs32_e(s32 a) { return (_Bool)a; }
+static _Bool fu32_i(u32 a) { return a; }
+static _Bool fu32_e(u32 a) { return (_Bool)a; }
+static _Bool fvdp_i(vdp a) { return a; }
+static _Bool fvdp_e(vdp a) { return (_Bool)a; }
+static _Bool fsip_i(sip a) { return a; }
+static _Bool fsip_e(sip a) { return (_Bool)a; }
+static _Bool ffun_i(void) { return fun; }
+static _Bool ffun_e(void) { return (_Bool)fun; }
+static _Bool fres_i(le16 a) { return a; }
+static _Bool fres_e(le16 a) { return (_Bool)a; }
+static _Bool fdbl_i(dbl a) { return a; }
+static _Bool fdbl_e(dbl a) { return (_Bool)a; }
+
+/*
+ * check-name: bool-cast
+ * check-command: test-linearize -m64 -fdump-ir=linearize $file
+ *
+ * check-output-ignore
+ * check-output-excludes: cast\\.
+ * check-output-pattern(12): setne\\.
+ * check-output-pattern(2): fcmpune\\.
+ */
diff --git a/validation/linear/cast-constant-to-float.c b/validation/linear/cast-constant-to-float.c
new file mode 100644
index 00000000..ef7892f1
--- /dev/null
+++ b/validation/linear/cast-constant-to-float.c
@@ -0,0 +1,35 @@
+typedef unsigned int uint;
+typedef unsigned long ulong;
+
+double f1(void) { return -1; }
+double f2(void) { return (double)-1; }
+double f3(void) { return -1.0; }
+
+/*
+ * check-name: cast-constant-to-float
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+f1:
+.L0:
+ <entry-point>
+ setfval.64 %r1 <- -1.000000
+ ret.64 %r1
+
+
+f2:
+.L2:
+ <entry-point>
+ setfval.64 %r3 <- -1.000000
+ ret.64 %r3
+
+
+f3:
+.L4:
+ <entry-point>
+ setfval.64 %r5 <- -1.000000
+ ret.64 %r5
+
+
+ * check-output-end
+ */
diff --git a/validation/linear/cast-constants.c b/validation/linear/cast-constants.c
new file mode 100644
index 00000000..9e200672
--- /dev/null
+++ b/validation/linear/cast-constants.c
@@ -0,0 +1,357 @@
+typedef unsigned int uint;
+typedef unsigned long ulong;
+
+static int uint_2_int(void) { return (int)123U; }
+static int long_2_int(void) { return (int)123L; }
+static int ulong_2_int(void) { return (int)123UL; }
+static int vptr_2_int(void) { return (int)((void*)123); }
+static int iptr_2_int(void) { return (int)((int*)128); }
+static int float_2_int(void) { return (int)1.123F; }
+static int double_2_int(void) { return (int)1.123L; }
+static uint int_2_uint(void) { return (uint)123; }
+static uint long_2_uint(void) { return (uint)123L; }
+static uint ulong_2_uint(void) { return (uint)123UL; }
+static uint vptr_2_uint(void) { return (uint)((void*)123); }
+static uint iptr_2_uint(void) { return (uint)((int*)128); }
+static uint float_2_uint(void) { return (uint)1.123F; }
+static uint double_2_uint(void) { return (uint)1.123L; }
+static long int_2_long(void) { return (long)123; }
+static long uint_2_long(void) { return (long)123U; }
+static long ulong_2_long(void) { return (long)123UL; }
+static long vptr_2_long(void) { return (long)((void*)123); }
+static long iptr_2_long(void) { return (long)((int*)128); }
+static long float_2_long(void) { return (long)1.123F; }
+static long double_2_long(void) { return (long)1.123L; }
+static ulong int_2_ulong(void) { return (ulong)123; }
+static ulong uint_2_ulong(void) { return (ulong)123U; }
+static ulong long_2_ulong(void) { return (ulong)123L; }
+static ulong vptr_2_ulong(void) { return (ulong)((void*)123); }
+static ulong iptr_2_ulong(void) { return (ulong)((int*)128); }
+static ulong float_2_ulong(void) { return (ulong)1.123F; }
+static ulong double_2_ulong(void) { return (ulong)1.123L; }
+static void * int_2_vptr(void) { return (void *)123; }
+static void * uint_2_vptr(void) { return (void *)123U; }
+static void * long_2_vptr(void) { return (void *)123L; }
+static void * ulong_2_vptr(void) { return (void *)123UL; }
+static void * iptr_2_vptr(void) { return (void *)((int*)128); }
+static int * int_2_iptr(void) { return (int *)123; }
+static int * uint_2_iptr(void) { return (int *)123U; }
+static int * long_2_iptr(void) { return (int *)123L; }
+static int * ulong_2_iptr(void) { return (int *)123UL; }
+static int * vptr_2_iptr(void) { return (int *)((void*)123); }
+static float int_2_float(void) { return (float)123; }
+static float uint_2_float(void) { return (float)123U; }
+static float long_2_float(void) { return (float)123L; }
+static float ulong_2_float(void) { return (float)123UL; }
+static float double_2_float(void) { return (float)1.123L; }
+static double int_2_double(void) { return (double)123; }
+static double uint_2_double(void) { return (double)123U; }
+static double long_2_double(void) { return (double)123L; }
+static double ulong_2_double(void) { return (double)123UL; }
+static double float_2_double(void) { return (double)1.123F; }
+
+/*
+ * check-name: cast-constants.c
+ * check-command: test-linearize -m64 $file
+ *
+ * check-output-start
+uint_2_int:
+.L0:
+ <entry-point>
+ ret.32 $123
+
+
+long_2_int:
+.L2:
+ <entry-point>
+ ret.32 $123
+
+
+ulong_2_int:
+.L4:
+ <entry-point>
+ ret.32 $123
+
+
+vptr_2_int:
+.L6:
+ <entry-point>
+ ret.32 $123
+
+
+iptr_2_int:
+.L8:
+ <entry-point>
+ ret.32 $128
+
+
+float_2_int:
+.L10:
+ <entry-point>
+ ret.32 $1
+
+
+double_2_int:
+.L12:
+ <entry-point>
+ ret.32 $1
+
+
+int_2_uint:
+.L14:
+ <entry-point>
+ ret.32 $123
+
+
+long_2_uint:
+.L16:
+ <entry-point>
+ ret.32 $123
+
+
+ulong_2_uint:
+.L18:
+ <entry-point>
+ ret.32 $123
+
+
+vptr_2_uint:
+.L20:
+ <entry-point>
+ ret.32 $123
+
+
+iptr_2_uint:
+.L22:
+ <entry-point>
+ ret.32 $128
+
+
+float_2_uint:
+.L24:
+ <entry-point>
+ ret.32 $1
+
+
+double_2_uint:
+.L26:
+ <entry-point>
+ ret.32 $1
+
+
+int_2_long:
+.L28:
+ <entry-point>
+ ret.64 $123
+
+
+uint_2_long:
+.L30:
+ <entry-point>
+ ret.64 $123
+
+
+ulong_2_long:
+.L32:
+ <entry-point>
+ ret.64 $123
+
+
+vptr_2_long:
+.L34:
+ <entry-point>
+ ret.64 $123
+
+
+iptr_2_long:
+.L36:
+ <entry-point>
+ ret.64 $128
+
+
+float_2_long:
+.L38:
+ <entry-point>
+ ret.64 $1
+
+
+double_2_long:
+.L40:
+ <entry-point>
+ ret.64 $1
+
+
+int_2_ulong:
+.L42:
+ <entry-point>
+ ret.64 $123
+
+
+uint_2_ulong:
+.L44:
+ <entry-point>
+ ret.64 $123
+
+
+long_2_ulong:
+.L46:
+ <entry-point>
+ ret.64 $123
+
+
+vptr_2_ulong:
+.L48:
+ <entry-point>
+ ret.64 $123
+
+
+iptr_2_ulong:
+.L50:
+ <entry-point>
+ ret.64 $128
+
+
+float_2_ulong:
+.L52:
+ <entry-point>
+ ret.64 $1
+
+
+double_2_ulong:
+.L54:
+ <entry-point>
+ ret.64 $1
+
+
+int_2_vptr:
+.L56:
+ <entry-point>
+ ret.64 $123
+
+
+uint_2_vptr:
+.L58:
+ <entry-point>
+ ret.64 $123
+
+
+long_2_vptr:
+.L60:
+ <entry-point>
+ ret.64 $123
+
+
+ulong_2_vptr:
+.L62:
+ <entry-point>
+ ret.64 $123
+
+
+iptr_2_vptr:
+.L64:
+ <entry-point>
+ ret.64 $128
+
+
+int_2_iptr:
+.L66:
+ <entry-point>
+ ret.64 $123
+
+
+uint_2_iptr:
+.L68:
+ <entry-point>
+ ret.64 $123
+
+
+long_2_iptr:
+.L70:
+ <entry-point>
+ ret.64 $123
+
+
+ulong_2_iptr:
+.L72:
+ <entry-point>
+ ret.64 $123
+
+
+vptr_2_iptr:
+.L74:
+ <entry-point>
+ ret.64 $123
+
+
+int_2_float:
+.L76:
+ <entry-point>
+ setfval.32 %r39 <- 123.000000
+ ret.32 %r39
+
+
+uint_2_float:
+.L78:
+ <entry-point>
+ setfval.32 %r41 <- 123.000000
+ ret.32 %r41
+
+
+long_2_float:
+.L80:
+ <entry-point>
+ setfval.32 %r43 <- 123.000000
+ ret.32 %r43
+
+
+ulong_2_float:
+.L82:
+ <entry-point>
+ setfval.32 %r45 <- 123.000000
+ ret.32 %r45
+
+
+double_2_float:
+.L84:
+ <entry-point>
+ setfval.32 %r47 <- 1.123000
+ ret.32 %r47
+
+
+int_2_double:
+.L86:
+ <entry-point>
+ setfval.64 %r49 <- 123.000000
+ ret.64 %r49
+
+
+uint_2_double:
+.L88:
+ <entry-point>
+ setfval.64 %r51 <- 123.000000
+ ret.64 %r51
+
+
+long_2_double:
+.L90:
+ <entry-point>
+ setfval.64 %r53 <- 123.000000
+ ret.64 %r53
+
+
+ulong_2_double:
+.L92:
+ <entry-point>
+ setfval.64 %r55 <- 123.000000
+ ret.64 %r55
+
+
+float_2_double:
+.L94:
+ <entry-point>
+ setfval.64 %r57 <- 1.123000
+ ret.64 %r57
+
+
+ * check-output-end
+ */
diff --git a/validation/linear/cast-kinds.c b/validation/linear/cast-kinds.c
new file mode 100644
index 00000000..e686c01e
--- /dev/null
+++ b/validation/linear/cast-kinds.c
@@ -0,0 +1,391 @@
+typedef unsigned int uint;
+typedef unsigned long ulong;
+
+static int uint_2_int(uint a) { return (int)a; }
+static int long_2_int(long a) { return (int)a; }
+static int ulong_2_int(ulong a) { return (int)a; }
+static int vptr_2_int(void *a) { return (int)a; }
+static int iptr_2_int(int *a) { return (int)a; }
+static int float_2_int(float a) { return (int)a; }
+static int double_2_int(double a) { return (int)a; }
+static uint int_2_uint(int a) { return (uint)a; }
+static uint long_2_uint(long a) { return (uint)a; }
+static uint ulong_2_uint(ulong a) { return (uint)a; }
+static uint vptr_2_uint(void *a) { return (uint)a; }
+static uint iptr_2_uint(int *a) { return (uint)a; }
+static uint float_2_uint(float a) { return (uint)a; }
+static uint double_2_uint(double a) { return (uint)a; }
+static long int_2_long(int a) { return (long)a; }
+static long uint_2_long(uint a) { return (long)a; }
+static long ulong_2_long(ulong a) { return (long)a; }
+static long vptr_2_long(void *a) { return (long)a; }
+static long iptr_2_long(int *a) { return (long)a; }
+static long float_2_long(float a) { return (long)a; }
+static long double_2_long(double a) { return (long)a; }
+static ulong int_2_ulong(int a) { return (ulong)a; }
+static ulong uint_2_ulong(uint a) { return (ulong)a; }
+static ulong long_2_ulong(long a) { return (ulong)a; }
+static ulong vptr_2_ulong(void *a) { return (ulong)a; }
+static ulong iptr_2_ulong(int *a) { return (ulong)a; }
+static ulong float_2_ulong(float a) { return (ulong)a; }
+static ulong double_2_ulong(double a) { return (ulong)a; }
+static void * int_2_vptr(int a) { return (void *)a; }
+static void * uint_2_vptr(uint a) { return (void *)a; }
+static void * long_2_vptr(long a) { return (void *)a; }
+static void * ulong_2_vptr(ulong a) { return (void *)a; }
+static void * iptr_2_vptr(int *a) { return (void *)a; }
+static int * int_2_iptr(int a) { return (int *)a; }
+static int * uint_2_iptr(uint a) { return (int *)a; }
+static int * long_2_iptr(long a) { return (int *)a; }
+static int * ulong_2_iptr(ulong a) { return (int *)a; }
+static int * vptr_2_iptr(void *a) { return (int *)a; }
+static float int_2_float(int a) { return (float)a; }
+static float uint_2_float(uint a) { return (float)a; }
+static float long_2_float(long a) { return (float)a; }
+static float ulong_2_float(ulong a) { return (float)a; }
+static float double_2_float(double a) { return (float)a; }
+static double int_2_double(int a) { return (double)a; }
+static double uint_2_double(uint a) { return (double)a; }
+static double long_2_double(long a) { return (double)a; }
+static double ulong_2_double(ulong a) { return (double)a; }
+static double float_2_double(float a) { return (double)a; }
+
+/*
+ * check-name: cast-kinds
+ * check-command: test-linearize -m64 $file
+ *
+ * check-output-start
+uint_2_int:
+.L0:
+ <entry-point>
+ ret.32 %arg1
+
+
+long_2_int:
+.L2:
+ <entry-point>
+ scast.32 %r5 <- (64) %arg1
+ ret.32 %r5
+
+
+ulong_2_int:
+.L4:
+ <entry-point>
+ cast.32 %r8 <- (64) %arg1
+ ret.32 %r8
+
+
+vptr_2_int:
+.L6:
+ <entry-point>
+ cast.32 %r11 <- (64) %arg1
+ ret.32 %r11
+
+
+iptr_2_int:
+.L8:
+ <entry-point>
+ cast.32 %r14 <- (64) %arg1
+ ret.32 %r14
+
+
+float_2_int:
+.L10:
+ <entry-point>
+ cast.32 %r17 <- (32) %arg1
+ ret.32 %r17
+
+
+double_2_int:
+.L12:
+ <entry-point>
+ cast.32 %r20 <- (64) %arg1
+ ret.32 %r20
+
+
+int_2_uint:
+.L14:
+ <entry-point>
+ ret.32 %arg1
+
+
+long_2_uint:
+.L16:
+ <entry-point>
+ scast.32 %r26 <- (64) %arg1
+ ret.32 %r26
+
+
+ulong_2_uint:
+.L18:
+ <entry-point>
+ cast.32 %r29 <- (64) %arg1
+ ret.32 %r29
+
+
+vptr_2_uint:
+.L20:
+ <entry-point>
+ cast.32 %r32 <- (64) %arg1
+ ret.32 %r32
+
+
+iptr_2_uint:
+.L22:
+ <entry-point>
+ cast.32 %r35 <- (64) %arg1
+ ret.32 %r35
+
+
+float_2_uint:
+.L24:
+ <entry-point>
+ cast.32 %r38 <- (32) %arg1
+ ret.32 %r38
+
+
+double_2_uint:
+.L26:
+ <entry-point>
+ cast.32 %r41 <- (64) %arg1
+ ret.32 %r41
+
+
+int_2_long:
+.L28:
+ <entry-point>
+ scast.64 %r44 <- (32) %arg1
+ ret.64 %r44
+
+
+uint_2_long:
+.L30:
+ <entry-point>
+ cast.64 %r47 <- (32) %arg1
+ ret.64 %r47
+
+
+ulong_2_long:
+.L32:
+ <entry-point>
+ ret.64 %arg1
+
+
+vptr_2_long:
+.L34:
+ <entry-point>
+ cast.64 %r53 <- (64) %arg1
+ ret.64 %r53
+
+
+iptr_2_long:
+.L36:
+ <entry-point>
+ cast.64 %r56 <- (64) %arg1
+ ret.64 %r56
+
+
+float_2_long:
+.L38:
+ <entry-point>
+ cast.64 %r59 <- (32) %arg1
+ ret.64 %r59
+
+
+double_2_long:
+.L40:
+ <entry-point>
+ cast.64 %r62 <- (64) %arg1
+ ret.64 %r62
+
+
+int_2_ulong:
+.L42:
+ <entry-point>
+ scast.64 %r65 <- (32) %arg1
+ ret.64 %r65
+
+
+uint_2_ulong:
+.L44:
+ <entry-point>
+ cast.64 %r68 <- (32) %arg1
+ ret.64 %r68
+
+
+long_2_ulong:
+.L46:
+ <entry-point>
+ ret.64 %arg1
+
+
+vptr_2_ulong:
+.L48:
+ <entry-point>
+ cast.64 %r74 <- (64) %arg1
+ ret.64 %r74
+
+
+iptr_2_ulong:
+.L50:
+ <entry-point>
+ cast.64 %r77 <- (64) %arg1
+ ret.64 %r77
+
+
+float_2_ulong:
+.L52:
+ <entry-point>
+ cast.64 %r80 <- (32) %arg1
+ ret.64 %r80
+
+
+double_2_ulong:
+.L54:
+ <entry-point>
+ cast.64 %r83 <- (64) %arg1
+ ret.64 %r83
+
+
+int_2_vptr:
+.L56:
+ <entry-point>
+ scast.64 %r86 <- (32) %arg1
+ ret.64 %r86
+
+
+uint_2_vptr:
+.L58:
+ <entry-point>
+ cast.64 %r89 <- (32) %arg1
+ ret.64 %r89
+
+
+long_2_vptr:
+.L60:
+ <entry-point>
+ scast.64 %r92 <- (64) %arg1
+ ret.64 %r92
+
+
+ulong_2_vptr:
+.L62:
+ <entry-point>
+ cast.64 %r95 <- (64) %arg1
+ ret.64 %r95
+
+
+iptr_2_vptr:
+.L64:
+ <entry-point>
+ cast.64 %r98 <- (64) %arg1
+ ret.64 %r98
+
+
+int_2_iptr:
+.L66:
+ <entry-point>
+ ptrcast.64 %r101 <- (32) %arg1
+ ret.64 %r101
+
+
+uint_2_iptr:
+.L68:
+ <entry-point>
+ ptrcast.64 %r104 <- (32) %arg1
+ ret.64 %r104
+
+
+long_2_iptr:
+.L70:
+ <entry-point>
+ ptrcast.64 %r107 <- (64) %arg1
+ ret.64 %r107
+
+
+ulong_2_iptr:
+.L72:
+ <entry-point>
+ ptrcast.64 %r110 <- (64) %arg1
+ ret.64 %r110
+
+
+vptr_2_iptr:
+.L74:
+ <entry-point>
+ ptrcast.64 %r113 <- (64) %arg1
+ ret.64 %r113
+
+
+int_2_float:
+.L76:
+ <entry-point>
+ fpcast.32 %r116 <- (32) %arg1
+ ret.32 %r116
+
+
+uint_2_float:
+.L78:
+ <entry-point>
+ fpcast.32 %r119 <- (32) %arg1
+ ret.32 %r119
+
+
+long_2_float:
+.L80:
+ <entry-point>
+ fpcast.32 %r122 <- (64) %arg1
+ ret.32 %r122
+
+
+ulong_2_float:
+.L82:
+ <entry-point>
+ fpcast.32 %r125 <- (64) %arg1
+ ret.32 %r125
+
+
+double_2_float:
+.L84:
+ <entry-point>
+ fpcast.32 %r128 <- (64) %arg1
+ ret.32 %r128
+
+
+int_2_double:
+.L86:
+ <entry-point>
+ fpcast.64 %r131 <- (32) %arg1
+ ret.64 %r131
+
+
+uint_2_double:
+.L88:
+ <entry-point>
+ fpcast.64 %r134 <- (32) %arg1
+ ret.64 %r134
+
+
+long_2_double:
+.L90:
+ <entry-point>
+ fpcast.64 %r137 <- (64) %arg1
+ ret.64 %r137
+
+
+ulong_2_double:
+.L92:
+ <entry-point>
+ fpcast.64 %r140 <- (64) %arg1
+ ret.64 %r140
+
+
+float_2_double:
+.L94:
+ <entry-point>
+ fpcast.64 %r143 <- (32) %arg1
+ ret.64 %r143
+
+
+ * check-output-end
+ */
diff --git a/validation/linear/fp-vs-ptrcast.c b/validation/linear/fp-vs-ptrcast.c
new file mode 100644
index 00000000..817aee5c
--- /dev/null
+++ b/validation/linear/fp-vs-ptrcast.c
@@ -0,0 +1,13 @@
+float *f01(void* p)
+{
+ return p;
+}
+
+/*
+ * check-name: fp-vs-ptrcast
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-excludes: fpcast
+ * check-output-contains: ptrcast
+ */
diff --git a/validation/linear/fp2i-cast.c b/validation/linear/fp2i-cast.c
new file mode 100644
index 00000000..98d7453e
--- /dev/null
+++ b/validation/linear/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): cast\\.
+ */