public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-1790] c: Fix C cast error-recovery [PR101171]
Date: Thu, 24 Jun 2021 13:57:42 +0000 (GMT)	[thread overview]
Message-ID: <20210624135742.65EB03AAAC32@sourceware.org> (raw)

https://gcc.gnu.org/g:fdc5522fb04b4a820b28c4d1f16f54897f5978de

commit r12-1790-gfdc5522fb04b4a820b28c4d1f16f54897f5978de
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Jun 24 15:55:28 2021 +0200

    c: Fix C cast error-recovery [PR101171]
    
    The following testcase ICEs during error-recovery, as build_c_cast calls
    note_integer_operands on error_mark_node and that wraps it into
    C_MAYBE_CONST_EXPR which is unexpected and causes ICE later on.
    Seems most other callers of note_integer_operands check early if something
    is error_mark_node and return before calling note_integer_operands on it.
    
    The following patch fixes it by not calling on error_mark_node, another
    possibility would be to handle error_mark_node in note_integer_operands and
    just return it.
    
    2021-06-24  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/101171
            * c-typeck.c (build_c_cast): Don't call note_integer_operands on
            error_mark_node.
    
            * gcc.dg/pr101171.c: New test.

Diff:
---
 gcc/c/c-typeck.c                |  1 +
 gcc/testsuite/gcc.dg/pr101171.c | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index d0d36c3b081..d079ce4b05b 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -6131,6 +6131,7 @@ build_c_cast (location_t loc, tree type, tree expr)
      return value reflects this.  */
   if (int_operands
       && INTEGRAL_TYPE_P (type)
+      && value != error_mark_node
       && !EXPR_INT_CONST_OPERANDS (value))
     value = note_integer_operands (value);
 
diff --git a/gcc/testsuite/gcc.dg/pr101171.c b/gcc/testsuite/gcc.dg/pr101171.c
new file mode 100644
index 00000000000..8d2bcabd3e4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr101171.c
@@ -0,0 +1,13 @@
+/* PR c/101171 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+extern void foo (void);
+int x = 0x1234;
+
+void
+bar (void)
+{
+  if (x != (sizeof ((enum T) 0x1234)))	/* { dg-error "conversion to incomplete type" } */
+    foo ();
+}


                 reply	other threads:[~2021-06-24 13:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210624135742.65EB03AAAC32@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@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).