From c8a0a219fda4028ee80aa310588652d66a070ff5 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Sat, 21 Apr 2007 21:47:35 +0000 Subject: [PATCH] re PR c/30265 (Compound literal can cause invalid gimple) 2007-04-21 Andrew Pinski PR C/30265 * c-gimplifier.c (gimplify_compound_literal_expr): Mark the decl as addressable if the compound literal was marked as addressable. Mark the decl as a gimple register if it is a complex or vector decl and does not live in memory. 2007-04-21 Andrew Pinski PR C/30265 * gcc.c-torture/compile/compound-literal-2.c: New testcase. * gcc.c-torture/compile/compound-literal-3.c: New testcase. From-SVN: r124024 --- gcc/ChangeLog | 9 +++++++++ gcc/c-gimplify.c | 14 ++++++++++++++ gcc/testsuite/ChangeLog | 6 ++++++ .../gcc.c-torture/compile/compound-literal-2.c | 8 ++++++++ .../gcc.c-torture/compile/compound-literal-3.c | 8 ++++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/compile/compound-literal-2.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/compound-literal-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fe2dbaa4e98..8f74ec8492f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2007-04-21 Andrew Pinski + + PR C/30265 + * c-gimplifier.c (gimplify_compound_literal_expr): Mark the + decl as addressable if the compound literal was marked as + addressable. + Mark the decl as a gimple register if it is a complex or + vector decl and does not live in memory. + 2007-04-21 Andrew Pinski * tree.h (GIMPLE_TUPLE_P): Also true for PHI_NODEs. diff --git a/gcc/c-gimplify.c b/gcc/c-gimplify.c index 7ddc88cf4ea..2a3803a6458 100644 --- a/gcc/c-gimplify.c +++ b/gcc/c-gimplify.c @@ -183,6 +183,20 @@ gimplify_compound_literal_expr (tree *expr_p, tree *pre_p) { tree decl_s = COMPOUND_LITERAL_EXPR_DECL_STMT (*expr_p); tree decl = DECL_EXPR_DECL (decl_s); + /* Mark the decl as addressable if the compound literal + expression is addressable now, otherwise it is marked too late + after we gimplify the initialization expression. */ + if (TREE_ADDRESSABLE (*expr_p)) + TREE_ADDRESSABLE (decl) = 1; + + /* Preliminarily mark non-addressed complex variables as eligible + for promotion to gimple registers. We'll transform their uses + as we find them. */ + if ((TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE + || TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE) + && !TREE_THIS_VOLATILE (decl) + && !needs_to_live_in_memory (decl)) + DECL_GIMPLE_REG_P (decl) = 1; /* This decl isn't mentioned in the enclosing block, so add it to the list of temps. FIXME it seems a bit of a kludge to say that diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3157d85de1d..e5772ffb52f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-04-21 Andrew Pinski + + PR C/30265 + * gcc.c-torture/compile/compound-literal-2.c: New testcase. + * gcc.c-torture/compile/compound-literal-3.c: New testcase. + 2007-04-21 Richard Guenther PR middle-end/31136 diff --git a/gcc/testsuite/gcc.c-torture/compile/compound-literal-2.c b/gcc/testsuite/gcc.c-torture/compile/compound-literal-2.c new file mode 100644 index 00000000000..7e2f304005a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/compound-literal-2.c @@ -0,0 +1,8 @@ +/* PR C/30265, invalid gimple was produced because we did not mark + the compound literal's decl early enough. */ + +int f(float *); +int g(float x) +{ + return f(&(float){x}) + f(&x); +} diff --git a/gcc/testsuite/gcc.c-torture/compile/compound-literal-3.c b/gcc/testsuite/gcc.c-torture/compile/compound-literal-3.c new file mode 100644 index 00000000000..bcd413c9ca1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/compound-literal-3.c @@ -0,0 +1,8 @@ +/* PR C/30265, invalid gimple was produced because we did not mark + the compound literal's decl early enough. */ + +int f(_Complex float *); +int g(_Complex float x) +{ + return f(&(_Complex float){x+1}) + f(&x); +}