]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195]
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 Jan 2024 08:57:21 +0000 (09:57 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 30 Jan 2024 08:57:21 +0000 (09:57 +0100)
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.

gcc/except.cc
gcc/testsuite/gcc.dg/pr101195.c [new file with mode: 0644]

index 9277a9a80c3dfb739d08e2911e33f6d792885819..2080fcc22e624de2df21dd57ff8c7853ab6c12d8 100644 (file)
@@ -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 (file)
index 0000000..7b219f8
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR middle-end/101195 */
+/* { dg-do compile } */
+
+int
+foo (void)
+{
+  return __builtin_eh_return_data_regno (-42);
+}