public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195]
@ 2024-01-30  8:02 Jakub Jelinek
  2024-01-30  8:45 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-01-30  8:02 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

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.jj	2024-01-03 11:51:37.552647625 +0100
+++ gcc/except.cc	2024-01-29 09:46:09.385299324 +0100
@@ -2167,6 +2167,9 @@ expand_builtin_eh_return_data_regno (tre
       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)
--- gcc/testsuite/gcc.dg/pr101195.c.jj	2024-01-29 09:48:15.969510457 +0100
+++ gcc/testsuite/gcc.dg/pr101195.c	2024-01-29 09:48:08.626614220 +0100
@@ -0,0 +1,8 @@
+/* PR middle-end/101195 */
+/* { dg-do compile } */
+
+int
+foo (void)
+{
+  return __builtin_eh_return_data_regno (-42);
+}

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195]
  2024-01-30  8:02 [PATCH] except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195] Jakub Jelinek
@ 2024-01-30  8:45 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-01-30  8:45 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Tue, 30 Jan 2024, Jakub Jelinek wrote:

> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK

> 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.jj	2024-01-03 11:51:37.552647625 +0100
> +++ gcc/except.cc	2024-01-29 09:46:09.385299324 +0100
> @@ -2167,6 +2167,9 @@ expand_builtin_eh_return_data_regno (tre
>        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)
> --- gcc/testsuite/gcc.dg/pr101195.c.jj	2024-01-29 09:48:15.969510457 +0100
> +++ gcc/testsuite/gcc.dg/pr101195.c	2024-01-29 09:48:08.626614220 +0100
> @@ -0,0 +1,8 @@
> +/* PR middle-end/101195 */
> +/* { dg-do compile } */
> +
> +int
> +foo (void)
> +{
> +  return __builtin_eh_return_data_regno (-42);
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-30  8:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30  8:02 [PATCH] except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195] Jakub Jelinek
2024-01-30  8:45 ` Richard Biener

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).