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 r14-8516] except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195]
Date: Tue, 30 Jan 2024 08:59:09 +0000 (GMT)	[thread overview]
Message-ID: <20240130085909.6E19A38582B9@sourceware.org> (raw)

https://gcc.gnu.org/g:26c9b95b9f712ff1f813351b5d45371620085221

commit r14-8516-g26c9b95b9f712ff1f813351b5d45371620085221
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jan 30 09:57:21 2024 +0100

    except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195]
    
    The expansion of this builtin emits an error if the argument is not
    INTEGER_CST, otherwise uses tree_to_uhwi on the argument (which is declared
    int) and then uses EH_RETURN_DATA_REGNO macro which on most targets returns
    INVALID_REGNUM for all values but some small number (2 or 4); if it returns
    INVALID_REGNUM, we silently expand to -1.
    
    Now, I think the error for non-INTEGER_CST makes sense to catch when people
    unintentionally don't call it with a constant (but, users shouldn't really
    use this builtin anyway, it is for the unwinder only).  Initially I thought
    about emitting an error for the negative values as well on which
    tree_to_uhwi otherwise ICEs, but given that the function will silently
    expand to -1 for INT_MAX - 1 or INT_MAX - 3 other values, I think treating
    the negatives the same silently is fine too.
    
    2024-01-30  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/101195
            * except.cc (expand_builtin_eh_return_data_regno): If which doesn't
            fit into unsigned HOST_WIDE_INT, return constm1_rtx.
    
            * gcc.dg/pr101195.c: New test.

Diff:
---
 gcc/except.cc                   | 3 +++
 gcc/testsuite/gcc.dg/pr101195.c | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/gcc/except.cc b/gcc/except.cc
index 9277a9a80c3d..2080fcc22e62 100644
--- a/gcc/except.cc
+++ b/gcc/except.cc
@@ -2167,6 +2167,9 @@ expand_builtin_eh_return_data_regno (tree exp)
       return constm1_rtx;
     }
 
+  if (!tree_fits_uhwi_p (which))
+    return constm1_rtx;
+
   iwhich = tree_to_uhwi (which);
   iwhich = EH_RETURN_DATA_REGNO (iwhich);
   if (iwhich == INVALID_REGNUM)
diff --git a/gcc/testsuite/gcc.dg/pr101195.c b/gcc/testsuite/gcc.dg/pr101195.c
new file mode 100644
index 000000000000..7b219f80711f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr101195.c
@@ -0,0 +1,8 @@
+/* PR middle-end/101195 */
+/* { dg-do compile } */
+
+int
+foo (void)
+{
+  return __builtin_eh_return_data_regno (-42);
+}

                 reply	other threads:[~2024-01-30  8:59 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=20240130085909.6E19A38582B9@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).