public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/110534] New: confusing -Wuninitialized when strict aliasing is violated
@ 2023-07-03 13:20 vanyacpp at gmail dot com
2023-07-03 16:02 ` [Bug middle-end/110534] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: vanyacpp at gmail dot com @ 2023-07-03 13:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110534
Bug ID: 110534
Summary: confusing -Wuninitialized when strict aliasing is
violated
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: vanyacpp at gmail dot com
Target Milestone: ---
GCC gives -Wuninitialized on this code:
#include <cstdint>
uint16_t test()
{
uint32_t foo32[4] = {0, 0, 0, 0};
uint16_t* foo16 = reinterpret_cast<uint16_t*>(&foo32[0]);
return foo16[0];
}
<source>:7:19: warning: 'foo32' is used uninitialized [-Wuninitialized]
7 | return foo16[0];
| ^
<source>:5:14: note: 'foo32' declared here
5 | uint32_t foo32[4] = {0, 0, 0, 0};
| ^~~~~
This issue was originally published on reddit:
https://www.reddit.com/r/cpp/comments/14lc9w9/gcc_warnings_for_uninitialized_variables_is/
The poster found the warning quite confusing and I agree with them.
I believe the ideal behavior would be to show -Wstrict-aliasing on this code
and avoid showing -Wuninitialized.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/110534] confusing -Wuninitialized when strict aliasing is violated
2023-07-03 13:20 [Bug middle-end/110534] New: confusing -Wuninitialized when strict aliasing is violated vanyacpp at gmail dot com
@ 2023-07-03 16:02 ` pinskia at gcc dot gnu.org
2023-07-03 16:04 ` pinskia at gcc dot gnu.org
2023-07-03 20:55 ` egallager at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-03 16:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110534
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There are different levels of -Wstrict-aliasing and iirc level 3 will warn.
Note I don't think the uninitialized warning is a bad thing here. Because it
does point out gcc is thinking it is uninitialized due to the alias violation.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/110534] confusing -Wuninitialized when strict aliasing is violated
2023-07-03 13:20 [Bug middle-end/110534] New: confusing -Wuninitialized when strict aliasing is violated vanyacpp at gmail dot com
2023-07-03 16:02 ` [Bug middle-end/110534] " pinskia at gcc dot gnu.org
@ 2023-07-03 16:04 ` pinskia at gcc dot gnu.org
2023-07-03 20:55 ` egallager at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-03 16:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110534
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Oh and there is already a bug recording this, PR 99768 (still open too).
*** This bug has been marked as a duplicate of bug 99768 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/110534] confusing -Wuninitialized when strict aliasing is violated
2023-07-03 13:20 [Bug middle-end/110534] New: confusing -Wuninitialized when strict aliasing is violated vanyacpp at gmail dot com
2023-07-03 16:02 ` [Bug middle-end/110534] " pinskia at gcc dot gnu.org
2023-07-03 16:04 ` pinskia at gcc dot gnu.org
@ 2023-07-03 20:55 ` egallager at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: egallager at gcc dot gnu.org @ 2023-07-03 20:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110534
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> There are different levels of -Wstrict-aliasing and iirc level 3 will warn.
>
Remember that -Wstrict-aliasing's numerical levels are weird compared to other
warnings with numerical levels
> Note I don't think the uninitialized warning is a bad thing here. Because it
> does point out gcc is thinking it is uninitialized due to the alias
> violation.
The wording that gets printed is still a bit confusing, though, since the
variable that gets the first caret isn't the same one that gets named in the
first line of the warning. The note helps a bit, but I can still see how it
might be confusing to some.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-03 20:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 13:20 [Bug middle-end/110534] New: confusing -Wuninitialized when strict aliasing is violated vanyacpp at gmail dot com
2023-07-03 16:02 ` [Bug middle-end/110534] " pinskia at gcc dot gnu.org
2023-07-03 16:04 ` pinskia at gcc dot gnu.org
2023-07-03 20:55 ` egallager 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).