From: Joseph Myers Date: Thu, 21 Nov 2019 20:29:40 +0000 (+0000) Subject: Make more bad uses of fallthrough attribute into pedwarns. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6c80b1b56dec2691436f3e2676e3d1b105b01b89;p=gcc.git Make more bad uses of fallthrough attribute into pedwarns. 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. gcc: * 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: * c-attribs.c (handle_fallthrough_attribute): Use pedwarn instead of warning. gcc/testsuite: * 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. From-SVN: r278599 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ab777929799..2ccdedb5611 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-11-21 Joseph Myers + + * gimplify.c (expand_FALLTHROUGH_r, expand_FALLTHROUGH): Use + pedwarn instead of warning_at for fallthrough not preceding a case + or default label. + 2019-11-22 Prathamesh Kulkarni PR tree-optimization/92608 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index e1b437bf92e..b1dc0bb1212 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2019-11-21 Joseph Myers + + * c-attribs.c (handle_fallthrough_attribute): Use pedwarn instead + of warning. + 2019-11-19 Joseph Myers * c-common.c (attribute_fallthrough_p): In C, use pedwarn not diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 4a59cdff836..b727f6605fb 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -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; } diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 0bbd475b3dd..da6566903e0 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -2405,8 +2405,8 @@ expand_FALLTHROUGH_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_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"); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 48bf697be0e..a3d3e73568e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2019-11-21 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. + 2019-11-22 Prathamesh Kulkarni PR tree-optimization/92608 diff --git a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c index c0d9031cb97..60fe11da828 100644 --- a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c +++ b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c @@ -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 @@ f (int a) case 5: b += 1; break; + case 6: + if (c == 2) + { + [[fallthrough]]; + } + else + { + [[fallthrough]]; + } + case 7: + b += 3; + [[fallthrough]]; + default: + b += 8; + break; } return b; } diff --git a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c index 0e36adccc9e..9d6995938cd 100644 --- a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c +++ b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c @@ -15,7 +15,8 @@ int z = sizeof (int [[fallthrough]]); /* { dg-error "ignored" } */ 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: diff --git a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c index 66fe820c315..714d0af947b 100644 --- a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c +++ b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c @@ -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; } diff --git a/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-6.c b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-6.c new file mode 100644 index 00000000000..aa7ff4cdd2a --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-attr-fallthrough-6.c @@ -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; +}