From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 374FF385801D for ; Mon, 2 Nov 2020 21:16:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 374FF385801D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joseph_myers@mentor.com IronPort-SDR: AFlI8hyq+cKhorU8Op2k48qvmb+gxlbvyyA8jqgWxtsPRSqjRlmOc9fStPRAJnOlNmDSjaaNWu aGsD3PqxzfxGuBuiikYNwJkdcEsGb3DmzmU1tjwDGksRM2iyRXx93fBGle2mIG2HNJKr4SYTfM 2VgZSdLFNbHRERloVLB2fqP+6LWyxtlKnV0eNGkq+C0/uYzRdRaL7fMtSP2Py4dMNF3GQFUBRy p2ByarfegRDbWfR50D3dAnNuJ7vc2yxAXk7hB37qVS5rdHbSVftXSnQVH2yMlqhxfA2Qri6uLV 09o= X-IronPort-AV: E=Sophos;i="5.77,445,1596528000"; d="scan'208";a="54727968" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 02 Nov 2020 13:16:29 -0800 IronPort-SDR: Ook/6beDAWsB1XJ+QMn//KirppQJxL+ZBfHoPfvcIbNB7W9Qp2U5W/TXiKL1fWUSdj5OYQjBJz SXTWIhZrCCY5c105s9z/hW3AE6Tw2ZufEfyTb4BffSGq6XHbnQ2bDRv8KTVM3B/MZOCkyEri8/ wpnt440gxMdb3KOZiQqzdkfVEPx94O1NW6eE9dr7kCrj7Uhzgd4fSuwVwL3mg0+O7UlvAfIPAr UJ4Qjabe4LpNVjuR5oEl1Rdl3EWZ+b5W+0Muah9JRkEPE8DlSmPaFVgFfMW09SsXlCVJuMbZ9x evM= Date: Mon, 2 Nov 2020 21:16:24 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: "Uecker, Martin" CC: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH] mixing of labels and code in C2X In-Reply-To: <1604270066.32038.5.camel@med.uni-goettingen.de> Message-ID: References: <1599996046.28509.3.camel@med.uni-goettingen.de> <1604270066.32038.5.camel@med.uni-goettingen.de> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-05.mgc.mentorg.com (139.181.222.5) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3124.2 required=5.0 tests=BAYES_00, BODY_8BITS, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Nov 2020 21:16:32 -0000 On Sun, 1 Nov 2020, Uecker, Martin wrote: > @@ -5693,27 +5692,54 @@ c_parser_compound_statement_nostart (c_parser *parser) >     last_label = true; >     last_stmt = false; >     mark_valid_location_for_stdc_pragma (false); > -   c_parser_label (parser); > +   c_parser_label (parser, std_attrs); > + > +   /* Allow '__attribute__((fallthrough));'.  */ > +   if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) > +     { > +       location_t loc = c_parser_peek_token (parser)->location; > +       tree attrs = c_parser_gnu_attributes (parser); > +       if (attribute_fallthrough_p (attrs)) > + { > +   if (c_parser_next_token_is (parser, CPP_SEMICOLON)) > +     { > +       tree fn = build_call_expr_internal_loc (loc, > +       IFN_FALLTHROUGH, > +       void_type_node, 0); > +       add_stmt (fn); > +     } > +   else > +      warning_at (loc, OPT_Wattributes, "% attribute " > +   "not followed by %<;%>"); > + } > +       else if (attrs != NULL_TREE) > + warning_at (loc, OPT_Wattributes, "only attribute %" > +     " can be applied to a null statement"); > +     } I don't think this is necessary or correct here. This code is being moved from c_parser_label. The syntax that c_parser_label was supposed to handle, as shown in the comment above the function, is: label: identifier : gnu-attributes[opt] case constant-expression : default : GNU extensions: label: case constant-expression ... constant-expression : That is: attributes on a label that is an identifier were parsed, and applied to the identifier, by code that's unchanged (beyond applying standard attributes rather than just warning in the caller that they are unused) by this patch. So this code could only fire in c_parser_label for a case or default label, a case in which GNU attributes on the label are not part of the syntax. Previously, a case or default label could not be followed by a declaration, so there was no particular concern about consuming prefix GNU attributes on such a following declaration; the declaration would still result in a syntax error (and fallthrough attributes were the only valid case needing to be handled). Now that such a declaration is valid, I think the attributes should be be parsed specially here, but left to apply to that declaration. The code in c_parser_declaration_or_fndef that handles GNU fallthrough attributes should suffice to handle one in this case; other warnings for empty declarations should suffice in the case where there are other attributes but no declaration following. > @@ -5843,12 +5879,10 @@ c_parser_all_labels (c_parser *parser) >     GNU C accepts any expressions without commas, non-constant >     expressions being rejected later.  Any standard >     attribute-specifier-sequence before the first label has been parsed > -   in the caller, to distinguish statements from declarations.  Any > -   attribute-specifier-sequence after the label is parsed in this > -   function.  */ > +   in the caller, to distinguish statements from declarations.  */ I don't think this change to the comment is accurate. As shown in the (unmodified) syntax comment, GNU attributes on a label that is an identifier (the only kind that has them) are still parsed in this function. It's only fallthrough attributes after case and default labels (which weren't part of that syntax comment anyway) that are no longer parsed here. > @@ -5898,8 +5932,13 @@ c_parser_label (c_parser *parser) >        if (tlab) >   { >     decl_attributes (&tlab, attrs, 0); > +   decl_attributes (&tlab, std_attrs, 0); >     label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); >   } > +      if (attrs > +   && c_parser_next_tokens_start_declaration (parser)) > +   warning_at (loc2, OPT_Wattributes, "GNU-style attribute between" > +       " label and declaration appertains to the label."); No trailing '.' on diagnostics. -- Joseph S. Myers joseph@codesourcery.com