* gcc.dg/ubsan/static-init-null.c: New testcase
authorIvan Baravy <i.baravy@samsung.com>
Tue, 21 Feb 2017 18:26:42 +0000 (21:26 +0300)
committerSlava Barinov <v.barinov@samsung.com>
Wed, 13 Sep 2023 11:13:17 +0000 (14:13 +0300)
gcc/testsuite/gcc.dg/ubsan/static-init-null.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.dg/ubsan/static-init-null.c b/gcc/testsuite/gcc.dg/ubsan/static-init-null.c
new file mode 100644 (file)
index 0000000..678e33c
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=null" } */
+
+typedef struct a_s a_t;
+typedef struct b_s b_t;
+
+struct b_s
+{
+  int n;
+};
+
+struct a_s
+{
+  int n;
+};
+
+static a_t arr[] = {
+  {
+    .n = 1,
+  },
+};
+
+__attribute__ ((used)) static b_t inited_struct = {
+  .n = arr == 0 ? 0 : 16 / sizeof (arr[0]),
+};