]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/56241 (ICE in toplev.c:332 on invalid)
authorJakub Jelinek <jakub@redhat.com>
Tue, 19 Feb 2013 17:24:37 +0000 (18:24 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 19 Feb 2013 17:24:37 +0000 (18:24 +0100)
Backported from mainline
2013-02-07  Jakub Jelinek  <jakub@redhat.com>

PR c++/56241
* init.c (build_vec_init): Don't append NULL values into new_vec.
(build_zero_init_1): Don't push anything into v if recursive call
returned NULL_TREE.
(build_value_init_noctor): Don't push anything into v if
build_value_init call returned NULL_TREE.

* g++.dg/parse/crash61.C: New test.

From-SVN: r196146

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/crash61.C [new file with mode: 0644]

index 3d34bdc9c228618a4a2f173db13beb44bd135174..6086d2b213c0128422aac2673148ebbcbf047621 100644 (file)
@@ -2,7 +2,14 @@
 
        Backported from mainline
        2013-02-07  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/56241
+       * init.c (build_vec_init): Don't append NULL values into new_vec.
+       (build_zero_init_1): Don't push anything into v if recursive call
+       returned NULL_TREE.
+       (build_value_init_noctor): Don't push anything into v if
+       build_value_init call returned NULL_TREE.
+
        PR c++/56239
        * parser.c (cp_parser_token_starts_cast_expression): Renamed to...
        (cp_parser_tokens_start_cast_expression): ... this.  Change parameter
index 39db56169c5c744bbf0f1291115dcefad080dced..afd082c24bc5ae4df2e1c540e460550a65448d67 100644 (file)
@@ -254,21 +254,23 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p,
         have an upper bound of -1.  */
       if (!tree_int_cst_equal (max_index, integer_minus_one_node))
        {
-         constructor_elt *ce;
-
-         v = VEC_alloc (constructor_elt, gc, 1);
-         ce = VEC_quick_push (constructor_elt, v, NULL);
+         constructor_elt ce;
 
          /* If this is a one element array, we just use a regular init.  */
          if (tree_int_cst_equal (size_zero_node, max_index))
-           ce->index = size_zero_node;
+           ce.index = size_zero_node;
          else
-           ce->index = build2 (RANGE_EXPR, sizetype, size_zero_node,
-                               max_index);
+           ce.index = build2 (RANGE_EXPR, sizetype, size_zero_node,
+                              max_index);
 
-         ce->value = build_zero_init_1 (TREE_TYPE (type),
-                                        /*nelts=*/NULL_TREE,
-                                        static_storage_p, NULL_TREE);
+         ce.value = build_zero_init_1 (TREE_TYPE (type),
+                                       /*nelts=*/NULL_TREE,
+                                       static_storage_p, NULL_TREE);
+         if (ce.value)
+           {
+             v = VEC_alloc (constructor_elt, gc, 1);
+             *VEC_quick_push (constructor_elt, v, NULL) = ce;
+           }
        }
 
       /* Build a constructor to contain the initializations.  */
@@ -449,28 +451,31 @@ build_value_init_noctor (tree type, tsubst_flags_t complain)
         have an upper bound of -1.  */
       if (!tree_int_cst_equal (max_index, integer_minus_one_node))
        {
-         constructor_elt *ce;
-
-         v = VEC_alloc (constructor_elt, gc, 1);
-         ce = VEC_quick_push (constructor_elt, v, NULL);
+         constructor_elt ce;
 
          /* If this is a one element array, we just use a regular init.  */
          if (tree_int_cst_equal (size_zero_node, max_index))
-           ce->index = size_zero_node;
+           ce.index = size_zero_node;
          else
-           ce->index = build2 (RANGE_EXPR, sizetype, size_zero_node,
-                               max_index);
+           ce.index = build2 (RANGE_EXPR, sizetype, size_zero_node,
+                              max_index);
 
-         ce->value = build_value_init (TREE_TYPE (type), complain);
+         ce.value = build_value_init (TREE_TYPE (type), complain);
 
-         if (ce->value == error_mark_node)
-           return error_mark_node;
+         if (ce.value)
+           {
+             if (ce.value == error_mark_node)
+               return error_mark_node;
+
+             v = VEC_alloc (constructor_elt, gc, 1);
+             *VEC_quick_push (constructor_elt, v, NULL) = ce;
 
-         /* We shouldn't have gotten here for anything that would need
-            non-trivial initialization, and gimplify_init_ctor_preeval
-            would need to be fixed to allow it.  */
-         gcc_assert (TREE_CODE (ce->value) != TARGET_EXPR
-                     && TREE_CODE (ce->value) != AGGR_INIT_EXPR);
+             /* We shouldn't have gotten here for anything that would need
+                non-trivial initialization, and gimplify_init_ctor_preeval
+                would need to be fixed to allow it.  */
+             gcc_assert (TREE_CODE (ce.value) != TARGET_EXPR
+                         && TREE_CODE (ce.value) != AGGR_INIT_EXPR);
+           }
        }
 
       /* Build a constructor to contain the initializations.  */
@@ -3335,9 +3340,12 @@ build_vec_init (tree base, tree maxindex, tree init,
              else
                {
                  if (do_static_init)
-                   CONSTRUCTOR_APPEND_ELT (new_vec, field,
-                                           build_zero_init (TREE_TYPE (e),
-                                                            NULL_TREE, true));
+                   {
+                     tree value = build_zero_init (TREE_TYPE (e), NULL_TREE,
+                                                   true);
+                     if (value)
+                       CONSTRUCTOR_APPEND_ELT (new_vec, field, value);
+                   }
                  saw_non_const = true;
                }
            }
index c66b5112c4d9b8864a9c276387f186cc20c6db20..cdc9e6195bb007ebf7e6c18b6d8537a3d1102ded 100644 (file)
@@ -2,7 +2,10 @@
 
        Backported from mainline
        2013-02-07  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/56241
+       * g++.dg/parse/crash61.C: New test.
+
        PR c++/56239
        * g++.dg/parse/pr56239.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/parse/crash61.C b/gcc/testsuite/g++.dg/parse/crash61.C
new file mode 100644 (file)
index 0000000..790df0e
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/56241
+// { dg-do compile }
+
+struct pair { constexpr pair (const) : }; // { dg-error "" }
+template <0> make_pair () {}             // { dg-error "" }
+pair prefix[] = { 0, make_pair }         // { dg-error "" }