public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107264] New: -O1 disables -Wfree-nonheap-object on a map
@ 2022-10-14 14:25 federico at kircheis dot it
2022-10-14 15:39 ` [Bug middle-end/107264] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: federico at kircheis dot it @ 2022-10-14 14:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107264
Bug ID: 107264
Summary: -O1 disables -Wfree-nonheap-object on a map
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: federico at kircheis dot it
Target Milestone: ---
Consider following code
----
#include <map>
struct Opaque;
void foo1(std::map<int*, Opaque*> v){
for (auto itr = v.begin(); itr != v.end(); ++itr) {
delete &itr->second;
}
}
----
when compiled without parameters, gcc diagnoses "warning: 'void operator
delete(void*, std::size_t)' called on pointer '<unknown>' with nonzero offset 8
[-Wfree-nonheap-object]
delete &itr->second;"
But when compiling at least with -O1, the diagnosis is done, eve when
explicitely adding "-Wfree-nonheap-object" as parameter:
https://godbolt.org/z/Percs3nqa
I've tested different scenarios (see https://godbolt.org/z/eba9axb1h), with a
for-each loop, for example, the diagnosis is active even with -O1.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug middle-end/107264] -O1 disables -Wfree-nonheap-object on a map
2022-10-14 14:25 [Bug c++/107264] New: -O1 disables -Wfree-nonheap-object on a map federico at kircheis dot it
@ 2022-10-14 15:39 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-14 15:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107264
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2022-10-14
Component|c++ |middle-end
Status|UNCONFIRMED |NEW
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
AT -O0 the IR is:
_1 = std::_Rb_tree_iterator<std::pair<int* const, Opaque*> >::operator->
(&itr);
_13 = &_1->second;
if (_13 != 0B)
goto <bb 4>; [INV]
else
goto <bb 5>; [INV]
<bb 4> :
*_13 ={v} {CLOBBER};
operator delete (_13, 8);
While at -O1:
_6 = &MEM[(struct pair *)itr$_M_node_18 + 32B].second;
operator delete (_6, 8);
I am shocked that didn't detect as a problem.
Confirmed.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-14 15:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-14 14:25 [Bug c++/107264] New: -O1 disables -Wfree-nonheap-object on a map federico at kircheis dot it
2022-10-14 15:39 ` [Bug middle-end/107264] " 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).