aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-04-28 11:04:55 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-04-30 17:43:06 +0200
commit5f8653250bdcb034d57c29e8dccfd23e39d19443 (patch)
tree5ef5687fe989062efbe6cbb45c44658c78074fd5 /validation
parentb06354707e33bbf24b04315a6909d257ad854007 (diff)
downloadsparse-dev-5f8653250bdcb034d57c29e8dccfd23e39d19443.tar.gz
add testcases for verifying ABI's integer size & align
It's easy to make some errors or some wrong assumptions about size and alignment of basic types, certainly so when taking in account the -m32, -m64 & -msize-llp64 flags and the default behaviour on different arch & environments. Try to catch these errors by adding a testcase for the size & alignment of int, long, long long & void*. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/abi-integer.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/validation/abi-integer.c b/validation/abi-integer.c
new file mode 100644
index 00000000..441b2094
--- /dev/null
+++ b/validation/abi-integer.c
@@ -0,0 +1,31 @@
+#define TEST(T, S, A) \
+ _Static_assert(sizeof(T) == S && _Alignof(T) == A, #T)
+
+int main(void)
+{
+ TEST(int, 4, 4);
+
+#if defined(__LP64__)
+ TEST(long, 8, 8);
+ TEST(void *, 8, 8);
+ TEST(long long, 8, 8);
+#elif defined(__LLP64__)
+ TEST(long, 4, 4);
+ TEST(void *, 8, 8);
+ TEST(long long, 8, 8);
+#elif defined(__x86_64__)
+ TEST(long, 4, 4);
+ TEST(void *, 4, 4);
+ TEST(long long, 8, 8);
+#else
+ TEST(long, 4, 4);
+ TEST(void *, 4, 4);
+ TEST(long long, 8, 4);
+#endif
+
+ return 0;
+}
+
+/*
+ * check-name: abi-integer
+ */