[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 Richard Biener changed: What|Removed |Added Keywords||missed-optimization Last reconfirmed||2022-12-22 Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Priority|P3 |P2 --- Comment #11 from Richard Biener --- Confirmed. We're diagnosing the read # VUSE <.MEM_106> _60 = MEM[(const struct basic_string *)]._M_string_length; which happens conditional after the lifetime of D.48280 starts: MEM[(struct __as_base &)] ={v} {CLOBBER}; MEM[(union _Variadic_union *)] ={v} {CLOBBER}; MEM[(union _Variadic_union *)] ={v} {CLOBBER}; MEM[(struct _Uninitialized *)] ={v} {CLOBBER}; _128 = (void *) ivtmp.494_2; _19 = MEM[(const type &)_128]; MEM[(struct _Uninitialized *)]._M_storage = _19; MEM[(struct _Variant_storage *)]._M_index = 2; ... the condition chains is [local count: 668941184]: MEM[(struct _Variant_storage *)_35]._M_index = 255; _45 = D.48280.D.48091.D.47570.D.47488.D.47356.D.47242.D.47146._M_index; _46 = (signed char) _45; _47 = (long unsigned int) _46; if (_47 > 4) goto ; [16.67%] else goto ; [83.33%] [local count: 557450988]: switch (_45) [20.00%], case 1: [20.00%], case 2: [20.00%], case 3: [20.00%], case 4: [20.00%]> [local count: 111490196]: : _57 = [(struct basic_string *)_35].D.36033._M_local_buf; MEM[(struct _Alloc_hider *)_35]._M_p = _57; _58 = MEM[(const struct basic_string *)]._M_dataplus._M_p; if ([(const struct basic_string *)].D.36033._M_local_buf == _58) goto ; [30.00%] else goto ; [70.00%] [local count: 33447058]: _60 = MEM[(const struct basic_string *)]._M_string_length; in this case we have other stores possibly clobbering the _M_index store so we fail to statically optimize these branches (from the = 2 initializer which should be still there?).
[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 --- Comment #10 from Jonathan Wakely --- (In reply to Marco Clemencic from comment #8) > But the warning is not issued in -O0 builds, which I believe means the code > is correct by itself, That's not a valid assumption. -Wmaybe-uninitialized doesn't even run for -O0 so you won't get those warnings even for incorrect code. So you can't infer anything from the absence of such warnings with -O0.
[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 Freddie Chopin changed: What|Removed |Added CC||freddie_chopin at op dot pl --- Comment #8 from Marco Clemencic --- That explains it then, thanks for the info. I admit I like the idea a lot. I'm just surprised that we do get warnings from the C++ standard library in some perfectly reasonable code... Now I have to decide what to do in my code. Probably I'll have to selectively suppress the warning, which is something I hate. But the warning is not issued in -O0 builds, which I believe means the code is correct by itself, but I have the feeling the warning gets checked after the optimizer refactored the code taking into account invariants already checked and at that point the "maybe-uninitialized" checker gets confused. If this is the case we can argue if it is the intended behavior or a bug in the way this new feature has been implemented. --- Comment #9 from Freddie Chopin --- Possibly related/duplicate #107919
[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 --- Comment #7 from Jonathan Wakely --- No, it's just that some warnings coming from code in system headers are no longer suppressed if they are the result of a template instantiation triggered in user code. That was a deliberate choice (although IMHO the set of warnings that now trigger in system headers are not the ones I actually thought would be useful).
[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 --- Comment #6 from Marco Clemencic --- I seem to be stumbling on more and more of these spurious warnings. The latest one is from a header that is found in a directory added to the search path with "-isystem", and in all cases the warnings talk about methods and functions that are "inlined from ...". I didn't manage to produce a minimal test case proving it, but I start suspecting that "-isystem" is ignored (in some circumstances) when functions get inlined.
[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 --- Comment #5 from Marco Clemencic --- I forgot to mention that I compiled with the options: g++ -c -Wmaybe-uninitialized -O1 -v -save-temps test.cpp
[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 --- Comment #4 from Marco Clemencic --- I have a similar problem with this chunk of code: ``` #include #include #include #include #include struct Wrapper { using Map = std::map; using Value = std::variant; Wrapper(Value v) : data{std::move(v)} {} Value data; }; auto f() { Wrapper::Map r; return std::make_unique(std::move(r)); // <- warning here // return std::make_unique(r); // <- no warning // return Wrapper(std::move(r)); // <- no warning } ``` but the uninitialized variable is coming from std::unique_ptr. As in the original report it works with gcc 11.3, but it fails with gcc12.2 and trunk (in my case already with -O1), see https://godbolt.org/z/bfo9vsEPc I attached the .ii produced by my test case.
[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 Marco Clemencic changed: What|Removed |Added CC||marco.clemencic at gmail dot com --- Comment #3 from Marco Clemencic --- Created attachment 53918 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53918=edit another example of false uninitialized warning
[Bug c++/107138] [12/13 regression] std::variant triggers false-positive 'may be used uninitialized' warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 Richard Biener changed: What|Removed |Added Keywords||diagnostic Summary|[12 regression] |[12/13 regression] |std::variant triggers |...> triggers |false-positive 'may be used |false-positive 'may be used |uninitialized' warning |uninitialized' warning Blocks||24639 Target Milestone|--- |12.3 Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639 [Bug 24639] [meta-bug] bug to track all Wuninitialized issues