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.
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;
--- /dev/null
+/* 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 ();
+}