re PR c/5105 (compound literal patch broken with inlining)
authorJoseph Myers <jsm28@cam.ac.uk>
Mon, 17 Dec 2001 01:18:41 +0000 (01:18 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Mon, 17 Dec 2001 01:18:41 +0000 (01:18 +0000)
* c-common.def (COMPOUND_LITERAL_EXPR): Contain a DECL_STMT, not
a DECL directly.
* c-common.h (COMPOUND_LITERAL_EXPR_DECL_STMT): New.
(COMPOUND_LITERAL_EXPR_DECL): Adjust definition.
* c-decl.c (build_compound_literal): Put the decl inside a
DECL_STMT.
* doc/c-tree.texi (COMPOUND_LITERAL_EXPR): Update documentation.
Fixes PR c/5105.

testsuite:
* gcc.c-torture/compile/20011217-1.c: New test.

From-SVN: r48085

gcc/ChangeLog
gcc/c-common.def
gcc/c-common.h
gcc/c-decl.c
gcc/doc/c-tree.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20011217-1.c [new file with mode: 0644]

index e6d9be251de4bf5c0dadb862cc4f12c1adfc248b..c17e1cf71f09a34d8f728eef38be15a761cdf70b 100644 (file)
@@ -1,3 +1,14 @@
+2001-12-17  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * c-common.def (COMPOUND_LITERAL_EXPR): Contain a DECL_STMT, not
+       a DECL directly.
+       * c-common.h (COMPOUND_LITERAL_EXPR_DECL_STMT): New.
+       (COMPOUND_LITERAL_EXPR_DECL): Adjust definition.
+       * c-decl.c (build_compound_literal): Put the decl inside a
+       DECL_STMT.
+       * doc/c-tree.texi (COMPOUND_LITERAL_EXPR): Update documentation.
+       Fixes PR c/5105.
+
 2001-12-16  Aldy Hernandez  <aldyh@redhat.com>
 
         * config.gcc: Add powerpc-*-eabisimaltivec*.
 2001-12-16  Aldy Hernandez  <aldyh@redhat.com>
 
         * config.gcc: Add powerpc-*-eabisimaltivec*.
index 7840ce81610e9eed86f6d6dbedfa31efb16bd192..d9b14be05a9d71b3fef41c6e662fefdefe6efaa0 100644 (file)
@@ -103,7 +103,8 @@ DEFTREECODE (CASE_LABEL, "case_label", 'e', 3)
 DEFTREECODE (STMT_EXPR, "stmt_expr", 'e', 1)
 
 /* A COMPOUND_LITERAL_EXPR represents a C99 compound literal.  The
 DEFTREECODE (STMT_EXPR, "stmt_expr", 'e', 1)
 
 /* A COMPOUND_LITERAL_EXPR represents a C99 compound literal.  The
-   COMPOND_LITERAL_EXPR_DECL is the decl for the anonymous object
-   represented by the COMPOUND_LITERAL; the DECL_INITIAL of that
-   decl is the CONSTRUCTOR that initializes the compound literal.  */
+   COMPOND_LITERAL_EXPR_DECL_STMT is the a DECL_STMT containing the decl
+   for the anonymous object represented by the COMPOUND_LITERAL;
+   the DECL_INITIAL of that decl is the CONSTRUCTOR that initializes
+   the compound literal.  */
 DEFTREECODE (COMPOUND_LITERAL_EXPR, "compound_literal_expr", 'e', 1)
 DEFTREECODE (COMPOUND_LITERAL_EXPR, "compound_literal_expr", 'e', 1)
index 514c448ecb288ea7e4fe5d53fcad2e642eecf978..61b8f84428b79fc66a1359734bc7125f51524a70 100644 (file)
@@ -637,9 +637,11 @@ extern tree strip_array_types                   PARAMS ((tree));
    the given label statement.  */
 #define LABEL_STMT_LABEL(NODE)  TREE_OPERAND (LABEL_STMT_CHECK (NODE), 0)
 
    the given label statement.  */
 #define LABEL_STMT_LABEL(NODE)  TREE_OPERAND (LABEL_STMT_CHECK (NODE), 0)
 
-/* COMPOUND_LITERAL_EXPR accessor.  */
-#define COMPOUND_LITERAL_EXPR_DECL(NODE)               \
+/* COMPOUND_LITERAL_EXPR accessors.  */
+#define COMPOUND_LITERAL_EXPR_DECL_STMT(NODE)          \
   TREE_OPERAND (COMPOUND_LITERAL_EXPR_CHECK (NODE), 0)
   TREE_OPERAND (COMPOUND_LITERAL_EXPR_CHECK (NODE), 0)
+#define COMPOUND_LITERAL_EXPR_DECL(NODE)                       \
+  DECL_STMT_DECL (COMPOUND_LITERAL_EXPR_DECL_STMT (NODE))
 
 /* Nonzero if this SCOPE_STMT is for the beginning of a scope.  */
 #define SCOPE_BEGIN_P(NODE) \
 
 /* Nonzero if this SCOPE_STMT is for the beginning of a scope.  */
 #define SCOPE_BEGIN_P(NODE) \
index 011624e95e869d28adb61f909e7812fcdd5dcadc..c7e1e0a872a04b84ce8205b1087201b6837e2b6e 100644 (file)
@@ -3836,6 +3836,7 @@ build_compound_literal (type, init)
      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT.  */
   tree decl = build_decl (VAR_DECL, NULL_TREE, type);
   tree complit;
      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT.  */
   tree decl = build_decl (VAR_DECL, NULL_TREE, type);
   tree complit;
+  tree stmt;
   DECL_EXTERNAL (decl) = 0;
   TREE_PUBLIC (decl) = 0;
   TREE_STATIC (decl) = (current_binding_level == global_binding_level);
   DECL_EXTERNAL (decl) = 0;
   TREE_PUBLIC (decl) = 0;
   TREE_STATIC (decl) = (current_binding_level == global_binding_level);
@@ -3855,7 +3856,8 @@ build_compound_literal (type, init)
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
     return error_mark_node;
 
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
     return error_mark_node;
 
-  complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), decl);
+  stmt = build_stmt (DECL_STMT, decl);
+  complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), stmt);
   TREE_SIDE_EFFECTS (complit) = 1;
 
   layout_decl (decl, 0);
   TREE_SIDE_EFFECTS (complit) = 1;
 
   layout_decl (decl, 0);
