aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-11-21 20:29:40 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2019-11-21 20:29:40 +0000
commit6c80b1b56dec2691436f3e2676e3d1b105b01b89 (patch)
tree9a51651149c41db896f090d511d9b1081849f9d7 /gcc
parentb30e83f809b2aa65222eb969f8b4523e5e1961f2 (diff)
downloadgcc-6c80b1b56dec2691436f3e2676e3d1b105b01b89.zip
gcc-6c80b1b56dec2691436f3e2676e3d1b105b01b89.tar.gz
gcc-6c80b1b56dec2691436f3e2676e3d1b105b01b89.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-attribs.c2
-rw-r--r--gcc/gimplify.c8
-rw-r--r--gcc/testsuite/ChangeLog9
-rw-r--r--gcc/testsuite/gcc.dg/c2x-attr-fallthrough-1.c17
-rw-r--r--gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c3
-rw-r--r--gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c9
-rw-r--r--gcc/testsuite/gcc.dg/c2x-attr-fallthrough-6.c18
9 files changed, 62 insertions, 15 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ab77792..2ccdedb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2019-11-21 Joseph Myers <joseph@codesourcery.com>
+
+ * 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 <prathamesh.kulkarni@linaro.org>
PR tree-optimization/92608
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index e1b437b..b1dc0bb 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2019-11-21 Joseph Myers <joseph@codesourcery.com>
+
+ * c-attribs.c (handle_fallthrough_attribute): Use pedwarn instead
+ of warning.
+
2019-11-19 Joseph Myers <joseph@codesourcery.com>
* 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 4a59cdf..b727f66 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 0bbd475..da65669 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 %<fallthrough%> not preceding "
- "a case label or default label");
+ pedwarn (loc, 0, "attribute %<fallthrough%> 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 %<fallthrough%> not preceding "
- "a case label or default label");
+ pedwarn (loc, 0, "attribute %<fallthrough%> not preceding "
+ "a case label or default label");
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 48bf697..a3d3e735 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2019-11-21 Joseph Myers <joseph@codesourcery.com>
+
+ * 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 <prathamesh.kulkarni@linaro.org>
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 c0d9031..60fe11d 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 0e36adc..9d69959 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 66fe820..714d0af 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 0000000..aa7ff4c
--- /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;
+}