From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>,
Joseph Myers <josmyers@redhat.com>
Subject: Re: [PATCH] c: ICE with invalid sizeof [PR115642]
Date: Thu, 27 Jun 2024 17:08:02 -0400 [thread overview]
Message-ID: <Zn3Usi7fTfsR3JRn@redhat.com> (raw)
In-Reply-To: <20240626150937.29901-1-polacek@redhat.com>
Sorry, I used the wrong e-mail address for Joseph.
On Wed, Jun 26, 2024 at 11:09:37AM -0400, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> -- >8 --
> Here we ICE in c_expr_sizeof_expr on an erroneous expr.value. The
> code checks for expr.value == error_mark_node but here the e_m_n is
> wrapped in a C_MAYBE_CONST_EXPR. I don't think we should have created
> such a tree, so let's return earlier in c_cast_expr.
>
> PR c/115642
>
> gcc/c/ChangeLog:
>
> * c-typeck.cc (c_cast_expr): Return error_mark_node if build_c_cast
> failed.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/noncompile/sizeof-1.c: New test.
> ---
> gcc/c/c-typeck.cc | 3 +++
> gcc/testsuite/gcc.dg/noncompile/sizeof-1.c | 7 +++++++
> 2 files changed, 10 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/noncompile/sizeof-1.c
>
> diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> index ffcab7df4d3..8c03a7731c4 100644
> --- a/gcc/c/c-typeck.cc
> +++ b/gcc/c/c-typeck.cc
> @@ -6695,6 +6695,9 @@ c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
> return error_mark_node;
>
> ret = build_c_cast (loc, type, expr);
> + if (ret == error_mark_node)
> + return error_mark_node;
> +
> if (type_expr)
> {
> bool inner_expr_const = true;
> diff --git a/gcc/testsuite/gcc.dg/noncompile/sizeof-1.c b/gcc/testsuite/gcc.dg/noncompile/sizeof-1.c
> new file mode 100644
> index 00000000000..db7e2044b11
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/noncompile/sizeof-1.c
> @@ -0,0 +1,7 @@
> +/* PR c/115642 */
> +/* { dg-do compile } */
> +
> +void f (int N) {
> + int a[2][N];
> + sizeof ((int [2][N])a); /* { dg-error "cast specifies array type" } */
> +}
>
> base-commit: 47b68cda2c4afe32e84c5f18da0196c39e5e0edf
> --
> 2.45.2
>
Marek
prev parent reply other threads:[~2024-06-27 21:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-26 15:09 Marek Polacek
2024-06-27 21:08 ` Marek Polacek [this message]
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=Zn3Usi7fTfsR3JRn@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=josmyers@redhat.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).