* [PATCH] expand: EXTEND_BITINT CALL_EXPR results [PR114332]
@ 2024-03-15 8:40 Jakub Jelinek
2024-03-15 8:53 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-03-15 8:40 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
The x86-64 and aarch64 psABIs (and the unwritten ia64 psABI part) say that
the padding bits of _BitInt are undefined, while the expansion internally
typically assumes that non-mode precision integers are sign/zero extended
and extends after operations. We handle that mismatch with EXTEND_BITINT
done when reading from untrusted sources like function arguments, reading
_BitInt from memory etc. but otherwise keep relying on stuff being extended
internally (say in pseudos).
The return value of a function is an ABI boundary though too and we need
to extend that too.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2024-03-15 Jakub Jelinek <jakub@redhat.com>
PR middle-end/114332
* expr.cc (expand_expr_real_1): EXTEND_BITINT also CALL_EXPR results.
--- gcc/expr.cc.jj 2024-03-04 19:20:27.120200885 +0100
+++ gcc/expr.cc 2024-03-14 19:22:50.623550538 +0100
@@ -12350,7 +12350,8 @@ expand_expr_real_1 (tree exp, rtx target
return expand_builtin (exp, target, subtarget, tmode, ignore);
}
}
- return expand_call (exp, target, ignore);
+ temp = expand_call (exp, target, ignore);
+ return EXTEND_BITINT (temp);
case VIEW_CONVERT_EXPR:
op0 = NULL_RTX;
--- gcc/testsuite/gcc.dg/torture/bitint-64.c.jj 2024-03-14 19:50:41.051311949 +0100
+++ gcc/testsuite/gcc.dg/torture/bitint-64.c 2024-03-14 19:50:05.480806808 +0100
@@ -0,0 +1,22 @@
+/* PR middle-end/114332 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23 -fwrapv" } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+enum E { E22 = 22 } e = E22;
+
+_BitInt (5)
+foo (void)
+{
+ _Atomic _BitInt (5) b = 0;
+ b += e;
+ return b;
+}
+
+int
+main ()
+{
+ if (foo () != -10)
+ __builtin_abort ();
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] expand: EXTEND_BITINT CALL_EXPR results [PR114332]
2024-03-15 8:40 [PATCH] expand: EXTEND_BITINT CALL_EXPR results [PR114332] Jakub Jelinek
@ 2024-03-15 8:53 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-03-15 8:53 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On Fri, 15 Mar 2024, Jakub Jelinek wrote:
> Hi!
>
> The x86-64 and aarch64 psABIs (and the unwritten ia64 psABI part) say that
> the padding bits of _BitInt are undefined, while the expansion internally
> typically assumes that non-mode precision integers are sign/zero extended
> and extends after operations. We handle that mismatch with EXTEND_BITINT
> done when reading from untrusted sources like function arguments, reading
> _BitInt from memory etc. but otherwise keep relying on stuff being extended
> internally (say in pseudos).
> The return value of a function is an ABI boundary though too and we need
> to extend that too.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2024-03-15 Jakub Jelinek <jakub@redhat.com>
>
> PR middle-end/114332
> * expr.cc (expand_expr_real_1): EXTEND_BITINT also CALL_EXPR results.
>
> --- gcc/expr.cc.jj 2024-03-04 19:20:27.120200885 +0100
> +++ gcc/expr.cc 2024-03-14 19:22:50.623550538 +0100
> @@ -12350,7 +12350,8 @@ expand_expr_real_1 (tree exp, rtx target
> return expand_builtin (exp, target, subtarget, tmode, ignore);
> }
> }
> - return expand_call (exp, target, ignore);
> + temp = expand_call (exp, target, ignore);
> + return EXTEND_BITINT (temp);
>
> case VIEW_CONVERT_EXPR:
> op0 = NULL_RTX;
> --- gcc/testsuite/gcc.dg/torture/bitint-64.c.jj 2024-03-14 19:50:41.051311949 +0100
> +++ gcc/testsuite/gcc.dg/torture/bitint-64.c 2024-03-14 19:50:05.480806808 +0100
> @@ -0,0 +1,22 @@
> +/* PR middle-end/114332 */
> +/* { dg-do run { target bitint } } */
> +/* { dg-options "-std=c23 -fwrapv" } */
> +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */
> +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
> +
> +enum E { E22 = 22 } e = E22;
> +
> +_BitInt (5)
> +foo (void)
> +{
> + _Atomic _BitInt (5) b = 0;
> + b += e;
> + return b;
> +}
> +
> +int
> +main ()
> +{
> + if (foo () != -10)
> + __builtin_abort ();
> +}
>
> 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-03-15 8:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-15 8:40 [PATCH] expand: EXTEND_BITINT CALL_EXPR results [PR114332] Jakub Jelinek
2024-03-15 8:53 ` 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).