public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105514] New: rv64 qsort gets wrong result when '-O2 -DDEBUG'.
@ 2022-05-07  9:56 chenglulu at loongson dot cn
  2022-05-07 10:49 ` [Bug target/105514] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: chenglulu at loongson dot cn @ 2022-05-07  9:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105514
           Summary: rv64 qsort gets wrong result when '-O2 -DDEBUG'.
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chenglulu at loongson dot cn
  Target Milestone: ---

Created attachment 52936
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52936&action=edit
riscv64-linux-gnu

%riscv64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/.../libexec/gcc/riscv64-linux-gnu/13.0.0/lto-wrapper
Target: riscv64-linux-gnu
Configured with: /.../configure --target=riscv64-linux-gnu --with-arch=rv64g
--with-abi=lp64d --enable-shared --disable-emultls --disable-bootstrap
--enable-languages=c,c++,fortran --disable-multilib 
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.0.0 20220507 (experimental) (GCC) 

There is no problem with the execution result of the following compiler.
% riscv64-linux-gnu-gcc qsort.c -o qsort -O2 --static -march=rv64g -mabi=lp64d
% ./qsort
./qsort 

But, When I add a line to the code to print,program execution result is wrong.
% riscv64-linux-gnu-gcc qsort.c -o qsort -O2 --static -march=rv64g -mabi=lp64d
-DDEBUG
./qsort 





test simple_qsort array with function pointer failed.

When add option '-DDEBUG -fno-reorder-blocks', The program execution result is
no problem again.

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

* [Bug target/105514] rv64 qsort gets wrong result when '-O2 -DDEBUG'.
  2022-05-07  9:56 [Bug c/105514] New: rv64 qsort gets wrong result when '-O2 -DDEBUG' chenglulu at loongson dot cn
@ 2022-05-07 10:49 ` pinskia at gcc dot gnu.org
  2022-05-09  1:19 ` chenglulu at loongson dot cn
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-07 10:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Just looking at the code, there seems to be some aliasing violations going on
which is causing the problem.

Sometimes accessing via unsigned long and others by double.

Does -fno-strict-aliasing fixes the issue?

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

* [Bug target/105514] rv64 qsort gets wrong result when '-O2 -DDEBUG'.
  2022-05-07  9:56 [Bug c/105514] New: rv64 qsort gets wrong result when '-O2 -DDEBUG' chenglulu at loongson dot cn
  2022-05-07 10:49 ` [Bug target/105514] " pinskia at gcc dot gnu.org
@ 2022-05-09  1:19 ` chenglulu at loongson dot cn
  2022-05-09  8:06 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: chenglulu at loongson dot cn @ 2022-05-09  1:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from chenglulu <chenglulu at loongson dot cn> ---
(In reply to Andrew Pinski from comment #1)
> Just looking at the code, there seems to be some aliasing violations going
> on which is causing the problem.
> 
> Sometimes accessing via unsigned long and others by double.
> 
> Does -fno-strict-aliasing fixes the issue?

After adding the compile option '-fno-strict-aliasing', the program runs
without problems.

But I don't understand why one print affects so much?

Thanks!

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

* [Bug target/105514] rv64 qsort gets wrong result when '-O2 -DDEBUG'.
  2022-05-07  9:56 [Bug c/105514] New: rv64 qsort gets wrong result when '-O2 -DDEBUG' chenglulu at loongson dot cn
  2022-05-07 10:49 ` [Bug target/105514] " pinskia at gcc dot gnu.org
  2022-05-09  1:19 ` chenglulu at loongson dot cn
@ 2022-05-09  8:06 ` rguenth at gcc dot gnu.org
  2022-05-12  2:10 ` chenglulu at loongson dot cn
  2022-05-12  2:29 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-09  8:06 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED
             Target|                            |riscv

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
indeed strict aliasing violation

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

* [Bug target/105514] rv64 qsort gets wrong result when '-O2 -DDEBUG'.
  2022-05-07  9:56 [Bug c/105514] New: rv64 qsort gets wrong result when '-O2 -DDEBUG' chenglulu at loongson dot cn
                   ` (2 preceding siblings ...)
  2022-05-09  8:06 ` rguenth at gcc dot gnu.org
@ 2022-05-12  2:10 ` chenglulu at loongson dot cn
  2022-05-12  2:29 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: chenglulu at loongson dot cn @ 2022-05-12  2:10 UTC (permalink / raw)
  To: gcc-bugs

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

chenglulu <chenglulu at loongson dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED

--- Comment #4 from chenglulu <chenglulu at loongson dot cn> ---
(In reply to Richard Biener from comment #3)
> indeed strict aliasing violation

Ok,thanks!

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

* [Bug target/105514] rv64 qsort gets wrong result when '-O2 -DDEBUG'.
  2022-05-07  9:56 [Bug c/105514] New: rv64 qsort gets wrong result when '-O2 -DDEBUG' chenglulu at loongson dot cn
                   ` (3 preceding siblings ...)
  2022-05-12  2:10 ` chenglulu at loongson dot cn
@ 2022-05-12  2:29 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-12  2:29 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.

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

end of thread, other threads:[~2022-05-12  2:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-07  9:56 [Bug c/105514] New: rv64 qsort gets wrong result when '-O2 -DDEBUG' chenglulu at loongson dot cn
2022-05-07 10:49 ` [Bug target/105514] " pinskia at gcc dot gnu.org
2022-05-09  1:19 ` chenglulu at loongson dot cn
2022-05-09  8:06 ` rguenth at gcc dot gnu.org
2022-05-12  2:10 ` chenglulu at loongson dot cn
2022-05-12  2:29 ` pinskia 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).