public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors
@ 2020-03-30 20:10 zsojka at seznam dot cz
  2020-03-30 20:41 ` [Bug middle-end/94412] " glisse at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: zsojka at seznam dot cz @ 2020-03-30 20:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94412
           Summary: wrong code with -fsanitize=undefined and vectors
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---

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

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

x[0] looks like garbage

$ 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-r10-7453-20200329214350-g60c254b279e-checking-yes-rtl-df-extra-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/10.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
--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 --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-r10-7453-20200329214350-g60c254b279e-checking-yes-rtl-df-extra-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.0.1 20200329 (experimental) (GCC)

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

* [Bug middle-end/94412] wrong code with -fsanitize=undefined and vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
@ 2020-03-30 20:41 ` glisse at gcc dot gnu.org
  2020-03-30 20:50 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-03-30 20:41 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-03-30
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
Actually it seems to me that the code is only right with -fsanitize=undefined,
it has to abort.
We replace -v/11u by v/-11u because in fold-const.c we check:
      if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
instead of ANY_INTEGRAL_TYPE_P for instance.

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

* [Bug middle-end/94412] wrong code with -fsanitize=undefined and vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
  2020-03-30 20:41 ` [Bug middle-end/94412] " glisse at gcc dot gnu.org
@ 2020-03-30 20:50 ` jakub at gcc dot gnu.org
  2020-03-30 21:15 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-30 20:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Yeah, -1U / 11 is 390451572, not 0.
11149         /* Convert -A / -B to A / B when the type is signed and overflow
is
11150            undefined.  */
11151         if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
11152             && TREE_CODE (op0) == NEGATE_EXPR
11153             && negate_expr_p (op1))
needs to be adjusted the way Marc said.

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

* [Bug middle-end/94412] wrong code with -fsanitize=undefined and vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
  2020-03-30 20:41 ` [Bug middle-end/94412] " glisse at gcc dot gnu.org
  2020-03-30 20:50 ` jakub at gcc dot gnu.org
@ 2020-03-30 21:15 ` jakub at gcc dot gnu.org
  2020-03-31  6:38 ` zsojka at seznam dot cz
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-30 21:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 48149
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48149&action=edit
gcc10-pr94412.patch

Patch I'm going to test momentarily.

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

* [Bug middle-end/94412] wrong code with -fsanitize=undefined and vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
                   ` (2 preceding siblings ...)
  2020-03-30 21:15 ` jakub at gcc dot gnu.org
@ 2020-03-31  6:38 ` zsojka at seznam dot cz
  2020-03-31  7:38 ` [Bug middle-end/94412] [8/9/10 Regression] wrong code with vectors jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: zsojka at seznam dot cz @ 2020-03-31  6:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Zdenek Sojka <zsojka at seznam dot cz> ---
