]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/83824 (ICE on invalid C++ code with alignas: in chainon, at tree...
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 17:12:28 +0000 (19:12 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 17:12:28 +0000 (19:12 +0200)
Backported from mainline
2018-01-18  Jakub Jelinek  <jakub@redhat.com>

PR c++/83824
* parser.c (attr_chainon): New function.
(cp_parser_label_for_labeled_statement, cp_parser_decl_specifier_seq,
cp_parser_namespace_definition, cp_parser_init_declarator,
cp_parser_type_specifier_seq, cp_parser_parameter_declaration,
cp_parser_gnu_attributes_opt): Use it.
(cp_parser_member_declaration, cp_parser_objc_class_ivars,
cp_parser_objc_struct_declaration): Likewise.  Don't reset
prefix_attributes if attributes is error_mark_node.

* g++.dg/cpp0x/pr83824.C: New test.

From-SVN: r262054

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr83824.C [new file with mode: 0644]

index 4113b0a394d56581bbbe9fcbb99e2ad6d1b8f454..d041338bdd3071876ff880751d81ecde47fa7adb 100644 (file)
@@ -1,6 +1,18 @@
 2018-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-01-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/83824
+       * parser.c (attr_chainon): New function.
+       (cp_parser_label_for_labeled_statement, cp_parser_decl_specifier_seq,
+       cp_parser_namespace_definition, cp_parser_init_declarator,
+       cp_parser_type_specifier_seq, cp_parser_parameter_declaration,
+       cp_parser_gnu_attributes_opt): Use it.
+       (cp_parser_member_declaration, cp_parser_objc_class_ivars,
+       cp_parser_objc_struct_declaration): Likewise.  Don't reset
+       prefix_attributes if attributes is error_mark_node.
+
        2017-12-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79650
index 09d78aefe501f4d03d6e98279535b51d1dd37dfc..4157c53b668ab859b756d0864e9013a059272ee5 100644 (file)
@@ -10559,6 +10559,18 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
                "attributes at the beginning of statement are ignored");
 }
 
+/* Append ATTR to attribute list ATTRS.  */
+
+static tree
+attr_chainon (tree attrs, tree attr)
+{
+  if (attrs == error_mark_node)
+    return error_mark_node;
+  if (attr == error_mark_node)
+    return error_mark_node;
+  return chainon (attrs, attr);
+}
+
 /* Parse the label for a labeled-statement, i.e.
 
    identifier :
@@ -10664,7 +10676,7 @@ cp_parser_label_for_labeled_statement (cp_parser* parser, tree attributes)
       else if (!cp_parser_parse_definitely (parser))
        ;
       else
-       attributes = chainon (attributes, attrs);
+       attributes = attr_chainon (attributes, attrs);
     }
 
   if (attributes != NULL_TREE)
@@ -12634,8 +12646,7 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
                  else
                    {
                      decl_specs->std_attributes
-                       = chainon (decl_specs->std_attributes,
-                                  attrs);
+                       = attr_chainon (decl_specs->std_attributes, attrs);
                      if (decl_specs->locations[ds_std_attribute] == 0)
                        decl_specs->locations[ds_std_attribute] = token->location;
                    }
@@ -12643,9 +12654,8 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
                }
            }
 
-           decl_specs->attributes
-             = chainon (decl_specs->attributes,
-                        attrs);
+         decl_specs->attributes
+           = attr_chainon (decl_specs->attributes, attrs);
          if (decl_specs->locations[ds_attribute] == 0)
            decl_specs->locations[ds_attribute] = token->location;
          continue;
@@ -17575,7 +17585,7 @@ cp_parser_namespace_definition (cp_parser* parser)
   if (post_ident_attribs)
     {
       if (attribs)
-        attribs = chainon (attribs, post_ident_attribs);
+        attribs = attr_chainon (attribs, post_ident_attribs);
       else
         attribs = post_ident_attribs;
     }
@@ -18705,7 +18715,7 @@ cp_parser_init_declarator (cp_parser* parser,
       decl = grokfield (declarator, decl_specifiers,
                        initializer, !is_non_constant_init,
                        /*asmspec=*/NULL_TREE,
-                       chainon (attributes, prefix_attributes));
+                       attr_chainon (attributes, prefix_attributes));
       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
        cp_parser_save_default_args (parser, decl);
       cp_finalize_omp_declare_simd (parser, decl);
