public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9492] expand: EXTEND_BITINT CALL_EXPR results [PR114332]
@ 2024-03-15 9:11 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-03-15 9:11 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:0319f265eddd17c32cb037b71489d9882a6eb00d
commit r14-9492-g0319f265eddd17c32cb037b71489d9882a6eb00d
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Mar 15 10:10:57 2024 +0100
expand: EXTEND_BITINT CALL_EXPR results [PR114332]
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.
2024-03-15 Jakub Jelinek <jakub@redhat.com>
PR middle-end/114332
* expr.cc (expand_expr_real_1): EXTEND_BITINT also CALL_EXPR results.
Diff:
---
gcc/expr.cc | 3 ++-
gcc/testsuite/gcc.dg/torture/bitint-64.c | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/gcc/expr.cc b/gcc/expr.cc
index f7d74525c15..2918c469735 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -12350,7 +12350,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
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;
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-64.c b/gcc/testsuite/gcc.dg/torture/bitint-64.c
new file mode 100644
index 00000000000..8f0f21cbee2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-64.c
@@ -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 ();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-03-15 9:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-15 9:11 [gcc r14-9492] expand: EXTEND_BITINT CALL_EXPR results [PR114332] Jakub Jelinek
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).