diff mbox series

[02/17] add testcase for expansion of default initializers

Message ID 20191210225921.94897-3-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series improve expansion of constant symbols | expand

Commit Message

Luc Van Oostenryck Dec. 10, 2019, 10:59 p.m. UTC
Currently, constant_symbol_value() is doing the expansion
of a constant initializer when an explicit one is found
but nothing is done for the default/implicit ones.

Add a testcase to illustrate this.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/expand/default-init-array.c  | 16 ++++++++++++++++
 validation/expand/default-init-struct.c | 23 +++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 validation/expand/default-init-array.c
 create mode 100644 validation/expand/default-init-struct.c
diff mbox series

Patch

diff --git a/validation/expand/default-init-array.c b/validation/expand/default-init-array.c
new file mode 100644
index 000000000000..b372ea09534b
--- /dev/null
+++ b/validation/expand/default-init-array.c
@@ -0,0 +1,16 @@ 
+int test_array(int i)
+{
+	static const int a[3] = { [0] = 1, [2] = 3, };
+
+	return a[1];
+}
+
+/*
+ * check-name: default-init-array
+ * check-command: test-linearize -Wno-decl -fdump-ir $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: phisrc\\..*return.*\\$0
+ * check-output-excludes: load\\.
+ */
diff --git a/validation/expand/default-init-struct.c b/validation/expand/default-init-struct.c
new file mode 100644
index 000000000000..c843a1abb960
--- /dev/null
+++ b/validation/expand/default-init-struct.c
@@ -0,0 +1,23 @@ 
+struct s {
+	int a;
+	int b;
+	int c;
+};
+
+
+int test_struct(void)
+{
+	struct s s = { .a = 1, .c = 3, };
+
+	return s.b;
+}
+
+/*
+ * check-name: default-init-struct
+ * check-command: test-linearize -Wno-decl -fdump-ir $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: phisrc\\..*return.*\\$0
+ * check-output-excludes: load\\.
+ */