* [PATCH] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] @ 2021-12-16 22:35 Marek Polacek 2021-12-16 22:53 ` Jakub Jelinek 0 siblings, 1 reply; 7+ messages in thread From: Marek Polacek @ 2021-12-16 22:35 UTC (permalink / raw) To: GCC Patches, Jakub Jelinek, Jason Merrill, Joseph Myers 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. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c/103649 gcc/ChangeLog: * attribs.c (handle_ignored_attributes_option): Create the fake attribute with max_length == -1. gcc/testsuite/ChangeLog: * c-c++-common/Wno-attributes-6.c: New test. --- gcc/attribs.c | 2 +- gcc/testsuite/c-c++-common/Wno-attributes-6.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/Wno-attributes-6.c diff --git a/gcc/attribs.c b/gcc/attribs.c index 29703e75fba..4933f020f1a 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -304,7 +304,7 @@ handle_ignored_attributes_option (vec<char *> *v) We can't free it here, so squirrel away the pointers. */ attribute_spec *table = new attribute_spec[2]; ignored_attributes_table.safe_push (table); - table[0] = { attr, 0, 0, false, false, false, false, nullptr, nullptr }; + table[0] = { attr, 0, -1, false, false, false, false, nullptr, nullptr }; table[1] = { nullptr, 0, 0, false, false, false, false, nullptr, nullptr }; register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr); diff --git a/gcc/testsuite/c-c++-common/Wno-attributes-6.c b/gcc/testsuite/c-c++-common/Wno-attributes-6.c new file mode 100644 index 00000000000..02cdaaa1e89 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c @@ -0,0 +1,9 @@ +/* PR c/103649 */ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ +/* { dg-additional-options "-Wno-attributes=baz::" } */ + +[[foo::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ +[[baz::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ +[[foo::bar(1, 2)]] void f1(); +[[baz::bar(1, 2)]] void f2(); base-commit: f91814c22595e1db642140efe030caf2c092ab6f -- 2.33.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] 2021-12-16 22:35 [PATCH] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] Marek Polacek @ 2021-12-16 22:53 ` Jakub Jelinek 2021-12-17 0:52 ` [PATCH v2] " Marek Polacek 0 siblings, 1 reply; 7+ messages in thread From: Jakub Jelinek @ 2021-12-16 22:53 UTC (permalink / raw) To: Marek Polacek; +Cc: GCC Patches, Jason Merrill, Joseph Myers On Thu, Dec 16, 2021 at 05:35:55PM -0500, Marek Polacek wrote: > 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. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > PR c/103649 > > gcc/ChangeLog: > > * attribs.c (handle_ignored_attributes_option): Create the fake > attribute with max_length == -1. > > gcc/testsuite/ChangeLog: > > * c-c++-common/Wno-attributes-6.c: New test. I'm afraid this still changes behavior. 0, -1 range attribute arguments are parsed normally, while unknown attributes have the balanced token sequence skipped. E.g. the omp::{directive,sequence} attribute arguments are much more complex than what the normal parsing can handle. Can you make max -2 instead and special case it in the C and C++ FE attribute handling and in a testcase try something that is a balanced token sequence but not really valid when parsed as ordinary attributes' arguments? > --- a/gcc/attribs.c > +++ b/gcc/attribs.c > @@ -304,7 +304,7 @@ handle_ignored_attributes_option (vec<char *> *v) > We can't free it here, so squirrel away the pointers. */ > attribute_spec *table = new attribute_spec[2]; > ignored_attributes_table.safe_push (table); > - table[0] = { attr, 0, 0, false, false, false, false, nullptr, nullptr }; > + table[0] = { attr, 0, -1, false, false, false, false, nullptr, nullptr }; > table[1] = { nullptr, 0, 0, false, false, false, false, nullptr, > nullptr }; > register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr); > diff --git a/gcc/testsuite/c-c++-common/Wno-attributes-6.c b/gcc/testsuite/c-c++-common/Wno-attributes-6.c > new file mode 100644 > index 00000000000..02cdaaa1e89 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c > @@ -0,0 +1,9 @@ > +/* PR c/103649 */ > +/* { dg-do compile { target { c || c++11 } } } */ > +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ > +/* { dg-additional-options "-Wno-attributes=baz::" } */ > + > +[[foo::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ > +[[baz::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ > +[[foo::bar(1, 2)]] void f1(); > +[[baz::bar(1, 2)]] void f2(); > > base-commit: f91814c22595e1db642140efe030caf2c092ab6f > -- > 2.33.1 Jakub ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] 2021-12-16 22:53 ` Jakub Jelinek @ 2021-12-17 0:52 ` Marek Polacek 2021-12-17 1:06 ` Jason Merrill 0 siblings, 1 reply; 7+ messages in thread From: Marek Polacek @ 2021-12-17 0:52 UTC (permalink / raw) To: Jakub Jelinek; +Cc: GCC Patches, Jason Merrill, Joseph Myers On Thu, Dec 16, 2021 at 11:53:46PM +0100, Jakub Jelinek wrote: > On Thu, Dec 16, 2021 at 05:35:55PM -0500, Marek Polacek wrote: > > 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. > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > PR c/103649 > > > > gcc/ChangeLog: > > > > * attribs.c (handle_ignored_attributes_option): Create the fake > > attribute with max_length == -1. > > > > gcc/testsuite/ChangeLog: > > > > * c-c++-common/Wno-attributes-6.c: New test. > > I'm afraid this still changes behavior. 0, -1 range attribute arguments > are parsed normally, while unknown attributes have the balanced token > sequence skipped. > E.g. the omp::{directive,sequence} attribute arguments are much more complex > than what the normal parsing can handle. > Can you make max -2 instead and special case it in the C and C++ FE > attribute handling and in a testcase try something that is a balanced token > sequence but not really valid when parsed as ordinary attributes' arguments? Ah I see what you mean now. Fixed here, thanks. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- 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. PR c/103649 gcc/ChangeLog: * attribs.c (handle_ignored_attributes_option): Create the fake attribute with max_length == -2. * tree-core.h (struct attribute_spec): Document that max_length can be -2. gcc/c/ChangeLog: * c-parser.c (c_parser_std_attribute): Skip parsing of the attribute arguments when max_length == -2. gcc/cp/ChangeLog: * parser.c (cp_parser_std_attribute): Skip parsing of the attribute arguments when max_length == -2. gcc/testsuite/ChangeLog: * c-c++-common/Wno-attributes-6.c: New test. --- gcc/attribs.c | 2 +- gcc/c/c-parser.c | 4 +++- gcc/cp/parser.c | 4 +++- gcc/testsuite/c-c++-common/Wno-attributes-6.c | 14 ++++++++++++++ gcc/tree-core.h | 4 +++- 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/Wno-attributes-6.c diff --git a/gcc/attribs.c b/gcc/attribs.c index 29703e75fba..6af7f93e61c 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -304,7 +304,7 @@ handle_ignored_attributes_option (vec<char *> *v) We can't free it here, so squirrel away the pointers. */ attribute_spec *table = new attribute_spec[2]; ignored_attributes_table.safe_push (table); - table[0] = { attr, 0, 0, false, false, false, false, nullptr, nullptr }; + table[0] = { attr, 0, -2, false, false, false, false, nullptr, nullptr }; table[1] = { nullptr, 0, 0, false, false, false, false, nullptr, nullptr }; register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr); diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index d7e5f051ac0..c9068bdbb8a 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) + /* When MAX_LENGTH is -2, this is a fake attribute created to + handle -Wno-attributes, and we must skip parsing the arguments. */ + if (as && as->max_length != -2) { bool takes_identifier = (ns != NULL_TREE diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 44eed7ea638..763d74eaf6c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -28979,7 +28979,9 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) /* A GNU attribute that takes an identifier in parameter. */ attr_flag = id_attr; - if (as == NULL) + /* When MAX_LENGTH is -2, this is a fake attribute created to + handle -Wno-attributes, and we must skip parsing the arguments. */ + if (as == NULL || as->max_length == -2) { if ((flag_openmp || flag_openmp_simd) && attr_ns == omp_identifier) { diff --git a/gcc/testsuite/c-c++-common/Wno-attributes-6.c b/gcc/testsuite/c-c++-common/Wno-attributes-6.c new file mode 100644 index 00000000000..0b2dd5aa290 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c @@ -0,0 +1,14 @@ +/* PR c/103649 */ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ +/* { dg-additional-options "-Wno-attributes=baz::" } */ +/* { dg-additional-options "-Wno-attributes=womp::womp" } */ +/* { dg-additional-options "-Wno-attributes=qux::foo" } */ + +[[foo::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ +[[baz::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ +[[foo::bar(1, 2)]] void f1(); +[[baz::bar(1, 2)]] void f2(); +[[qux::foo({t})]] void f3(); +[[womp::womp (another::directive (threadprivate (t)))]] void f4(); +[[womp::womp (another::directive (threadprivate (t)))]]; /* { dg-warning "attribute ignored" } */ diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 91ae5237d7e..9b37a065d18 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -2077,7 +2077,9 @@ struct attribute_spec { /* The minimum length of the list of arguments of the attribute. */ int min_length; /* The maximum length of the list of arguments of the attribute - (-1 for no maximum). */ + (-1 for no maximum). It can also be -2 for fake attributes + created for the sake of -Wno-attributes; in that case, we + should skip the balanced token sequence when parsing the attribute. */ int max_length; /* Whether this attribute requires a DECL. If it does, it will be passed from types of DECLs, function return types and array element types to base-commit: 840a22e0fee9e7369a2eb1c9e3c70dcae24a20e4 -- 2.33.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] 2021-12-17 0:52 ` [PATCH v2] " Marek Polacek @ 2021-12-17 1:06 ` Jason Merrill 2021-12-17 18:14 ` [PATCH v3] " Marek Polacek 0 siblings, 1 reply; 7+ messages in thread From: Jason Merrill @ 2021-12-17 1:06 UTC (permalink / raw) To: Marek Polacek, Jakub Jelinek; +Cc: GCC Patches, Joseph Myers On 12/16/21 19:52, Marek Polacek wrote: > On Thu, Dec 16, 2021 at 11:53:46PM +0100, Jakub Jelinek wrote: >> On Thu, Dec 16, 2021 at 05:35:55PM -0500, Marek Polacek wrote: >>> 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. >>> >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? >>> >>> PR c/103649 >>> >>> gcc/ChangeLog: >>> >>> * attribs.c (handle_ignored_attributes_option): Create the fake >>> attribute with max_length == -1. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * c-c++-common/Wno-attributes-6.c: New test. >> >> I'm afraid this still changes behavior. 0, -1 range attribute arguments >> are parsed normally, while unknown attributes have the balanced token >> sequence skipped. >> E.g. the omp::{directive,sequence} attribute arguments are much more complex >> than what the normal parsing can handle. >> Can you make max -2 instead and special case it in the C and C++ FE >> attribute handling and in a testcase try something that is a balanced token >> sequence but not really valid when parsed as ordinary attributes' arguments? > > Ah I see what you mean now. Fixed here, thanks. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > -- >8 -- > 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. > > PR c/103649 > > gcc/ChangeLog: > > * attribs.c (handle_ignored_attributes_option): Create the fake > attribute with max_length == -2. > * tree-core.h (struct attribute_spec): Document that max_length > can be -2. > > gcc/c/ChangeLog: > > * c-parser.c (c_parser_std_attribute): Skip parsing of the attribute > arguments when max_length == -2. > > gcc/cp/ChangeLog: > > * parser.c (cp_parser_std_attribute): Skip parsing of the attribute > arguments when max_length == -2. > > gcc/testsuite/ChangeLog: > > * c-c++-common/Wno-attributes-6.c: New test. > --- > gcc/attribs.c | 2 +- > gcc/c/c-parser.c | 4 +++- > gcc/cp/parser.c | 4 +++- > gcc/testsuite/c-c++-common/Wno-attributes-6.c | 14 ++++++++++++++ > gcc/tree-core.h | 4 +++- > 5 files changed, 24 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/Wno-attributes-6.c > > diff --git a/gcc/attribs.c b/gcc/attribs.c > index 29703e75fba..6af7f93e61c 100644 > --- a/gcc/attribs.c > +++ b/gcc/attribs.c > @@ -304,7 +304,7 @@ handle_ignored_attributes_option (vec<char *> *v) > We can't free it here, so squirrel away the pointers. */ > attribute_spec *table = new attribute_spec[2]; > ignored_attributes_table.safe_push (table); > - table[0] = { attr, 0, 0, false, false, false, false, nullptr, nullptr }; > + table[0] = { attr, 0, -2, false, false, false, false, nullptr, nullptr }; > table[1] = { nullptr, 0, 0, false, false, false, false, nullptr, > nullptr }; > register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr); > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c > index d7e5f051ac0..c9068bdbb8a 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) > + /* When MAX_LENGTH is -2, this is a fake attribute created to > + handle -Wno-attributes, and we must skip parsing the arguments. */ > + if (as && as->max_length != -2) > { > bool takes_identifier > = (ns != NULL_TREE > diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c > index 44eed7ea638..763d74eaf6c 100644 > --- a/gcc/cp/parser.c > +++ b/gcc/cp/parser.c > @@ -28979,7 +28979,9 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) > /* A GNU attribute that takes an identifier in parameter. */ > attr_flag = id_attr; > > - if (as == NULL) > + /* When MAX_LENGTH is -2, this is a fake attribute created to > + handle -Wno-attributes, and we must skip parsing the arguments. */ > + if (as == NULL || as->max_length == -2) > { > if ((flag_openmp || flag_openmp_simd) && attr_ns == omp_identifier) > { > diff --git a/gcc/testsuite/c-c++-common/Wno-attributes-6.c b/gcc/testsuite/c-c++-common/Wno-attributes-6.c > new file mode 100644 > index 00000000000..0b2dd5aa290 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c > @@ -0,0 +1,14 @@ > +/* PR c/103649 */ > +/* { dg-do compile { target { c || c++11 } } } */ > +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ > +/* { dg-additional-options "-Wno-attributes=baz::" } */ > +/* { dg-additional-options "-Wno-attributes=womp::womp" } */ > +/* { dg-additional-options "-Wno-attributes=qux::foo" } */ > + > +[[foo::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ > +[[baz::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ > +[[foo::bar(1, 2)]] void f1(); > +[[baz::bar(1, 2)]] void f2(); > +[[qux::foo({t})]] void f3(); > +[[womp::womp (another::directive (threadprivate (t)))]] void f4(); > +[[womp::womp (another::directive (threadprivate (t)))]]; /* { dg-warning "attribute ignored" } */ If we're ignoring these attributes, we should ignore them everywhere; perhaps using them for an attribute-declaration is meaningful in another compiler. > diff --git a/gcc/tree-core.h b/gcc/tree-core.h > index 91ae5237d7e..9b37a065d18 100644 > --- a/gcc/tree-core.h > +++ b/gcc/tree-core.h > @@ -2077,7 +2077,9 @@ struct attribute_spec { > /* The minimum length of the list of arguments of the attribute. */ > int min_length; > /* The maximum length of the list of arguments of the attribute > - (-1 for no maximum). */ > + (-1 for no maximum). It can also be -2 for fake attributes > + created for the sake of -Wno-attributes; in that case, we > + should skip the balanced token sequence when parsing the attribute. */ > int max_length; > /* Whether this attribute requires a DECL. If it does, it will be passed > from types of DECLs, function return types and array element types to > > base-commit: 840a22e0fee9e7369a2eb1c9e3c70dcae24a20e4 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] 2021-12-17 1:06 ` Jason Merrill @ 2021-12-17 18:14 ` Marek Polacek 2021-12-17 19:33 ` Jason Merrill 0 siblings, 1 reply; 7+ messages in thread From: Marek Polacek @ 2021-12-17 18:14 UTC (permalink / raw) To: Jason Merrill; +Cc: Jakub Jelinek, GCC Patches, Joseph Myers On Thu, Dec 16, 2021 at 08:06:43PM -0500, Jason Merrill wrote: > On 12/16/21 19:52, Marek Polacek wrote: > > --- /dev/null > > +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c > > @@ -0,0 +1,14 @@ > > +/* PR c/103649 */ > > +/* { dg-do compile { target { c || c++11 } } } */ > > +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ > > +/* { dg-additional-options "-Wno-attributes=baz::" } */ > > +/* { dg-additional-options "-Wno-attributes=womp::womp" } */ > > +/* { dg-additional-options "-Wno-attributes=qux::foo" } */ > > + > > +[[foo::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ > > +[[baz::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ > > +[[foo::bar(1, 2)]] void f1(); > > +[[baz::bar(1, 2)]] void f2(); > > +[[qux::foo({t})]] void f3(); > > +[[womp::womp (another::directive (threadprivate (t)))]] void f4(); > > +[[womp::womp (another::directive (threadprivate (t)))]]; /* { dg-warning "attribute ignored" } */ > > If we're ignoring these attributes, we should ignore them everywhere; > perhaps using them for an attribute-declaration is meaningful in another > compiler. Sounds good. Reminds me of P177, Portable assumptions... Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- 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 function. * attribs.h (attribute_ignored_p): Declare. * 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 max_length == -2. 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 max_length == -2. gcc/testsuite/ChangeLog: * c-c++-common/Wno-attributes-6.c: New test. --- gcc/attribs.c | 20 ++++++++++++++++++- gcc/attribs.h | 1 + gcc/c/c-decl.c | 2 +- gcc/c/c-parser.c | 4 +++- gcc/cp/parser.c | 6 ++++-- gcc/testsuite/c-c++-common/Wno-attributes-6.c | 16 +++++++++++++++ gcc/tree-core.h | 4 +++- 7 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/Wno-attributes-6.c diff --git a/gcc/attribs.c b/gcc/attribs.c index 29703e75fba..82527869093 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -304,7 +304,7 @@ handle_ignored_attributes_option (vec<char *> *v) We can't free it here, so squirrel away the pointers. */ attribute_spec *table = new attribute_spec[2]; ignored_attributes_table.safe_push (table); - table[0] = { attr, 0, 0, false, false, false, false, nullptr, nullptr }; + table[0] = { attr, 0, -2, false, false, false, false, nullptr, nullptr }; table[1] = { nullptr, 0, 0, false, false, false, false, nullptr, nullptr }; register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr); @@ -569,6 +569,24 @@ attr_namespace_ignored_p (tree ns) return r && r->ignored_p; } +/* Return true if the attribute ATTR should not be warned about. */ + +bool +attribute_ignored_p (tree attr) +{ + if (!cxx11_attribute_p (attr)) + return false; + if (tree ns = get_attribute_namespace (attr)) + { + if (attr_namespace_ignored_p (ns)) + return true; + const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (attr)); + if (as && as->max_length == -2) + return true; + } + return false; +} + /* Process the attributes listed in ATTRIBUTES and install them in *NODE, which is either a DECL (including a TYPE_DECL) or a TYPE. If a DECL, it should be modified in place; if a TYPE, a copy should be created diff --git a/gcc/attribs.h b/gcc/attribs.h index f5899d83c0b..d3449d5bd1d 100644 --- a/gcc/attribs.h +++ b/gcc/attribs.h @@ -39,6 +39,7 @@ extern tree get_attribute_name (const_tree); extern tree get_attribute_namespace (const_tree); extern void apply_tm_attr (tree, tree); extern tree make_attribute (const char *, const char *, tree); +extern bool attribute_ignored_p (tree); extern struct scoped_attributes* register_scoped_attributes (const struct attribute_spec *, const char *, diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 4b5481ce8f4..516e3c26e21 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 d7e5f051ac0..c9068bdbb8a 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) + /* When MAX_LENGTH is -2, this is a fake attribute created to + handle -Wno-attributes, and we must skip parsing the arguments. */ + if (as && as->max_length != -2) { bool takes_identifier = (ns != NULL_TREE diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 44eed7ea638..a843c953da8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -14776,7 +14776,7 @@ cp_parser_declaration (cp_parser* parser, tree prefix_attrs) } } - if (std_attrs != NULL_TREE) + if (std_attrs != NULL_TREE && !attribute_ignored_p (std_attrs)) warning_at (make_location (attrs_loc, attrs_loc, parser->lexer), OPT_Wattributes, "attribute ignored"); if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)) @@ -28979,7 +28979,9 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) /* A GNU attribute that takes an identifier in parameter. */ attr_flag = id_attr; - if (as == NULL) + /* When MAX_LENGTH is -2, this is a fake attribute created to + handle -Wno-attributes, and we must skip parsing the arguments. */ + if (as == NULL || as->max_length == -2) { if ((flag_openmp || flag_openmp_simd) && attr_ns == omp_identifier) { diff --git a/gcc/testsuite/c-c++-common/Wno-attributes-6.c b/gcc/testsuite/c-c++-common/Wno-attributes-6.c new file mode 100644 index 00000000000..ca3c7bebb99 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c @@ -0,0 +1,16 @@ +/* PR c/103649 */ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ +/* { dg-additional-options "-Wno-attributes=baz::" } */ +/* { dg-additional-options "-Wno-attributes=womp::womp" } */ +/* { dg-additional-options "-Wno-attributes=qux::foo" } */ +/* { dg-additional-options "-Wno-attributes=vendor::assume" } */ + +[[vendor::assume(1 + 1 == 2)]]; +[[foo::bar(1, 2)]]; +[[baz::bar(1, 2)]]; +[[foo::bar(1, 2)]] void f1(); +[[baz::bar(1, 2)]] void f2(); +[[qux::foo({t})]] void f3(); +[[womp::womp (another::directive (threadprivate (t)))]] void f4(); +[[womp::womp (another::directive (threadprivate (t)))]]; diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 91ae5237d7e..9b37a065d18 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -2077,7 +2077,9 @@ struct attribute_spec { /* The minimum length of the list of arguments of the attribute. */ int min_length; /* The maximum length of the list of arguments of the attribute - (-1 for no maximum). */ + (-1 for no maximum). It can also be -2 for fake attributes + created for the sake of -Wno-attributes; in that case, we + should skip the balanced token sequence when parsing the attribute. */ int max_length; /* Whether this attribute requires a DECL. If it does, it will be passed from types of DECLs, function return types and array element types to base-commit: d7ca2a79b82c6500ead6ab983d14c609e2124eee -- 2.33.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] 2021-12-17 18:14 ` [PATCH v3] " Marek Polacek @ 2021-12-17 19:33 ` Jason Merrill 2021-12-17 22:56 ` [PATCH v4] " Marek Polacek 0 siblings, 1 reply; 7+ messages in thread From: Jason Merrill @ 2021-12-17 19:33 UTC (permalink / raw) To: Marek Polacek; +Cc: Jakub Jelinek, GCC Patches, Joseph Myers On 12/17/21 13:14, Marek Polacek wrote: > On Thu, Dec 16, 2021 at 08:06:43PM -0500, Jason Merrill wrote: >> On 12/16/21 19:52, Marek Polacek wrote: >>> --- /dev/null >>> +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c >>> @@ -0,0 +1,14 @@ >>> +/* PR c/103649 */ >>> +/* { dg-do compile { target { c || c++11 } } } */ >>> +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ >>> +/* { dg-additional-options "-Wno-attributes=baz::" } */ >>> +/* { dg-additional-options "-Wno-attributes=womp::womp" } */ >>> +/* { dg-additional-options "-Wno-attributes=qux::foo" } */ >>> + >>> +[[foo::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ >>> +[[baz::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */ >>> +[[foo::bar(1, 2)]] void f1(); >>> +[[baz::bar(1, 2)]] void f2(); >>> +[[qux::foo({t})]] void f3(); >>> +[[womp::womp (another::directive (threadprivate (t)))]] void f4(); >>> +[[womp::womp (another::directive (threadprivate (t)))]]; /* { dg-warning "attribute ignored" } */ >> >> If we're ignoring these attributes, we should ignore them everywhere; >> perhaps using them for an attribute-declaration is meaningful in another >> compiler. > > Sounds good. Reminds me of P177, Portable assumptions... > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > -- >8 -- > 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 function. > * attribs.h (attribute_ignored_p): Declare. > * 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 max_length == -2. > > 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 max_length == -2. > > gcc/testsuite/ChangeLog: > > * c-c++-common/Wno-attributes-6.c: New test. > --- > gcc/attribs.c | 20 ++++++++++++++++++- > gcc/attribs.h | 1 + > gcc/c/c-decl.c | 2 +- > gcc/c/c-parser.c | 4 +++- > gcc/cp/parser.c | 6 ++++-- > gcc/testsuite/c-c++-common/Wno-attributes-6.c | 16 +++++++++++++++ > gcc/tree-core.h | 4 +++- > 7 files changed, 47 insertions(+), 6 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/Wno-attributes-6.c > > diff --git a/gcc/attribs.c b/gcc/attribs.c > index 29703e75fba..82527869093 100644 > --- a/gcc/attribs.c > +++ b/gcc/attribs.c > @@ -304,7 +304,7 @@ handle_ignored_attributes_option (vec<char *> *v) > We can't free it here, so squirrel away the pointers. */ > attribute_spec *table = new attribute_spec[2]; > ignored_attributes_table.safe_push (table); > - table[0] = { attr, 0, 0, false, false, false, false, nullptr, nullptr }; > + table[0] = { attr, 0, -2, false, false, false, false, nullptr, nullptr }; > table[1] = { nullptr, 0, 0, false, false, false, false, nullptr, > nullptr }; > register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr); > @@ -569,6 +569,24 @@ attr_namespace_ignored_p (tree ns) > return r && r->ignored_p; > } > > +/* Return true if the attribute ATTR should not be warned about. */ > + > +bool > +attribute_ignored_p (tree attr) > +{ > + if (!cxx11_attribute_p (attr)) > + return false; > + if (tree ns = get_attribute_namespace (attr)) > + { > + if (attr_namespace_ignored_p (ns)) > + return true; > + const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (attr)); > + if (as && as->max_length == -2) > + return true; > + } > + return false; > +} > + > /* Process the attributes listed in ATTRIBUTES and install them in *NODE, > which is either a DECL (including a TYPE_DECL) or a TYPE. If a DECL, > it should be modified in place; if a TYPE, a copy should be created > diff --git a/gcc/attribs.h b/gcc/attribs.h > index f5899d83c0b..d3449d5bd1d 100644 > --- a/gcc/attribs.h > +++ b/gcc/attribs.h > @@ -39,6 +39,7 @@ extern tree get_attribute_name (const_tree); > extern tree get_attribute_namespace (const_tree); > extern void apply_tm_attr (tree, tree); > extern tree make_attribute (const char *, const char *, tree); > +extern bool attribute_ignored_p (tree); > > extern struct scoped_attributes* register_scoped_attributes (const struct attribute_spec *, > const char *, > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c > index 4b5481ce8f4..516e3c26e21 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 d7e5f051ac0..c9068bdbb8a 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) > + /* When MAX_LENGTH is -2, this is a fake attribute created to > + handle -Wno-attributes, and we must skip parsing the arguments. */ > + if (as && as->max_length != -2) > { > bool takes_identifier > = (ns != NULL_TREE > diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c > index 44eed7ea638..a843c953da8 100644 > --- a/gcc/cp/parser.c > +++ b/gcc/cp/parser.c > @@ -14776,7 +14776,7 @@ cp_parser_declaration (cp_parser* parser, tree prefix_attrs) > } > } > > - if (std_attrs != NULL_TREE) > + if (std_attrs != NULL_TREE && !attribute_ignored_p (std_attrs)) > warning_at (make_location (attrs_loc, attrs_loc, parser->lexer), > OPT_Wattributes, "attribute ignored"); > if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)) > @@ -28979,7 +28979,9 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) > /* A GNU attribute that takes an identifier in parameter. */ > attr_flag = id_attr; > > - if (as == NULL) > + /* When MAX_LENGTH is -2, this is a fake attribute created to > + handle -Wno-attributes, and we must skip parsing the arguments. */ > + if (as == NULL || as->max_length == -2) Rather than require multiple places to know about the magic -2, could we have an overload of attribute_ignored_p that takes an attribute_spec*? OK with that change. > { > if ((flag_openmp || flag_openmp_simd) && attr_ns == omp_identifier) > { > diff --git a/gcc/testsuite/c-c++-common/Wno-attributes-6.c b/gcc/testsuite/c-c++-common/Wno-attributes-6.c > new file mode 100644 > index 00000000000..ca3c7bebb99 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c > @@ -0,0 +1,16 @@ > +/* PR c/103649 */ > +/* { dg-do compile { target { c || c++11 } } } */ > +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ > +/* { dg-additional-options "-Wno-attributes=baz::" } */ > +/* { dg-additional-options "-Wno-attributes=womp::womp" } */ > +/* { dg-additional-options "-Wno-attributes=qux::foo" } */ > +/* { dg-additional-options "-Wno-attributes=vendor::assume" } */ > + > +[[vendor::assume(1 + 1 == 2)]]; > +[[foo::bar(1, 2)]]; > +[[baz::bar(1, 2)]]; > +[[foo::bar(1, 2)]] void f1(); > +[[baz::bar(1, 2)]] void f2(); > +[[qux::foo({t})]] void f3(); > +[[womp::womp (another::directive (threadprivate (t)))]] void f4(); > +[[womp::womp (another::directive (threadprivate (t)))]]; > diff --git a/gcc/tree-core.h b/gcc/tree-core.h > index 91ae5237d7e..9b37a065d18 100644 > --- a/gcc/tree-core.h > +++ b/gcc/tree-core.h > @@ -2077,7 +2077,9 @@ struct attribute_spec { > /* The minimum length of the list of arguments of the attribute. */ > int min_length; > /* The maximum length of the list of arguments of the attribute > - (-1 for no maximum). */ > + (-1 for no maximum). It can also be -2 for fake attributes > + created for the sake of -Wno-attributes; in that case, we > + should skip the balanced token sequence when parsing the attribute. */ > int max_length; > /* Whether this attribute requires a DECL. If it does, it will be passed > from types of DECLs, function return types and array element types to > > base-commit: d7ca2a79b82c6500ead6ab983d14c609e2124eee ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] 2021-12-17 19:33 ` Jason Merrill @ 2021-12-17 22:56 ` Marek Polacek 0 siblings, 0 replies; 7+ messages in thread From: Marek Polacek @ 2021-12-17 22:56 UTC (permalink / raw) To: Jason Merrill; +Cc: Jakub Jelinek, GCC Patches, Joseph Myers On Fri, Dec 17, 2021 at 02:33:01PM -0500, Jason Merrill wrote: > On 12/17/21 13:14, Marek Polacek wrote: > > @@ -28979,7 +28979,9 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) > > /* A GNU attribute that takes an identifier in parameter. */ > > attr_flag = id_attr; > > - if (as == NULL) > > + /* When MAX_LENGTH is -2, this is a fake attribute created to > > + handle -Wno-attributes, and we must skip parsing the arguments. */ > > + if (as == NULL || as->max_length == -2) > > Rather than require multiple places to know about the magic -2, could we > have an overload of attribute_ignored_p that takes an attribute_spec*? OK > with that change. Sure, here's what I'm pushing: Tested x86_64-pc-linux-gnu, applying to trunk. -- >8 -- 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/attribs.c | 28 ++++++++++++++++++- gcc/attribs.h | 2 ++ gcc/c/c-decl.c | 2 +- gcc/c/c-parser.c | 4 ++- gcc/cp/parser.c | 6 ++-- gcc/testsuite/c-c++-common/Wno-attributes-6.c | 16 +++++++++++ gcc/tree-core.h | 4 ++- 7 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/Wno-attributes-6.c diff --git a/gcc/attribs.c b/gcc/attribs.c index 29703e75fba..9e7b7c1abd2 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -304,7 +304,7 @@ handle_ignored_attributes_option (vec<char *> *v) We can't free it here, so squirrel away the pointers. */ attribute_spec *table = new attribute_spec[2]; ignored_attributes_table.safe_push (table); - table[0] = { attr, 0, 0, false, false, false, false, nullptr, nullptr }; + table[0] = { attr, 0, -2, false, false, false, false, nullptr, nullptr }; table[1] = { nullptr, 0, 0, false, false, false, false, nullptr, nullptr }; register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr); @@ -569,6 +569,32 @@ attr_namespace_ignored_p (tree ns) return r && r->ignored_p; } +/* Return true if the attribute ATTR should not be warned about. */ + +bool +attribute_ignored_p (tree attr) +{ + if (!cxx11_attribute_p (attr)) + return false; + if (tree ns = get_attribute_namespace (attr)) + { + if (attr_namespace_ignored_p (ns)) + return true; + const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (attr)); + if (as && as->max_length == -2) + return true; + } + return false; +} + +/* Like above, but takes an attribute_spec AS, which must be nonnull. */ + +bool +attribute_ignored_p (const attribute_spec *const as) +{ + return as->max_length == -2; +} + /* Process the attributes listed in ATTRIBUTES and install them in *NODE, which is either a DECL (including a TYPE_DECL) or a TYPE. If a DECL, it should be modified in place; if a TYPE, a copy should be created diff --git a/gcc/attribs.h b/gcc/attribs.h index f5899d83c0b..4928b126f59 100644 --- a/gcc/attribs.h +++ b/gcc/attribs.h @@ -39,6 +39,8 @@ extern tree get_attribute_name (const_tree); extern tree get_attribute_namespace (const_tree); extern void apply_tm_attr (tree, tree); extern tree make_attribute (const char *, const char *, tree); +extern bool attribute_ignored_p (tree); +extern bool attribute_ignored_p (const attribute_spec *const); extern struct scoped_attributes* register_scoped_attributes (const struct attribute_spec *, const char *, diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 4b5481ce8f4..516e3c26e21 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 d7e5f051ac0..b09ad307acd 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 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 44eed7ea638..33fb40a5b59 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -14776,7 +14776,7 @@ cp_parser_declaration (cp_parser* parser, tree prefix_attrs) } } - if (std_attrs != NULL_TREE) + if (std_attrs != NULL_TREE && !attribute_ignored_p (std_attrs)) warning_at (make_location (attrs_loc, attrs_loc, parser->lexer), OPT_Wattributes, "attribute ignored"); if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)) @@ -28979,7 +28979,9 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) /* A GNU attribute that takes an identifier in parameter. */ attr_flag = id_attr; - if (as == NULL) + /* If this is a fake attribute created to handle -Wno-attributes, + we must skip parsing the arguments. */ + if (as == NULL || attribute_ignored_p (as)) { if ((flag_openmp || flag_openmp_simd) && attr_ns == omp_identifier) { diff --git a/gcc/testsuite/c-c++-common/Wno-attributes-6.c b/gcc/testsuite/c-c++-common/Wno-attributes-6.c new file mode 100644 index 00000000000..ca3c7bebb99 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c @@ -0,0 +1,16 @@ +/* PR c/103649 */ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-additional-options "-Wno-attributes=foo::bar" } */ +/* { dg-additional-options "-Wno-attributes=baz::" } */ +/* { dg-additional-options "-Wno-attributes=womp::womp" } */ +/* { dg-additional-options "-Wno-attributes=qux::foo" } */ +/* { dg-additional-options "-Wno-attributes=vendor::assume" } */ + +[[vendor::assume(1 + 1 == 2)]]; +[[foo::bar(1, 2)]]; +[[baz::bar(1, 2)]]; +[[foo::bar(1, 2)]] void f1(); +[[baz::bar(1, 2)]] void f2(); +[[qux::foo({t})]] void f3(); +[[womp::womp (another::directive (threadprivate (t)))]] void f4(); +[[womp::womp (another::directive (threadprivate (t)))]]; diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 91ae5237d7e..9b37a065d18 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -2077,7 +2077,9 @@ struct attribute_spec { /* The minimum length of the list of arguments of the attribute. */ int min_length; /* The maximum length of the list of arguments of the attribute - (-1 for no maximum). */ + (-1 for no maximum). It can also be -2 for fake attributes + created for the sake of -Wno-attributes; in that case, we + should skip the balanced token sequence when parsing the attribute. */ int max_length; /* Whether this attribute requires a DECL. If it does, it will be passed from types of DECLs, function return types and array element types to base-commit: d7ca2a79b82c6500ead6ab983d14c609e2124eee -- 2.33.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-12-17 22:56 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-12-16 22:35 [PATCH] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] Marek Polacek 2021-12-16 22:53 ` Jakub Jelinek 2021-12-17 0:52 ` [PATCH v2] " Marek Polacek 2021-12-17 1:06 ` Jason Merrill 2021-12-17 18:14 ` [PATCH v3] " Marek Polacek 2021-12-17 19:33 ` Jason Merrill 2021-12-17 22:56 ` [PATCH v4] " Marek Polacek
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).