From: Martin Sebor <msebor@gmail.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] handle erroneous types in attribute nonnull (PR 100783)
Date: Thu, 27 May 2021 10:00:06 -0600 [thread overview]
Message-ID: <40750f8b-89be-a3a1-2279-f912d499382f@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 830 bytes --]
When attribute nonnull is applied to an argument of an erroneous
type the attribute positional argument validation function ICEs
while printing a warning that mentions the invalid type.
The attached patch changes the validation function to ignore
erroneous types on the assumption that they must have already
been diagnosed. It also enhances the pretty-printer to detect
erroneous types and print "{erroneous}" instead of causing
an ICE. There already is code in the pretty printer that tries
to be robust in thew presence of erroneous types without actually
printing them, and this extends the detection to also print them.
(With the first part of this patch I don't have a test case for
it but handling the condition gracefully feels preferable to
waiting for another bug report with invalid code triggering
an ICE).
Martin
[-- Attachment #2: gcc-100783.diff --]
[-- Type: text/x-patch, Size: 1988 bytes --]
PR c/100783 - ICE on -Wnonnull and erroneous type
gcc/c-family/ChangeLog:
PR c/100783
* c-attribs.c (positional_argument): Bail on erroneous types.
gcc/c/ChangeLog:
PR c/100783
* c-objc-common.c (print_type): Handle erroneous types.
gcc/testsuite/ChangeLog:
PR c/100783
* gcc.dg/nonnull-6.c: New test.
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 804374d5acc..756a91b1c0d 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -698,6 +698,9 @@ positional_argument (const_tree fntype, const_tree atname, tree pos,
if (tree argtype = type_argument_type (fntype, ipos))
{
+ if (argtype == error_mark_node)
+ return NULL_TREE;
+
if (flags & POSARG_ELLIPSIS)
{
if (argno < 1)
diff --git a/gcc/c/c-objc-common.c b/gcc/c/c-objc-common.c
index a68249d7011..b945de15ab8 100644
--- a/gcc/c/c-objc-common.c
+++ b/gcc/c/c-objc-common.c
@@ -185,6 +185,12 @@ get_aka_type (tree type)
static void
print_type (c_pretty_printer *cpp, tree t, bool *quoted)
{
+ if (t == error_mark_node)
+ {
+ pp_string (cpp, _("{erroneous}"));
+ return;
+ }
+
gcc_assert (TYPE_P (t));
struct obstack *ob = pp_buffer (cpp)->obstack;
char *p = (char *) obstack_base (ob);
diff --git a/gcc/testsuite/gcc.dg/nonnull-6.c b/gcc/testsuite/gcc.dg/nonnull-6.c
new file mode 100644
index 00000000000..8f368702e0e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/nonnull-6.c
@@ -0,0 +1,15 @@
+/* PR c/100783 - ICE on attribute nonnull and erroneous type
+ { dg-do compile }
+ { dg-options "-Wall" } */
+
+__attribute__((nonnull (1))) void
+f1 (char[][n]); // { dg-error "undeclared" }
+
+__attribute__((nonnull (2))) void
+f2 (int n, char[n][m]); // { dg-error "undeclared" }
+
+__attribute__((nonnull (1))) void
+f3 (char[*][n]); // { dg-error "undeclared" }
+
+__attribute__((nonnull (1))) void
+f4 (char[f1]); // { dg-error "size" }
next reply other threads:[~2021-05-27 16:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-27 16:00 Martin Sebor [this message]
2021-05-27 17:40 ` Jeff Law
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=40750f8b-89be-a3a1-2279-f912d499382f@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
/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).