@@ -20058,9 +20068,9 @@ cp_parser_type_specifier_seq (cp_parser* parser,
       /* Check for attributes first.  */
       if (cp_next_tokens_can_be_attribute_p (parser))
        {
-         type_specifier_seq->attributes =
-           chainon (type_specifier_seq->attributes,
-                    cp_parser_attributes_opt (parser));
+         type_specifier_seq->attributes
+           = attr_chainon (type_specifier_seq->attributes,
+                           cp_parser_attributes_opt (parser));
          continue;
        }
 
@@ -20539,8 +20549,8 @@ cp_parser_parameter_declaration (cp_parser *parser,
       parser->default_arg_ok_p = saved_default_arg_ok_p;
       /* After the declarator, allow more attributes.  */
       decl_specifiers.attributes
-       = chainon (decl_specifiers.attributes,
-                  cp_parser_attributes_opt (parser));
+       = attr_chainon (decl_specifiers.attributes,
+                       cp_parser_attributes_opt (parser));
 
       /* If the declarator is a template parameter pack, remember that and
         clear the flag in the declarator itself so we don't get errors
@@ -22491,7 +22501,7 @@ cp_parser_member_declaration (cp_parser* parser)
                 which are not.  */
              first_attribute = attributes;
              /* Combine the attributes.  */
-             attributes = chainon (prefix_attributes, attributes);
+             attributes = attr_chainon (prefix_attributes, attributes);
 
              /* Create the bitfield declaration.  */
              decl = grokbitfield (identifier
@@ -22548,7 +22558,7 @@ cp_parser_member_declaration (cp_parser* parser)
                 which are not.  */
              first_attribute = attributes;
              /* Combine the attributes.  */
-             attributes = chainon (prefix_attributes, attributes);
+             attributes = attr_chainon (prefix_attributes, attributes);
 
              /* If it's an `=', then we have a constant-initializer or a
                 pure-specifier.  It is not correct to parse the
@@ -22662,10 +22672,13 @@ cp_parser_member_declaration (cp_parser* parser)
          cp_finalize_oacc_routine (parser, decl, false);
 
          /* Reset PREFIX_ATTRIBUTES.  */
-         while (attributes && TREE_CHAIN (attributes) != first_attribute)
-           attributes = TREE_CHAIN (attributes);
-         if (attributes)
-           TREE_CHAIN (attributes) = NULL_TREE;
+         if (attributes != error_mark_node)
+           {
+             while (attributes && TREE_CHAIN (attributes) != first_attribute)
+               attributes = TREE_CHAIN (attributes);
+             if (attributes)
+               TREE_CHAIN (attributes) = NULL_TREE;
+           }
 
          /* If there is any qualification still in effect, clear it
             now; we will be starting fresh with the next declarator.  */
@@ -23765,7 +23778,7 @@ cp_parser_gnu_attributes_opt (cp_parser* parser)
        cp_parser_skip_to_end_of_statement (parser);
 
       /* Add these new attributes to the list.  */
-      attributes = chainon (attributes, attribute_list);
+      attributes = attr_chainon (attributes, attribute_list);
     }
 
   return attributes;
@@ -28876,7 +28889,7 @@ cp_parser_objc_class_ivars (cp_parser* parser)
             which are not.  */
          first_attribute = attributes;
          /* Combine the attributes.  */
-         attributes = chainon (prefix_attributes, attributes);
+         attributes = attr_chainon (prefix_attributes, attributes);
 
          if (width)
              /* Create the bitfield declaration.  */
@@ -28893,10 +28906,13 @@ cp_parser_objc_class_ivars (cp_parser* parser)
            objc_add_instance_variable (decl);
 
          /* Reset PREFIX_ATTRIBUTES.  */
-         while (attributes && TREE_CHAIN (attributes) != first_attribute)
-           attributes = TREE_CHAIN (attributes);
-         if (attributes)
-           TREE_CHAIN (attributes) = NULL_TREE;
+         if (attributes != error_mark_node)
+           {
+             while (attributes && TREE_CHAIN (attributes) != first_attribute)
+               attributes = TREE_CHAIN (attributes);
+             if (attributes)
+               TREE_CHAIN (attributes) = NULL_TREE;
+           }
 
          token = cp_lexer_peek_token (parser->lexer);
 
@@ -29426,8 +29442,8 @@ cp_parser_objc_struct_declaration (cp_parser *parser)
         which are not.  */
       first_attribute = attributes;
       /* Combine the attributes.  */
-      attributes = chainon (prefix_attributes, attributes);
-      
+      attributes = attr_chainon (prefix_attributes, attributes);
+
       decl = grokfield (declarator, &declspecs,
                        NULL_TREE, /*init_const_expr_p=*/false,
                        NULL_TREE, attributes);
@@ -29436,10 +29452,13 @@ cp_parser_objc_struct_declaration (cp_parser *parser)
        return error_mark_node;
       
       /* Reset PREFIX_ATTRIBUTES.  */
-      while (attributes && TREE_CHAIN (attributes) != first_attribute)
-       attributes = TREE_CHAIN (attributes);
-      if (attributes)
-       TREE_CHAIN (attributes) = NULL_TREE;
+      if (attributes != error_mark_node)
+       {
+         while (attributes && TREE_CHAIN (attributes) != first_attribute)
+           attributes = TREE_CHAIN (attributes);
+         if (attributes)
+           TREE_CHAIN (attributes) = NULL_TREE;
+       }
 
       DECL_CHAIN (decl) = decls;
       decls = decl;
index dde03d6687bfdc15aa92a6e682b80b032fdb4421..8033c0e9caee5c06e6f33098102e8ba58ea40c18 100644 (file)
@@ -1,6 +1,11 @@
 2018-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-01-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/83824
+       * g++.dg/cpp0x/pr83824.C: New test.
+
        2018-01-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/83605
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr83824.C b/gcc/testsuite/g++.dg/cpp0x/pr83824.C
new file mode 100644 (file)
index 0000000..9474e1e
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/83824
+// { dg-do compile { target c++11 } }
+
+void
+foo ()
+{
+  if (alignas(1 alignas(1)))   // { dg-error "expected" }
+    ;
+}