aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-11-15 01:33:37 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2019-11-15 01:33:37 +0000
commitf8aea5e37d12e09fef68b854a190f71d6b39e11f (patch)
treeaf29d11914c8522b85aaac821765cf424cea24f3 /gcc/c
parentd3cb8f004a3c1ea3de3d948d80f5faabadd1f0b0 (diff)
downloadgcc-f8aea5e37d12e09fef68b854a190f71d6b39e11f.zip
gcc-f8aea5e37d12e09fef68b854a190f71d6b39e11f.tar.gz
gcc-f8aea5e37d12e09fef68b854a190f71d6b39e11f.tar.bz2
Improve checks on C2x fallthrough attribute.
When adding C2x attribute support, some [[fallthrough]] support appeared as a side-effect because of code for that attribute going through separate paths from the normal attribute handling. However, going through those paths without the normal attribute handlers meant that certain checks, such as for the invalid usage [[fallthrough()]], did not operate. This patch improves checks by adding this attribute to the standard attribute table, so that the parser knows it expects no arguments, along with adding an explicit check for "[[fallthrough]];" attribute-declarations at top level. As with other attributes, there are still cases where warnings should be pedwarns because C2x constraints are violated, but this patch improves the attribute handling. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-decl.c (std_attribute_table): Add fallthrough. * c-parser.c (c_parser_declaration_or_fndef): Diagnose fallthrough attribute at top level. gcc/c-family: * c-attribs.c (handle_fallthrough_attribute): Remove static. * c-common.h (handle_fallthrough_attribute): Declare. gcc/testsuite: * gcc.dg/c2x-attr-fallthrough-2.c, gcc.dg/c2x-attr-fallthrough-3.c: New tests. From-SVN: r278273
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-decl.c2
-rw-r--r--gcc/c/c-parser.c12
3 files changed, 17 insertions, 3 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index fdc9153..c2cab57 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,5 +1,11 @@
2019-11-15 Joseph Myers <joseph@codesourcery.com>
+ * c-decl.c (std_attribute_table): Add fallthrough.
+ * c-parser.c (c_parser_declaration_or_fndef): Diagnose fallthrough
+ attribute at top level.
+
+2019-11-15 Joseph Myers <joseph@codesourcery.com>
+
* c-decl.c (std_attribute_table): New.
(c_init_decl_processing): Register attributes from
std_attribute_table.
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index a7f7c69..98b71ea 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -4343,6 +4343,8 @@ const struct attribute_spec std_attribute_table[] =
affects_type_identity, handler, exclude } */
{ "deprecated", 0, 1, false, false, false, false,
handle_deprecated_attribute, NULL },
+ { "fallthrough", 0, 0, false, false, false, false,
+ handle_fallthrough_attribute, NULL },
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
};
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 721158a..5b290bf 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1927,9 +1927,15 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
{
if (fallthru_attr_p != NULL)
*fallthru_attr_p = true;
- tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH,
- void_type_node, 0);
- add_stmt (fn);
+ if (nested)
+ {
+ tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH,
+ void_type_node, 0);
+ add_stmt (fn);
+ }
+ else
+ pedwarn (here, OPT_Wattributes,
+ "%<fallthrough%> attribute at top level");
}
else if (empty_ok && !(have_attrs
&& specs->non_std_attrs_seen_p))