public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114332] New: wrong code with _Atomic _BitInt(5) at -O -fwrapv
@ 2024-03-14  6:06 zsojka at seznam dot cz
  2024-03-14 18:19 ` [Bug tree-optimization/114332] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zsojka at seznam dot cz @ 2024-03-14  6:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114332

            Bug ID: 114332
           Summary: wrong code with _Atomic _BitInt(5) at -O -fwrapv
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

Created attachment 57691
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57691&action=edit
reduced testcase

Output:
$ x86_64-pc-linux-gnu-gcc -O testcase.c
$ ./a.out 
Aborted


$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-r14-9454-20240313184120-g11caf47b599-checking-yes-rtl-df-extra-nobootstrap-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--disable-bootstrap --with-cloog --with-ppl --with-isl
--build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
--target=x86_64-pc-linux-gnu --with-ld=/usr/bin/x86_64-pc-linux-gnu-ld
--with-as=/usr/bin/x86_64-pc-linux-gnu-as --enable-libsanitizer
--disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-r14-9454-20240313184120-g11caf47b599-checking-yes-rtl-df-extra-nobootstrap-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240313 (experimental) (GCC)

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

* [Bug tree-optimization/114332] wrong code with _Atomic _BitInt(5) at -O -fwrapv
  2024-03-14  6:06 [Bug tree-optimization/114332] New: wrong code with _Atomic _BitInt(5) at -O -fwrapv zsojka at seznam dot cz
@ 2024-03-14 18:19 ` jakub at gcc dot gnu.org
  2024-03-15  9:11 ` [Bug middle-end/114332] " cvs-commit at gcc dot gnu.org
  2024-03-15  9:13 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-14 18:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114332

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Given that the x86-64 psABI says:
  \item The value of the unused bits beyond the width of the
   \texttt{_BitInt(N)} value but within the size of the
   \texttt{_BitInt(N)} are unspecified when stored in memory or register.
and that doesn't apply just to N > 64, but also smaller ones, but internally
GCC sign or zero extends only when reading from memory or VAR_DECLs etc., I
think we need to EXTEND_BITINT also the call return values.

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

* [Bug middle-end/114332] wrong code with _Atomic _BitInt(5) at -O -fwrapv
  2024-03-14  6:06 [Bug tree-optimization/114332] New: wrong code with _Atomic _BitInt(5) at -O -fwrapv zsojka at seznam dot cz
  2024-03-14 18:19 ` [Bug tree-optimization/114332] " jakub at gcc dot gnu.org
@ 2024-03-15  9:11 ` cvs-commit at gcc dot gnu.org
  2024-03-15  9:13 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-15  9:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114332

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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.

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

* [Bug middle-end/114332] wrong code with _Atomic _BitInt(5) at -O -fwrapv
  2024-03-14  6:06 [Bug tree-optimization/114332] New: wrong code with _Atomic _BitInt(5) at -O -fwrapv zsojka at seznam dot cz
  2024-03-14 18:19 ` [Bug tree-optimization/114332] " jakub at gcc dot gnu.org
  2024-03-15  9:11 ` [Bug middle-end/114332] " cvs-commit at gcc dot gnu.org
@ 2024-03-15  9:13 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-15  9:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114332

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2024-03-15  9:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-14  6:06 [Bug tree-optimization/114332] New: wrong code with _Atomic _BitInt(5) at -O -fwrapv zsojka at seznam dot cz
2024-03-14 18:19 ` [Bug tree-optimization/114332] " jakub at gcc dot gnu.org
2024-03-15  9:11 ` [Bug middle-end/114332] " cvs-commit at gcc dot gnu.org
2024-03-15  9:13 ` jakub at gcc dot gnu.org

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