public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99623] New: Code behaves differently at -O2 optimization
@ 2021-03-17 12:07 sebastiano.vigna at unimi dot it
  2021-03-17 12:08 ` [Bug c/99623] " sebastiano.vigna at unimi dot it
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: sebastiano.vigna at unimi dot it @ 2021-03-17 12:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99623
           Summary: Code behaves differently at -O2 optimization
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastiano.vigna at unimi dot it
  Target Milestone: ---

Created attachment 50406
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50406&action=edit
Output of --save-temps

The included code compares two variants of Ben Pfaff's GNU LibAVL library. One
implementation is the original one, and it stores pointers to uint64_t values,
comparing them with a user-supplied function. The second implementation is a
mild variation storing the uint64_t values directly into the map, and comparing
them directly using the language operators. The two implementations should be
equivalent--the code builds the same RB tree with the same values and compares
the results after each insertion.

The two trees are identical:

- with clang, any level optimization, Mac OS X, Linux
- with gcc 10.2.1, no optimization or -O1, Mac OS X, Linux

The two trees diverge after 5 insertions:

- with gcc 10.2.1, -O2, Mac OS X, Linux

We have tried all possible diagnostics, including the sanitizer, but any
perturbation to the code makes the two trees identical. The problem seems to
lie in myprob_probe()--even adding a printf(""); anywhere between lines 207-231
makes the test work.

Note that this test is reported using a compare() function for trees that might
be bugged, but the original bug was that when deleting the tree the library
would give a segmentation fault. We tracked down the problem to a divergence in
the construction of the tree.

To replicate the bug, try

gcc -O1 bug.c
./a.out
gcc -O2 bug.c
./a.out

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

end of thread, other threads:[~2021-03-17 14:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 12:07 [Bug c/99623] New: Code behaves differently at -O2 optimization sebastiano.vigna at unimi dot it
2021-03-17 12:08 ` [Bug c/99623] " sebastiano.vigna at unimi dot it
2021-03-17 12:08 ` sebastiano.vigna at unimi dot it
2021-03-17 12:19 ` zeccav at gmail dot com
2021-03-17 12:23 ` jakub at gcc dot gnu.org
2021-03-17 12:59 ` sebastiano.vigna at unimi dot it
2021-03-17 13:00 ` sebastiano.vigna at unimi dot it
2021-03-17 13:22 ` sebastiano.vigna at unimi dot it
2021-03-17 13:40 ` sebastiano.vigna at unimi dot it
2021-03-17 13:53 ` sebastiano.vigna at unimi dot it
2021-03-17 14:24 ` sebastiano.vigna at unimi dot it

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