index 4046d18c4b45ee80849e54494e67cc61439fb716..8d226474e49fe4bf5bb7e54c8a754db8c8eb7667 100644 (file)
@@ -2219,13 +2219,16 @@ Conceptually, before any initialization is done, the entire area of
 storage is initialized to zero.
 
 @item COMPOUND_LITERAL_EXPR
 storage is initialized to zero.
 
 @item COMPOUND_LITERAL_EXPR
+@findex COMPOUND_LITERAL_EXPR_DECL_STMT
 @findex COMPOUND_LITERAL_EXPR_DECL
 These nodes represent ISO C99 compound literals.  The
 @findex COMPOUND_LITERAL_EXPR_DECL
 These nodes represent ISO C99 compound literals.  The
-@code{COMPOUND_LITERAL_EXPR_DECL} is an anonymous @code{VAR_DECL} for
+@code{COMPOUND_LITERAL_EXPR_DECL_STMT} is a @code{DECL_STMT}
+containing an anonymous @code{VAR_DECL} for
 the unnamed object represented by the compound literal; the
 @code{DECL_INITIAL} of that @code{VAR_DECL} is a @code{CONSTRUCTOR}
 representing the brace-enclosed list of initializers in the compound
 the unnamed object represented by the compound literal; the
 @code{DECL_INITIAL} of that @code{VAR_DECL} is a @code{CONSTRUCTOR}
 representing the brace-enclosed list of initializers in the compound
-literal.
+literal.  That anonymous @code{VAR_DECL} can also be accessed directly
+by the @code{COMPOUND_LITERAL_EXPR_DECL} macro.
 
 @item SAVE_EXPR
 
 
 @item SAVE_EXPR
 
index a838d6b5ca2153b6b2f282d76f57f329b968c167..170ff3fe7737338d5f2bcb1a3635d8e5878a7b17 100644 (file)
@@ -1,3 +1,7 @@
+2001-12-17  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.c-torture/compile/20011217-1.c: New test.
+
 2001-12-14  Aldy Hernandez  <aldyh@redhat.com>
 
        * testsuite/gcc.dg/20011214-1.c: New.
 2001-12-14  Aldy Hernandez  <aldyh@redhat.com>
 
        * testsuite/gcc.dg/20011214-1.c: New.
diff --git a/gcc/testsuite/gcc.c-torture/compile/20011217-1.c b/gcc/testsuite/gcc.c-torture/compile/20011217-1.c
new file mode 100644 (file)
index 0000000..3e89ca0
--- /dev/null
@@ -0,0 +1,20 @@
+/* Test that the initializer of a compound literal is properly walked
+   when tree inlining.  */
+/* Origin: PR c/5105 from <aj@suse.de>.  */
+
+typedef struct { long p; } pt;
+
+inline pt f (pt _p)
+{
+  long p = _p.p;
+
+  return (pt) { (p) };
+}
+
+static int mmap_mem (void)
+{
+  pt p;
+  p = f (p);
+
+  return 0;
+}