aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-05-28 07:04:01 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-05-28 16:59:37 +0200
commitc100a7ab2504f9e6fe6b6d3f9a010a8ea5ed30a3 (patch)
treeda3bd4d1cb46c41c8bc1c2964273caba95cc8137 /validation
parentf7679db159d05701ecd4a858622c611d79482571 (diff)
downloadsparse-dev-c100a7ab2504f9e6fe6b6d3f9a010a8ea5ed30a3.tar.gz
add support for _Generic
It's slightly tested but is fine for the latest kernels like https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/kcsan Note: a known difference with GCC is that it doesn't make the distinction between 'signed char' and a plain 'char' (on platforms where plain char are signed) since it's using the usual type compatbility like used for assignements. Reference: lore.kernel.org/r/20200527235442.GC1805@zn.tnic Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/generic-functions.c44
-rw-r--r--validation/generic-schar.c39
-rw-r--r--validation/generic-typename.c157
3 files changed, 240 insertions, 0 deletions
diff --git a/validation/generic-functions.c b/validation/generic-functions.c
new file mode 100644
index 00000000..61bfd99e
--- /dev/null
+++ b/validation/generic-functions.c
@@ -0,0 +1,44 @@
+void funf(float);
+void fund(double);
+void funl(long double);
+
+#define fung(X) _Generic(X, \
+ float: funf, \
+ default: fund, \
+ long double: funl) (X)
+
+#define TEST(name, T) \
+static void test ## name(T a) { return fung(a); }
+
+TEST(f, float)
+TEST(d, double)
+TEST(l, long double)
+
+/*
+ * check-name: generic-functions
+ * check-command: test-linearize $file
+ *
+ * check-output-start
+testf:
+.L0:
+ <entry-point>
+ call funf, %arg1
+ ret
+
+
+testd:
+.L2:
+ <entry-point>
+ call fund, %arg1
+ ret
+
+
+testl:
+.L4:
+ <entry-point>
+ call funl, %arg1
+ ret
+
+
+ * check-output-end
+ */
diff --git a/validation/generic-schar.c b/validation/generic-schar.c
new file mode 100644
index 00000000..0b082f4f
--- /dev/null
+++ b/validation/generic-schar.c
@@ -0,0 +1,39 @@
+#define typename(x) _Generic((x) 0, \
+char: "char", \
+signed char: "signed char", \
+unsigned char: "unsigned char", \
+default: "???")
+
+#define TEST(name, x) \
+static const char *test_ ## name(void) { return typename(x); }
+
+TEST(char, char)
+TEST(schar, signed char)
+TEST(uchar, unsigned char)
+
+/*
+ * check-name: generic-schar
+ * check-command: test-linearize --arch=i386 -fsigned-char $file
+ * check-known-to-fail
+ *
+ * check-output-start
+test_char:
+.L0:
+ <entry-point>
+ ret.32 "char"
+
+
+test_schar:
+.L2:
+ <entry-point>
+ ret.32 "signed char"
+
+
+test_uchar:
+.L4:
+ <entry-point>
+ ret.32 "unsigned char"
+
+
+ * check-output-end
+ */
diff --git a/validation/generic-typename.c b/validation/generic-typename.c
new file mode 100644
index 00000000..1e914c57
--- /dev/null
+++ b/validation/generic-typename.c
@@ -0,0 +1,157 @@
+#define typename(x) _Generic((x) 0, \
+_Bool: "_Bool", \
+char: "char", \
+unsigned char: "unsigned char", \
+short: "short", \
+unsigned short: "unsigned short", \
+int: "int", \
+unsigned int: "unsigned int", \
+long: "long", \
+unsigned long: "unsigned long", \
+long long: "long long", \
+unsigned long long: "unsigned long long", \
+float: "float", \
+double: "double", \
+long double: "long double", \
+void *: "void *", \
+char *: "char *", \
+int *: "int *", \
+default: "???")
+
+#define TEST(name, x) \
+static const char *test_ ## name(void) { return typename(x); }
+
+TEST(bool, _Bool)
+TEST(char, char)
+TEST(uchar, unsigned char)
+TEST(short, short)
+TEST(ushort, unsigned short)
+TEST(int, int)
+TEST(uint, unsigned int)
+TEST(long, long)
+TEST(ulong, unsigned long)
+TEST(llong, long long)
+TEST(ullong, unsigned long long)
+TEST(float, float)
+TEST(double, double)
+TEST(ldouble, long double)
+TEST(vptr, void *)
+TEST(cptr, char *)
+TEST(iptr, int *)
+TEST(int128, __int128)
+
+/*
+ * check-name: generic-typename
+ * check-command: test-linearize --arch=i386 -fsigned-char $file
+ *
+ * check-output-start
+test_bool:
+.L0:
+ <entry-point>
+ ret.32 "_Bool"
+
+
+test_char:
+.L2:
+ <entry-point>
+ ret.32 "char"
+
+
+test_uchar:
+.L4:
+ <entry-point>
+ ret.32 "unsigned char"
+
+
+test_short:
+.L6:
+ <entry-point>
+ ret.32 "short"
+
+
+test_ushort:
+.L8:
+ <entry-point>
+ ret.32 "unsigned short"
+
+
+test_int:
+.L10:
+ <entry-point>
+ ret.32 "int"
+
+
+test_uint:
+.L12:
+ <entry-point>
+ ret.32 "unsigned int"
+
+
+test_long:
+.L14:
+ <entry-point>
+ ret.32 "long"
+
+
+test_ulong:
+.L16:
+ <entry-point>
+ ret.32 "unsigned long"
+
+
+test_llong:
+.L18:
+ <entry-point>
+ ret.32 "long long"
+
+
+test_ullong:
+.L20:
+ <entry-point>
+ ret.32 "unsigned long long"
+
+
+test_float:
+.L22:
+ <entry-point>
+ ret.32 "float"
+
+
+test_double:
+.L24:
+ <entry-point>
+ ret.32 "double"
+
+
+test_ldouble:
+.L26:
+ <entry-point>
+ ret.32 "long double"
+
+
+test_vptr:
+.L28:
+ <entry-point>
+ ret.32 "void *"
+
+
+test_cptr:
+.L30:
+ <entry-point>
+ ret.32 "char *"
+
+
+test_iptr:
+.L32:
+ <entry-point>
+ ret.32 "int *"
+
+
+test_int128:
+.L34:
+ <entry-point>
+ ret.32 "???"
+
+
+ * check-output-end
+ */