From patchwork Wed Nov 20 23:15:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1198574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514256-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OFp9YEyL"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JJV16HZMz9s4Y for ; Thu, 21 Nov 2019 10:16:23 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=IIAYLvzeyM8kB7E9vcRYrJTJrl1z6QUj6J6BcNLOh+sxiom31vink 77uf1fSq+cmwd3SbrbPjUpxP863zEZzPhB/mvT6u1WOb4BIIEsBGcvbd2y2OfN+n uiSjRq4XEk7EviOYjoKW8yhLf5mEgpQblytqrYGfk7nVKeKx579vKA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=CmLgol8fzk+N7uC+hdvvSGWf1m0=; b=OFp9YEyL3NxX13NJ8dW7 ShBvbu41sx+k4MAOXZhk9TEUu5/JpP0eMy6iZSOr/hnV2+bbdZGyphaxPKDsu7Mk avS4WUakA0dDdLXTLJDheF6HEEUlQvQUdVMhN6Xu5bAgYnDNNihxI85fT+pwcqMf e4G8sgBDl8D7j/UskRFW4SI= Received: (qmail 118182 invoked by alias); 20 Nov 2019 23:16:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 118156 invoked by uid 89); 20 Nov 2019 23:16:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=duly, UD:c2x-attr-fallthrough-1.c, wextra, Wextra X-HELO: esa1.mentor.iphmx.com Received: from esa1.mentor.iphmx.com (HELO esa1.mentor.iphmx.com) (68.232.129.153) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 23:16:11 +0000 IronPort-SDR: B5P3q7jCradsY1VwQ9+r6SA3ZA4SS6W9oe0xu+kLed3UYnOoZ4AI25bzaMCqvU+OYe+8eEJjIh oyj/slyLli7PmgHOna1FbeC8yqfiAQLqrmk/sXEvrAurr+7OTNIQ8jNqmyqezuF4narolw4gFP koB0y9AQ81DzAIPZ4xsuJSgDWL9XQEmwFrtJThNGaBwBtPynKpHISdoxBD9BSoakKDEj4cUlDY 9CyFkLIZxk+wfE5ng9AQgHZiU5GR8mf+XT/uCwgR6YT/caxLT1La+pq3NtbraSiy423Iy64Znc IUY= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 20 Nov 2019 15:16:02 -0800 IronPort-SDR: wh3M9P1Fu0OaiHkexhbQI3GPJDr0VeokEfDZ/+EoU0eJLrF532DDSWGVr7QEosaEY1VVrZPA5g 0SNuDA16cSn5MPNErcCjwbXotKCHTXd3rWJM//njad+zgGgILtnzsNU3UMsUh1YmWyJ35aF+pY bX04gKuYy6anmhasCWztm45AQrX6QYJeA13LGlaA3TDPKxnfArfHUuvOPtGB1X3DRgWGAlINhy WKQI8Y7BaM3rlkPl34HJZQN+DV3uxPIXPPU81GF049eOJ2XtqSYHP6jf07xD6o/n143hXru1nY r7k= Date: Wed, 20 Nov 2019 23:15:56 +0000 From: Joseph Myers To: Subject: Make more bad uses of fallthrough attribute into pedwarns Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Various bad uses of the [[fallthrough]] attribute are constraint violations in C2x, so need pedwarns rather than warnings. This patch duly turns the relevant warnings into pedwarns. The relevant code is not specific to C, and does not know which form the attribute was given in ([[fallthrough]] or [[gnu::fallthrough]] or __attribute__((fallthrough))), but as I understand it these usages are also erroneous for C++ and it seems reasonable to give a pedwarn here even when a form other than [[fallthrough]] is being used. The precise meaning of the standard wording about "The next statement that would be executed" seems a but unclear in some corner cases; the tests added keep to cases where it is clear whether or not the next statement executed is of the required form. Bootstrapped with no regressions for x86_64-pc-linux-gnu. OK to commit (the gimplify.c changes)? gcc: 2019-11-20 Joseph Myers * gimplify.c (expand_FALLTHROUGH_r, expand_FALLTHROUGH): Use pedwarn instead of warning_at for fallthrough not preceding a case or default label. gcc/c-family: 2019-11-20 Joseph Myers * c-attribs.c (handle_fallthrough_attribute): Use pedwarn instead of warning. gcc/testsuite: 2019-11-20 Joseph Myers * gcc.dg/c2x-attr-fallthrough-6.c: New test. Split out from c2x-attr-fallthrough-3.c. * gcc.dg/c2x-attr-fallthrough-1.c: Add more tests. * gcc.dg/c2x-attr-fallthrough-2.c: Update expected diagnostics. * gcc.dg/c2x-attr-fallthrough-3.c: Split inside-switch part of test out to c2x-attr-fallthrough-6.c. Index: gcc/c-family/c-attribs.c =================================================================== --- gcc/c-family/c-attribs.c (revision 278510) +++ gcc/c-family/c-attribs.c (working copy) @@ -4117,7 +4117,7 @@ tree handle_fallthrough_attribute (tree *, tree name, tree, int, bool *no_add_attrs) { - warning (OPT_Wattributes, "%qE attribute ignored", name); + pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored", name); *no_add_attrs = true; return NULL_TREE; } Index: gcc/gimplify.c =================================================================== --- gcc/gimplify.c (revision 278510) +++ gcc/gimplify.c (working copy) @@ -2405,8 +2405,8 @@ expand_FALLTHROUGH_r (gimple_stmt_iterator *gsi_p, gsi_next (&gsi2); } if (!found) - warning_at (loc, 0, "attribute % not preceding " - "a case label or default label"); + pedwarn (loc, 0, "attribute % not preceding " + "a case label or default label"); } break; default: @@ -2428,8 +2428,8 @@ expand_FALLTHROUGH (gimple_seq *seq_p) if (wi.callback_result == integer_zero_node) /* We've found [[fallthrough]]; at the end of a switch, which the C++ standard says is ill-formed; see [dcl.attr.fallthrough]. */ - warning_at (loc, 0, "attribute % not preceding " - "a case label or default label"); + pedwarn (loc, 0, "attribute % not preceding " + "a case label or default label"); } Index: gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c =================================================================== --- gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c (revision 278510) +++ gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c (working copy) @@ -3,7 +3,7 @@ /* { dg-options "-std=c2x -pedantic-errors -Wextra" } */ int -f (int a) +f (int a, int c) { int b = 2; switch (a) @@ -22,6 +22,21 @@ int case 5: b += 1; break; + case 6: + if (c == 2) + { + [[fallthrough]]; + } + else + { + [[fallthrough]]; + } + case 7: + b += 3; + [[fallthrough]]; + default: + b += 8; + break; } return b; } Index: gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c =================================================================== --- gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c (revision 278510) +++ gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c (working copy) @@ -15,7 +15,8 @@ int z = sizeof (int [[fallthrough]]); /* { dg-erro int f (int a) { - [[fallthrough]] int b = 2; /* { dg-warning "not followed by|ignored" } */ + [[fallthrough]] int b = 2; /* { dg-warning "not followed by" } */ + /* { dg-error "ignored" "ignored" { target *-*-* } .-1 } */ switch (a) { case 1: Index: gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c =================================================================== --- gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c (revision 278510) +++ gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c (working copy) @@ -1,5 +1,5 @@ /* Test C2x attribute syntax. Invalid use of fallthrough attribute - outside switch or in bad context inside switch. */ + outside switch. */ /* { dg-do compile } */ /* { dg-options "-std=c2x -pedantic-errors -Wextra" } */ @@ -7,12 +7,5 @@ int f (int a) { [[fallthrough]]; /* { dg-error "invalid use of attribute 'fallthrough'" } */ - switch (a) - { - case 1: - a++; - [[fallthrough]]; /* { dg-warning "attribute 'fallthrough' not preceding a case label or default label" } */ - a++; - } return a; } Index: gcc/testsuite/gcc.dg/c2x-attr-fallthrough-6.c =================================================================== --- gcc/testsuite/gcc.dg/c2x-attr-fallthrough-6.c (nonexistent) +++ gcc/testsuite/gcc.dg/c2x-attr-fallthrough-6.c (working copy) @@ -0,0 +1,18 @@ +/* Test C2x attribute syntax. Invalid use of fallthrough attribute in + bad context inside switch. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors -Wextra" } */ + +int +f (int a) +{ + switch (a) + { + case 1: + a++; + [[fallthrough]]; /* { dg-error "attribute 'fallthrough' not preceding a case label or default label" } */ + a++; + [[fallthrough]]; /* { dg-error "attribute 'fallthrough' not preceding a case label or default label" } */ + } + return a; +}