[PATCH 04/18] expand: add missing expansion of compound literals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Compound literals, like all other expressions, need to be be
expanded before linearization, but this is currently not done.
As consequence, some builtins are unexpectedly still present,
same for EXPR_TYPEs, ... with error messages like:
	warning: unknown expression
at linearization.

Fix this by adding the missing expansion of compound literals.

Note: as explained in the code itself, it's not totally clear
      how compound literals can be identified after evaluation.
      The code here consider all anonymous symbols with an
      initializer as being a compound literal.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 evaluate.c                             | 1 +
 expand.c                               | 8 ++++++++
 validation/expand/compound-literal.c   | 1 -
 validation/linear/compound-literal02.c | 1 -
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index f6dfcced7..70d76523e 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2935,6 +2935,7 @@ static struct symbol *evaluate_cast(struct expression *expr)
 	 * initializer, in which case we need to pass
 	 * the type value down to that initializer rather
 	 * than trying to evaluate it as an expression
+	 * (cfr. compound literals: C99 & C11 6.5.2.5).
 	 *
 	 * A more complex case is when the initializer is
 	 * dereferenced as part of a post-fix expression.
diff --git a/expand.c b/expand.c
index e8e50b080..aba20b8cf 100644
--- a/expand.c
+++ b/expand.c
@@ -61,6 +61,14 @@ static int expand_symbol_expression(struct expression *expr)
 		expr->taint = 0;
 		return 0;
 	}
+
+	// expand compound literals (C99 & C11 6.5.2.5)
+	// FIXME: is this the correct way to identify them?
+	//	All compound literals are anonymous but is
+	//	the reverse true?
+	if (sym->initializer && !expr->symbol_name)
+		return expand_expression(sym->initializer);
+
 	/* The cost of a symbol expression is lower for on-stack symbols */
 	return (sym->ctype.modifiers & (MOD_STATIC | MOD_EXTERN)) ? 2 : 1;
 }
diff --git a/validation/expand/compound-literal.c b/validation/expand/compound-literal.c
index 7401b0191..034164bca 100644
--- a/validation/expand/compound-literal.c
+++ b/validation/expand/compound-literal.c
@@ -13,7 +13,6 @@ static void foo(struct s *p)
 /*
  * check-name: compound-literal
  * check-command: test-linearize $file
- * check-known-to-fail
  *
  * check-output-start
 foo:
diff --git a/validation/linear/compound-literal02.c b/validation/linear/compound-literal02.c
index 87b98d76b..6ed5809eb 100644
--- a/validation/linear/compound-literal02.c
+++ b/validation/linear/compound-literal02.c
@@ -13,7 +13,6 @@ int bar(void)
  * check-name: compound-literal02.c
  * check-command: test-linearize -Wno-decl $file
  *
- * check-known-to-fail
  * check-output-ignore
  * check-output-contains: ret\\..*\\$6
  */
-- 
2.23.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux