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