public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/114263] New: LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13
@ 2024-03-07 5:19 obaines at nvidia dot com
2024-03-07 5:24 ` [Bug ipa/114263] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: obaines at nvidia dot com @ 2024-03-07 5:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114263
Bug ID: 114263
Summary: LTO generating incorrect code with -O2 -std=c++20
-fno-strict-aliasing flags in GCC13
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: lto
Assignee: unassigned at gcc dot gnu.org
Reporter: obaines at nvidia dot com
Target Milestone: ---
I have a minimized test case where LTO seems to be generating incorrect code.
### Sources ###
A.cpp
```
#include <vector>
#include <cstdint>
struct A {
A(uint64_t _x, uint8_t _y) : x(_x), y(_y) {}
uint64_t x;
uint8_t y;
};
void doA() {
std::vector<A> v;
v.emplace_back(0x1111111111111111ULL, 0x2);
v.emplace_back(0x3333333333333333ULL, 0x4);
}
```
B.cpp
```
#include <iostream>
#include <vector>
#include <cstdint>
struct B {
B(uint64_t _x, uint64_t _y) : x(_x), y(_y) {}
uint64_t x;
uint64_t y;
};
void doB() {
std::vector<B> v;
v.emplace_back(0x5555555555555555ULL, 0x6666666666666666ULL);
v.emplace_back(0x7777777777777777ULL, 0x8888888888888888ULL);
std::cout << std::hex << "expected: " << 0x6666666666666666ULL << " actual:
" << v[0].y << std::endl;
}
```
AB.cpp
```
void doA();
void doB();
int main() {
doA();
doB();
}
```
### Build Command ###
g++ -flto -g -O2 -std=c++20 -fno-strict-aliasing -Wall -Wextra -c *.cpp
g++ -flto -g -O2 -std=c++20 -fno-strict-aliasing -Wall -Wextra *.o
### Notes ###
The code doesn't generate any warnings during compilation.
The output of the program is usually `expected: 6666666666666666 actual:
6666666666666666`, but with these optimization flags the output is `expected:
6666666666666666 actual: 66`. The bug won't reproduce if I specify C++ standard
before C++20, or if I don't disable strict-aliasing optimization.
Changing the size of A::y affects the number of bytes that are correctly copied
in the output. The bug reproduces in gcc 13.2.0 and from the latest
releases/gcc-13 branch (g++ (GCC) 13.2.1 20240306), but does not reproduce in
gcc-12.3.0 or with the latest trunk branch (g++ (GCC) 14.0.1 20240306
(experimental)).
So, as far as I can tell the bug is exclusive to GCC13.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug ipa/114263] LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13
2024-03-07 5:19 [Bug lto/114263] New: LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13 obaines at nvidia dot com
@ 2024-03-07 5:24 ` pinskia at gcc dot gnu.org
2024-03-07 5:25 ` pinskia at gcc dot gnu.org
2024-03-09 21:44 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-07 5:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114263
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This sounds almost the same as what is mentioned in PR 113359 ("is changed by
SRA to only store 64 + 32 bits into the std::pair rather than 64 + 64 bits.").
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug ipa/114263] LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13
2024-03-07 5:19 [Bug lto/114263] New: LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13 obaines at nvidia dot com
2024-03-07 5:24 ` [Bug ipa/114263] " pinskia at gcc dot gnu.org
@ 2024-03-07 5:25 ` pinskia at gcc dot gnu.org
2024-03-09 21:44 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-07 5:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114263
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
the testcase in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113359#c15 makes
it even more likely the same as this one.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug ipa/114263] LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13
2024-03-07 5:19 [Bug lto/114263] New: LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13 obaines at nvidia dot com
2024-03-07 5:24 ` [Bug ipa/114263] " pinskia at gcc dot gnu.org
2024-03-07 5:25 ` pinskia at gcc dot gnu.org
@ 2024-03-09 21:44 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-09 21:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114263
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes this is a dup of bug 113359.
*** This bug has been marked as a duplicate of bug 113359 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-09 21:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-07 5:19 [Bug lto/114263] New: LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13 obaines at nvidia dot com
2024-03-07 5:24 ` [Bug ipa/114263] " pinskia at gcc dot gnu.org
2024-03-07 5:25 ` pinskia at gcc dot gnu.org
2024-03-09 21:44 ` 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).