From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Joseph Myers <joseph@codesourcery.com>
Subject: [PATCH v2] c-family: ICE with [[gnu::nocf_check]] [PR106937]
Date: Tue, 4 Oct 2022 19:06:21 -0400 [thread overview]
Message-ID: <Yzy8bdzUiCfLImkn@redhat.com> (raw)
In-Reply-To: <1c85a5bf-82dd-772c-a960-75a495ded832@redhat.com>
On Fri, Sep 30, 2022 at 09:12:24AM -0400, Jason Merrill wrote:
> On 9/29/22 18:49, Marek Polacek wrote:
> > When getting the name of an attribute, we ought to use
> > get_attribute_name, which handles both [[ ]] and __attribute__(())
> > forms. Failure to do so may result in an ICE, like here.
> >
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> How do we print the attributes with this patch? Don't we also want to print
> the namespace, and use [[]] in the output?
Good point, however: while the testcase indeed has an attribute
in the [[]] form in the typedef, here we're printing its "aka":
warning: initialization of 'FuncPointerWithNoCfCheck' {aka 'void (__attribute__((nocf_check)) *)(void)'} from incompatible pointer type 'FuncPointer' {aka 'void (*)(void)'}
c-pretty-print.cc doesn't seem to know how to print an [[]] attribute.
I could do that, but then we'd print
aka 'void ([[nocf_check]] *)(void)'
in the above, but that's invalid syntax! pp_c_attributes_display appears
to be called for * and & only where you can't use an [[]] attribute. So
perhaps we want to keep printing the GNU form here?
I noticed that pp_c_attributes has never been used, so we can just remove it.
I've also adjusted the test not to use "-w".
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
When getting the name of an attribute, we ought to use
get_attribute_name, which handles both [[ ]] and __attribute__(())
forms. Failure to do so may result in an ICE, like here.
pp_c_attributes has been unused since its introduction in r56273.
PR c++/106937
gcc/c-family/ChangeLog:
* c-pretty-print.cc (pp_c_attributes): Remove.
(pp_c_attributes_display): Use get_attribute_name.
* c-pretty-print.h (pp_c_attributes): Remove.
gcc/testsuite/ChangeLog:
* gcc.dg/fcf-protection-1.c: New test.
---
gcc/c-family/c-pretty-print.cc | 30 +++----------------------
gcc/c-family/c-pretty-print.h | 1 -
gcc/testsuite/gcc.dg/fcf-protection-1.c | 13 +++++++++++
3 files changed, 16 insertions(+), 28 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/fcf-protection-1.c
diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc
index efa1768f4d6..2419e149333 100644
--- a/gcc/c-family/c-pretty-print.cc
+++ b/gcc/c-family/c-pretty-print.cc
@@ -850,32 +850,8 @@ c_pretty_printer::declaration (tree t)
pp_c_init_declarator (this, t);
}
-/* Pretty-print ATTRIBUTES using GNU C extension syntax. */
-
-void
-pp_c_attributes (c_pretty_printer *pp, tree attributes)
-{
- if (attributes == NULL_TREE)
- return;
-
- pp_c_ws_string (pp, "__attribute__");
- pp_c_left_paren (pp);
- pp_c_left_paren (pp);
- for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
- {
- pp_tree_identifier (pp, TREE_PURPOSE (attributes));
- if (TREE_VALUE (attributes))
- pp_c_call_argument_list (pp, TREE_VALUE (attributes));
-
- if (TREE_CHAIN (attributes))
- pp_separate_with (pp, ',');
- }
- pp_c_right_paren (pp);
- pp_c_right_paren (pp);
-}
-
/* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
- marked to be displayed on disgnostic. */
+ marked to be displayed on diagnostic. */
void
pp_c_attributes_display (c_pretty_printer *pp, tree a)
@@ -888,7 +864,7 @@ pp_c_attributes_display (c_pretty_printer *pp, tree a)
for (; a != NULL_TREE; a = TREE_CHAIN (a))
{
const struct attribute_spec *as;
- as = lookup_attribute_spec (TREE_PURPOSE (a));
+ as = lookup_attribute_spec (get_attribute_name (a));
if (!as || as->affects_type_identity == false)
continue;
if (c_dialect_cxx ()
@@ -906,7 +882,7 @@ pp_c_attributes_display (c_pretty_printer *pp, tree a)
{
pp_separate_with (pp, ',');
}
- pp_tree_identifier (pp, TREE_PURPOSE (a));
+ pp_tree_identifier (pp, get_attribute_name (a));
if (TREE_VALUE (a))
pp_c_call_argument_list (pp, TREE_VALUE (a));
}
diff --git a/gcc/c-family/c-pretty-print.h b/gcc/c-family/c-pretty-print.h
index be86bed4fee..92674ab4d06 100644
--- a/gcc/c-family/c-pretty-print.h
+++ b/gcc/c-family/c-pretty-print.h
@@ -119,7 +119,6 @@ void pp_c_space_for_pointer_operator (c_pretty_printer *, tree);
/* Declarations. */
void pp_c_tree_decl_identifier (c_pretty_printer *, tree);
void pp_c_function_definition (c_pretty_printer *, tree);
-void pp_c_attributes (c_pretty_printer *, tree);
void pp_c_attributes_display (c_pretty_printer *, tree);
void pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type);
void pp_c_type_qualifier_list (c_pretty_printer *, tree);
diff --git a/gcc/testsuite/gcc.dg/fcf-protection-1.c b/gcc/testsuite/gcc.dg/fcf-protection-1.c
new file mode 100644
index 00000000000..baad74cd86f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fcf-protection-1.c
@@ -0,0 +1,13 @@
+/* PR c++/106937 */
+/* { dg-options "-fcf-protection" } */
+
+[[gnu::nocf_check]] typedef void (*FuncPointerWithNoCfCheck)(void);
+typedef void (*FuncPointer)(void);
+[[gnu::nocf_check]] void testNoCfCheck();
+void testNoCfCheck(){};
+int i;
+void testNoCfCheckImpl(double i) {}
+void testNoCfCheckMismatch(FuncPointer f) {
+ FuncPointerWithNoCfCheck fNoCfCheck = f; /* { dg-warning "initialization" } */
+ (*fNoCfCheck)();
+}
base-commit: ade1e0d5896221500d1cbda38cd631cf80325aaa
--
2.37.3
next prev parent reply other threads:[~2022-10-04 23:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 22:49 [PATCH] " Marek Polacek
2022-09-30 13:12 ` Jason Merrill
2022-10-04 23:06 ` Marek Polacek [this message]
2022-10-06 21:42 ` [PATCH v2] " Jason Merrill
2022-10-07 2:12 ` [PATCH v3] " Marek Polacek
2022-10-07 16:17 ` Jason Merrill
2022-10-07 21:08 ` [PATCH v4] " Marek Polacek
2022-10-07 21:56 ` Jason Merrill
2022-10-07 22:16 ` Marek Polacek
2022-10-10 14:49 ` Jason Merrill
2022-10-10 19:18 ` [PATCH v5] " Marek Polacek
2022-10-10 19:23 ` Jason Merrill
2022-10-11 7:40 ` Andreas Schwab
2022-10-11 20:03 ` Marek Polacek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yzy8bdzUiCfLImkn@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=joseph@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).