diff mbox series

[07/17] add test for constant expansion of complex initializer

Message ID 20191210225921.94897-8-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
Constant expansion of symbols with a complex type is not done
like for simpler ones. Only the first-level EXPR_INITIALIZER
is handled.

Add some testcases for this.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 .../expand/constant-init-nested-array.c       | 15 ++++++++++++
 .../expand/constant-init-nested-struct.c      | 23 +++++++++++++++++++
 validation/expand/constant-init-string.c      | 15 ++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 validation/expand/constant-init-nested-array.c
 create mode 100644 validation/expand/constant-init-nested-struct.c
 create mode 100644 validation/expand/constant-init-string.c
diff mbox series

Patch

diff --git a/validation/expand/constant-init-nested-array.c b/validation/expand/constant-init-nested-array.c
new file mode 100644
index 000000000000..0d50d955287c
--- /dev/null
+++ b/validation/expand/constant-init-nested-array.c
@@ -0,0 +1,15 @@ 
+int foo(void)
+{
+	int a[2][3] = {{0, 1, 2},{3, 4, 5}};
+	return a[1][2];
+}
+
+/*
+ * check-name: constant-init-nested-array
+ * check-command: test-linearize -Wno-decl -fdump-ir $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: phisrc\\..*\\$5
+ * check-output-excludes: load\\.
+ */
diff --git a/validation/expand/constant-init-nested-struct.c b/validation/expand/constant-init-nested-struct.c
new file mode 100644
index 000000000000..f27de556f6c5
--- /dev/null
+++ b/validation/expand/constant-init-nested-struct.c
@@ -0,0 +1,23 @@ 
+struct s {
+	int a;
+	struct {
+		int b;
+		int c;
+	} s;
+};
+
+int foo(void)
+{
+	struct s s = {1, {2, 3}};
+	return s.s.c;
+}
+
+/*
+ * check-name: constant-init-nested-struct
+ * check-command: test-linearize -Wno-decl -fdump-ir $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: phisrc\\..*\\$3
+ * check-output-excludes: load\\.
+ */
diff --git a/validation/expand/constant-init-string.c b/validation/expand/constant-init-string.c
new file mode 100644
index 000000000000..42ae9bd3d8a4
--- /dev/null
+++ b/validation/expand/constant-init-string.c
@@ -0,0 +1,15 @@ 
+char foo(void)
+{
+	static const char s[] = "abc?";
+	return s[3];
+}
+
+/*
+ * check-name: constant-init-nested-array
+ * check-command: test-linearize -Wno-decl -fdump-ir $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: phisrc\\..*\\$63
+ * check-output-pattern(0,1): load\\.
+ */