From 6afb8a68a9113897ccf39e40983e042ed90d7aed Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 16 Dec 2021 16:29:41 -0500 Subject: attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] My patch to implement -Wno-attribute=A::b caused a bogus error when parsing [[foo::bar(1, 2)]]; when -Wno-attributes=foo::bar was specified on the command line, because when we create a fake foo::bar attribute and insert it into our attribute table, it is created with max_length == 0 which doesn't allow any args. That is wrong -- we know nothing about the attribute, so we shouldn't require any specific number of arguments. And since unknown attributes can be rather complex (see for example omp::{directive,sequence}), we must skip parsing their arguments. To that end, I'm using max_length with value -2. Also let's not warn about things like [[vendor::assume(true)]]; because they may have some meaning (this is reminiscent of C++ Portable Assumptions). PR c/103649 gcc/ChangeLog: * attribs.c (handle_ignored_attributes_option): Create the fake attribute with max_length == -2. (attribute_ignored_p): New overloads. * attribs.h (attribute_ignored_p): Declare them. * tree-core.h (struct attribute_spec): Document that max_length can be -2. gcc/c/ChangeLog: * c-decl.c (c_warn_unused_attributes): Don't warn for attribute_ignored_p. * c-parser.c (c_parser_std_attribute): Skip parsing of the attribute arguments when the attribute is ignored. gcc/cp/ChangeLog: * parser.c (cp_parser_declaration): Don't warn for attribute_ignored_p. (cp_parser_std_attribute): Skip parsing of the attribute arguments when the attribute is ignored. gcc/testsuite/ChangeLog: * c-c++-common/Wno-attributes-6.c: New test. --- gcc/c/c-decl.c | 2 +- gcc/c/c-parser.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'gcc/c') diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 4b5481c..516e3c2 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -4643,7 +4643,7 @@ c_warn_unused_attributes (tree attrs) constraint violation. */ pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored", get_attribute_name (t)); - else + else if (!attribute_ignored_p (t)) warning (OPT_Wattributes, "%qE attribute ignored", get_attribute_name (t)); } diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index d7e5f05..b09ad30 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -4943,7 +4943,9 @@ c_parser_std_attribute (c_parser *parser, bool for_tm) parens.skip_until_found_close (parser); return error_mark_node; } - if (as) + /* If this is a fake attribute created to handle -Wno-attributes, + we must skip parsing the arguments. */ + if (as && !attribute_ignored_p (as)) { bool takes_identifier = (ns != NULL_TREE -- cgit v1.1