(In reply to Jakub Jelinek from comment #3)
> Created attachment 48149 [details]
> gcc10-pr94412.patch
> 
> Patch I'm going to test momentarily.

Thank you for checking this. I am sorry for the wrong testcase; the testcase
was looking correct at the first sight and all gcc versions at -O0 agreed on
the result.

The patch fixes the new testcases for me (and also other variants with signed
vectors and -fwrapv).

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

* [Bug middle-end/94412] [8/9/10 Regression] wrong code with vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
                   ` (3 preceding siblings ...)
  2020-03-31  6:38 ` zsojka at seznam dot cz
@ 2020-03-31  7:38 ` jakub at gcc dot gnu.org
  2020-03-31  9:07 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-31  7:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |8.5
            Summary|wrong code with             |[8/9/10 Regression] wrong
                   |-fsanitize=undefined and    |code with vectors
                   |vectors                     |
      Known to work|                            |4.7.0, 4.8.0

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This testcase started to work with
r0-111007-g0e3a99ae913c732f015b0dcfecb85d3236cc142f and aborts since
r0-123887-g948a1fd93681cc364caf89dbd6bb7f746d0fa576, thus it is a regression.
Also verified recent 4.8 and 4.7 snapshot accept it and the testcase succeeds.

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

* [Bug middle-end/94412] [8/9/10 Regression] wrong code with vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
                   ` (4 preceding siblings ...)
  2020-03-31  7:38 ` [Bug middle-end/94412] [8/9/10 Regression] wrong code with vectors jakub at gcc dot gnu.org
@ 2020-03-31  9:07 ` cvs-commit at gcc dot gnu.org
  2020-03-31  9:11 ` [Bug middle-end/94412] [8/9 " jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-03-31  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS 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:1dcffc8ddc48f0b45d3d0d2f763ef5870560eb9a

commit r10-7471-g1dcffc8ddc48f0b45d3d0d2f763ef5870560eb9a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 31 11:06:43 2020 +0200

    fold-const: Fix division folding with vector operands [PR94412]

    The following testcase is miscompiled since 4.9, we treat unsigned
    vector types as if they were signed and "optimize" negations across it.

    2020-03-31  Marc Glisse  <marc.glisse@inria.fr>
                Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/94412
            * fold-const.c (fold_binary_loc) <case TRUNC_DIV_EXPR>: Use
            ANY_INTEGRAL_TYPE_P instead of INTEGRAL_TYPE_P.

            * gcc.c-torture/execute/pr94412.c: New test.

    Co-authored-by: Marc Glisse <marc.glisse@inria.fr>

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

* [Bug middle-end/94412] [8/9 Regression] wrong code with vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
                   ` (5 preceding siblings ...)
  2020-03-31  9:07 ` cvs-commit at gcc dot gnu.org
@ 2020-03-31  9:11 ` jakub at gcc dot gnu.org
  2020-04-07 19:04 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-31  9:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[8/9/10 Regression] wrong   |[8/9 Regression] wrong code
                   |code with vectors           |with vectors

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.

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

* [Bug middle-end/94412] [8/9 Regression] wrong code with vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
                   ` (6 preceding siblings ...)
  2020-03-31  9:11 ` [Bug middle-end/94412] [8/9 " jakub at gcc dot gnu.org
@ 2020-04-07 19:04 ` cvs-commit at gcc dot gnu.org
  2020-04-07 20:02 ` [Bug middle-end/94412] [8 " jakub at gcc dot gnu.org
  2020-09-17 17:24 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-07 19:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:8f99f9e6ccec167a5ba67dcc08e6c14948595b82

commit r9-8475-g8f99f9e6ccec167a5ba67dcc08e6c14948595b82
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 31 11:06:43 2020 +0200

    fold-const: Fix division folding with vector operands [PR94412]

    The following testcase is miscompiled since 4.9, we treat unsigned
    vector types as if they were signed and "optimize" negations across it.

    2020-03-31  Marc Glisse  <marc.glisse@inria.fr>
                Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/94412
            * fold-const.c (fold_binary_loc) <case TRUNC_DIV_EXPR>: Use
            ANY_INTEGRAL_TYPE_P instead of INTEGRAL_TYPE_P.

            * gcc.c-torture/execute/pr94412.c: New test.

    Co-authored-by: Marc Glisse <marc.glisse@inria.fr>

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

* [Bug middle-end/94412] [8 Regression] wrong code with vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
                   ` (7 preceding siblings ...)
  2020-04-07 19:04 ` cvs-commit at gcc dot gnu.org
@ 2020-04-07 20:02 ` jakub at gcc dot gnu.org
  2020-09-17 17:24 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-04-07 20:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[8/9 Regression] wrong code |[8 Regression] wrong code
                   |with vectors                |with vectors

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 9.4+ too.

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

* [Bug middle-end/94412] [8 Regression] wrong code with vectors
  2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
                   ` (8 preceding siblings ...)
  2020-04-07 20:02 ` [Bug middle-end/94412] [8 " jakub at gcc dot gnu.org
@ 2020-09-17 17:24 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-17 17:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 8.5 in r8-10478-gff421cb31d2d51f337dffdaf6b008fe1737d239f too.

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

end of thread, other threads:[~2020-09-17 17:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 20:10 [Bug middle-end/94412] New: wrong code with -fsanitize=undefined and vectors zsojka at seznam dot cz
2020-03-30 20:41 ` [Bug middle-end/94412] " glisse at gcc dot gnu.org
2020-03-30 20:50 ` jakub at gcc dot gnu.org
2020-03-30 21:15 ` jakub at gcc dot gnu.org
2020-03-31  6:38 ` zsojka at seznam dot cz
2020-03-31  7:38 ` [Bug middle-end/94412] [8/9/10 Regression] wrong code with vectors jakub at gcc dot gnu.org
2020-03-31  9:07 ` cvs-commit at gcc dot gnu.org
2020-03-31  9:11 ` [Bug middle-end/94412] [8/9 " jakub at gcc dot gnu.org
2020-04-07 19:04 ` cvs-commit at gcc dot gnu.org
2020-04-07 20:02 ` [Bug middle-end/94412] [8 " jakub at gcc dot gnu.org
2020-09-17 17:24 ` 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).