public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116742] New: -Wuninitialized failed to issue uninitialized variable
@ 2024-09-16 13:30 xiaohuba2021 at 163 dot com
2024-09-16 14:07 ` [Bug tree-optimization/116742] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: xiaohuba2021 at 163 dot com @ 2024-09-16 13:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116742
Bug ID: 116742
Summary: -Wuninitialized failed to issue uninitialized variable
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: xiaohuba2021 at 163 dot com
Target Milestone: ---
The following code WON'T generate any warning with -O2 -Wuninitialized
-Wmaybe-uninitialized:
```
#include <iostream>
using namespace std;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, s = n; // n is uninitialized
cin >> n;
cout << s << endl;
return 0;
}
```
Turning on -Wall -Wextra does not help.
However, with `ios_base::sync_with_stdio(false)` and `cin.tie(0)` commented,
the compiler will notice that n is uninitialized.
g++ version:
```
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-snapshot/bin/g++
Target: x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240916 (experimental)
(Compiler-Explorer-Build-gcc-4f2cd256aace732bff511c59f5871456a564a3a5-binutils-2.42)
```
compiler explorer: https://godbolt.org/z/dWbcjq7vn
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/116742] -Wuninitialized failed to issue uninitialized variable
2024-09-16 13:30 [Bug c++/116742] New: -Wuninitialized failed to issue uninitialized variable xiaohuba2021 at 163 dot com
@ 2024-09-16 14:07 ` pinskia at gcc dot gnu.org
2024-09-17 8:06 ` rguenth at gcc dot gnu.org
2024-09-23 1:54 ` xiaohuba2021 at 163 dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-16 14:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116742
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Blocks| |24639
Component|c++ |tree-optimization
Keywords| |diagnostic
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There might be a dup of this one already.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/116742] -Wuninitialized failed to issue uninitialized variable
2024-09-16 13:30 [Bug c++/116742] New: -Wuninitialized failed to issue uninitialized variable xiaohuba2021 at 163 dot com
2024-09-16 14:07 ` [Bug tree-optimization/116742] " pinskia at gcc dot gnu.org
@ 2024-09-17 8:06 ` rguenth at gcc dot gnu.org
2024-09-23 1:54 ` xiaohuba2021 at 163 dot com
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-09-17 8:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116742
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-09-17
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is that 'n' is address taken and escapes:
<bb 2> :
std::ios_base::sync_with_stdio (0);
<bb 3> :
std::basic_ios<char>::tie (&cin.D.48191, 0B);
s_6 = n;
std::basic_istream<char>::operator>> (&cin, &n);
<bb 4> :
_9 = std::basic_ostream<char>::operator<< (&cout, s_6);
we thus consider that for example std::ios_base::sync_with_stdio might
initialize 'n' since we lose the fact that 'n' only becomes live after that
call. The C++ frontend does not add explicit scopes for
int n, s = n;
so it doesn't get CLOBBER treatment. Adding scopes doesn't help either
(the gimplifier doesn't add CLOBBERs for start-of-live).
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/116742] -Wuninitialized failed to issue uninitialized variable
2024-09-16 13:30 [Bug c++/116742] New: -Wuninitialized failed to issue uninitialized variable xiaohuba2021 at 163 dot com
2024-09-16 14:07 ` [Bug tree-optimization/116742] " pinskia at gcc dot gnu.org
2024-09-17 8:06 ` rguenth at gcc dot gnu.org
@ 2024-09-23 1:54 ` xiaohuba2021 at 163 dot com
2 siblings, 0 replies; 4+ messages in thread
From: xiaohuba2021 at 163 dot com @ 2024-09-23 1:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116742
--- Comment #3 from xiaohuba2021 <xiaohuba2021 at 163 dot com> ---
So is there any workaround or patch?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-23 1:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-16 13:30 [Bug c++/116742] New: -Wuninitialized failed to issue uninitialized variable xiaohuba2021 at 163 dot com
2024-09-16 14:07 ` [Bug tree-optimization/116742] " pinskia at gcc dot gnu.org
2024-09-17 8:06 ` rguenth at gcc dot gnu.org
2024-09-23 1:54 ` xiaohuba2021 at 163 dot com
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).