From 9fe9cc26a024923483d9ae3b6133c36b037cc4ab Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sat, 7 Dec 2019 02:43:13 +0100 Subject: add test for constant expansion of complex initializer 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 --- validation/expand/constant-init-nested-array.c | 15 +++++++++++++++ validation/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 --git a/validation/expand/constant-init-nested-array.c b/validation/expand/constant-init-nested-array.c new file mode 100644 index 00000000..0d50d955 --- /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 00000000..f27de556 --- /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 00000000..42ae9bd3 --- /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\\. + */ -- cgit 1.2.3-korg