Kind of undefined behavior (or bug?) with GCC 10.1
Roland Denis
denis@math.univ-lyon1.fr
Tue Jun 16 11:57:10 GMT 2020
Hi,
I encounter a strange bug while compiling a project with GCC 10.1 and
-O3 that looks like an undefined behavior but I don't found where.
Result is correct with previous version of GCC, with LLVM & Intel.
I have attached a snippet (also on godbolt
https://gcc.godbolt.org/z/EC4WYZ) that I tried to minimize but remaining
lines seems to be important to reproduce the erroneous result.
Uncommenting any of the indicated lines solve the issue.
To explain the code a bit: from a 3D Point with integer coordinates, I
convert it into another coordinate system (using uSpel that returns a
Cell). I use a dimension iterator q (DirIterator, that doesn't look like
an iterator anymore) and the uIncident function to visit neighbors of
the cell. From the point (0, 0, 0), I should get the cell c=(1, 1, 1)
and the incident cell f1=(0, 1, 1). I additionally copy f1 into f2 (to
increase the weirdness of the bug).
Here are the result with and without -O3 flag:
$ g++ bug_minimal.cpp && ./a.out
q.dir = 0 ; f1 = 0 1 1 ; f2 = 0 1 1
$ g++ -O3 bug_minimal.cpp && ./a.out
q.dir = 0 ; f1 = 1 1 1 ; f2 = 0 1 1
The bug is in the first coordinate of f1 that should be 0.
As I explain above, slightly modifying the code implies the right
result, e.g.:
- declaring default copy or move constructor for Point
- using std::array in place of Point
- using Point in place of Cell
- passing Cell by reference instead of copy in uIncident
- constructing Cell without uSpel
- specifying the incidence direction by hand
Am I missing something important or does that look like a GCC bug ?
Regards,
PS: result is correct with trunk version of GCC in godbolt, does that
mean it is an already solved bug?
--
Roland DENIS
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug_minimal.cpp
Type: text/x-c++src
Size: 2046 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20200616/23f95dd6/attachment.bin>
More information about the Gcc-help
mailing list