public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr
@ 2013-04-29 12:29 jb.1234abcd at gmail dot com
2013-04-29 12:57 ` [Bug c++/57111] " redi at gcc dot gnu.org
` (17 more replies)
0 siblings, 18 replies; 19+ messages in thread
From: jb.1234abcd at gmail dot com @ 2013-04-29 12:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
Bug #: 57111
Summary: Core dump - invalid pointer detected after
std::unique_ptr
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: jb.1234abcd@gmail.com
$ cat uniqueptr.cpp
#include <iostream>
#include <memory>
int main () {
int arr[]={1,2};
std::unique_ptr<int[]> up(arr);
std::cout << up[0];
return 0;
}
$ g++ -std=c++11 -Wall -o uniqueptr uniqueptr.cpp
$ ./uniqueptr
*** glibc detected *** ./uniqueptr: free(): invalid pointer: 0xbfe35788 ***
======= Backtrace: =========
/lib/libc.so.6[0x4ce44ff9]
/lib/libstdc++.so.6(_ZdlPv+0x20)[0x4d414500]
/lib/libstdc++.so.6(_ZdaPv+0x1c)[0x4d41455c]
./uniqueptr[0x80489fd]
./uniqueptr[0x8048966]
./uniqueptr[0x8048765]
/lib/libc.so.6(__libc_start_main+0xf5)[0x4cde8865]
./uniqueptr[0x8048611]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:09 1963079 /home/jb/prog-c++/uniqueptr
0804a000-0804b000 r--p 00001000 08:09 1963079 /home/jb/prog-c++/uniqueptr
0804b000-0804c000 rw-p 00002000 08:09 1963079 /home/jb/prog-c++/uniqueptr
08dbf000-08de0000 rw-p 00000000 00:00 0 [heap]
4cdac000-4cdcb000 r-xp 00000000 08:09 655817 /usr/lib/ld-2.16.so
4cdcb000-4cdcc000 r--p 0001e000 08:09 655817 /usr/lib/ld-2.16.so
4cdcc000-4cdcd000 rw-p 0001f000 08:09 655817 /usr/lib/ld-2.16.so
4cdcf000-4cf7f000 r-xp 00000000 08:09 659071 /usr/lib/libc-2.16.so
4cf7f000-4cf81000 r--p 001b0000 08:09 659071 /usr/lib/libc-2.16.so
4cf81000-4cf82000 rw-p 001b2000 08:09 659071 /usr/lib/libc-2.16.so
4cf82000-4cf85000 rw-p 00000000 00:00 0
4cfce000-4d00c000 r-xp 00000000 08:09 664509 /usr/lib/libm-2.16.so
4d00c000-4d00d000 r--p 0003d000 08:09 664509 /usr/lib/libm-2.16.so
4d00d000-4d00e000 rw-p 0003e000 08:09 664509 /usr/lib/libm-2.16.so
4d010000-4d02c000 r-xp 00000000 08:09 664696
/usr/lib/libgcc_s-4.7.2-20121109.so.1
4d02c000-4d02d000 r--p 0001b000 08:09 664696
/usr/lib/libgcc_s-4.7.2-20121109.so.1
4d02d000-4d02e000 rw-p 0001c000 08:09 664696
/usr/lib/libgcc_s-4.7.2-20121109.so.1
4d3c9000-4d4a9000 r-xp 00000000 08:09 664705 /usr/lib/libstdc++.so.6.0.17
4d4a9000-4d4ad000 r--p 000df000 08:09 664705 /usr/lib/libstdc++.so.6.0.17
4d4ad000-4d4af000 rw-p 000e3000 08:09 664705 /usr/lib/libstdc++.so.6.0.17
4d4af000-4d4b5000 rw-p 00000000 00:00 0
b7777000-b777a000 rw-p 00000000 00:00 0
b778b000-b778e000 rw-p 00000000 00:00 0
b778e000-b778f000 r-xp 00000000 00:00 0 [vdso]
bfe17000-bfe38000 rw-p 00000000 00:00 0 [stack]
1Aborted (core dumped)
$
Packages:
gcc-c++-4.7.2-8.fc18.i686
glibc-2.16-30.fc18.i686
libstdc++-4.7.2-8.fc18.i686
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Core dump - invalid pointer detected after std::unique_ptr
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
@ 2013-04-29 12:57 ` redi at gcc dot gnu.org
2013-04-29 14:04 ` jb.1234abcd at gmail dot com
` (16 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: redi at gcc dot gnu.org @ 2013-04-29 12:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-04-29 12:57:36 UTC ---
That's not how you use unique_ptr.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Core dump - invalid pointer detected after std::unique_ptr
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
2013-04-29 12:57 ` [Bug c++/57111] " redi at gcc dot gnu.org
@ 2013-04-29 14:04 ` jb.1234abcd at gmail dot com
2013-04-29 14:09 ` redi at gcc dot gnu.org
` (15 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jb.1234abcd at gmail dot com @ 2013-04-29 14:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #2 from jb <jb.1234abcd at gmail dot com> 2013-04-29 14:04:38 UTC ---
(In reply to comment #1)
> That's not how you use unique_ptr.
That's besides the point when you get a dump.
If the proper use of unique_ptr with array is:
unique_ptr<int[]> up(new int[4]); //array version of unique_ptr
then the compiler should give a warning on "improper use", do not you think ?
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Core dump - invalid pointer detected after std::unique_ptr
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
2013-04-29 12:57 ` [Bug c++/57111] " redi at gcc dot gnu.org
2013-04-29 14:04 ` jb.1234abcd at gmail dot com
@ 2013-04-29 14:09 ` redi at gcc dot gnu.org
2013-04-30 18:37 ` glisse at gcc dot gnu.org
` (14 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: redi at gcc dot gnu.org @ 2013-04-29 14:09 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-04-29 14:09:46 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > That's not how you use unique_ptr.
>
> That's besides the point when you get a dump.
No, it's entirely the point, you get a coredump because your program has
undefined behaviour when it attempts to delete a stack variable.
> If the proper use of unique_ptr with array is:
> unique_ptr<int[]> up(new int[4]); //array version of unique_ptr
> then the compiler should give a warning on "improper use", do not you think ?
The compiler can't warn about everything. Sometimes you just have to meet the
requirements of the API you're using and not to stupid things.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Core dump - invalid pointer detected after std::unique_ptr
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (2 preceding siblings ...)
2013-04-29 14:09 ` redi at gcc dot gnu.org
@ 2013-04-30 18:37 ` glisse at gcc dot gnu.org
2013-04-30 21:57 ` jb.1234abcd at gmail dot com
` (13 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-04-30 18:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> 2013-04-30 18:37:41 UTC ---
gcc has -Wfree-nonheap-object, which works for free but not for delete or
delete[]. Extending it to these functions seems like a reasonable RFE.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Core dump - invalid pointer detected after std::unique_ptr
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (3 preceding siblings ...)
2013-04-30 18:37 ` glisse at gcc dot gnu.org
@ 2013-04-30 21:57 ` jb.1234abcd at gmail dot com
2013-04-30 22:07 ` glisse at gcc dot gnu.org
` (12 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jb.1234abcd at gmail dot com @ 2013-04-30 21:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #5 from jb <jb.1234abcd at gmail dot com> 2013-04-30 21:57:00 UTC ---
(In reply to comment #4)
> gcc has -Wfree-nonheap-object, which works for free but not for delete or
> delete[]. Extending it to these functions seems like a reasonable RFE.
I agree with your suggestion.
gcc(1)
-Wno-free-nonheap-object
Do not warn when attempting to free an object that was not
allocated on the heap.
The above is a non-default option.
$ cat free-test.c
#include <stdlib.h>
int main () {
int arr[] = {1,2};
int * p = arr;
free(p);
return 0;
}
$ gcc -Wall -o free-test free-test.c
$ ./free-test
Segmentation fault (core dumped)
$ gcc -Wall -Wfree-nonheap-object -o free-test free-test.c
$ ./free-test
Segmentation fault (core dumped)
$ gcc -Wall -Wno-free-nonheap-object -o free-test free-test.c
$ ./free-test
Segmentation fault (core dumped)
$
It seems to me that the option "free-nonheap-object" does not work in gcc.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Core dump - invalid pointer detected after std::unique_ptr
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (4 preceding siblings ...)
2013-04-30 21:57 ` jb.1234abcd at gmail dot com
@ 2013-04-30 22:07 ` glisse at gcc dot gnu.org
2013-04-30 22:22 ` jb.1234abcd at gmail dot com
` (11 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-04-30 22:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #6 from Marc Glisse <glisse at gcc dot gnu.org> 2013-04-30 22:07:02 UTC ---
(In reply to comment #5)
> It seems to me that the option "free-nonheap-object" does not work in gcc.
You need to add -O2 (maybe -O1 is enough, sometimes you need -O3), otherwise
gcc does not propagate the information of what p is all the way to free.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Core dump - invalid pointer detected after std::unique_ptr
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (5 preceding siblings ...)
2013-04-30 22:07 ` glisse at gcc dot gnu.org
@ 2013-04-30 22:22 ` jb.1234abcd at gmail dot com
2013-04-30 22:58 ` [Bug c++/57111] Generalize -Wfree-nonheap-object to delete glisse at gcc dot gnu.org
` (10 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jb.1234abcd at gmail dot com @ 2013-04-30 22:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #7 from jb <jb.1234abcd at gmail dot com> 2013-04-30 22:22:44 UTC ---
(In reply to comment #6)
> (In reply to comment #5)
> > It seems to me that the option "free-nonheap-object" does not work in gcc.
>
> You need to add -O2 (maybe -O1 is enough, sometimes you need -O3), otherwise
> gcc does not propagate the information of what p is all the way to free.
OK, that worked.
$ gcc -O1 -Wall -o free-test free-test.c
free-test.c: In function ‘main’:
free-test.c:6:7: warning: attempt to free a non-heap object ‘arr’
[-Wfree-nonheap-object]
>From gcc-bugs-return-421323-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Apr 30 22:50:16 2013
Return-Path: <gcc-bugs-return-421323-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 29022 invoked by alias); 30 Apr 2013 22:50:16 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 28997 invoked by uid 48); 30 Apr 2013 22:50:13 -0000
From: "jb.1234abcd at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/57111] Core dump - invalid pointer detected after std::unique_ptr
Date: Tue, 30 Apr 2013 22:50:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jb.1234abcd at gmail dot com
X-Bugzilla-Status: VERIFIED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields: Status
Message-ID: <bug-57111-4-DuX2JA4WZq@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57111-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57111-4@http.gcc.gnu.org/bugzilla/>
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
X-SW-Source: 2013-04/txt/msg02468.txt.bz2
Content-length: 474
http://gcc.gnu.org/bugzilla/show_bug.cgi?idW111
jb <jb.1234abcd at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |VERIFIED
--- Comment #8 from jb <jb.1234abcd at gmail dot com> 2013-04-30 22:50:12 UTC ---
Please reopen this bug report.
The RFE will make this feature consistent across gcc and g++.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (6 preceding siblings ...)
2013-04-30 22:22 ` jb.1234abcd at gmail dot com
@ 2013-04-30 22:58 ` glisse at gcc dot gnu.org
2013-04-30 23:01 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-04-30 22:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
Marc Glisse <glisse at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|VERIFIED |UNCONFIRMED
Resolution|INVALID |
Summary|Core dump - invalid pointer |Generalize
|detected after |-Wfree-nonheap-object to
|std::unique_ptr |delete
Severity|normal |enhancement
--- Comment #9 from Marc Glisse <glisse at gcc dot gnu.org> 2013-04-30 22:58:53 UTC ---
"verified" isn't the right status, you are hoping for someone to set it to NEW,
and leaving it at unconfirmed is the way to say that.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (7 preceding siblings ...)
2013-04-30 22:58 ` [Bug c++/57111] Generalize -Wfree-nonheap-object to delete glisse at gcc dot gnu.org
@ 2013-04-30 23:01 ` redi at gcc dot gnu.org
2020-11-05 17:52 ` msebor at gcc dot gnu.org
` (8 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: redi at gcc dot gnu.org @ 2013-04-30 23:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-04-30
Ever Confirmed|0 |1
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-04-30 23:01:11 UTC ---
OK, confirmed as a diagnostic enhancement
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (8 preceding siblings ...)
2013-04-30 23:01 ` redi at gcc dot gnu.org
@ 2020-11-05 17:52 ` msebor at gcc dot gnu.org
2020-11-09 14:51 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-11-05 17:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
CC| |msebor at gcc dot gnu.org
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=90629
--- Comment #11 from Martin Sebor <msebor at gcc dot gnu.org> ---
The patch I submitted for pr90629 implements this enhancement:
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/557987.html
It detects the bug in the test case in comment #0 but only with optimization
(to see through inlined calls) and with -Wsystem-headers. Just like all late
warnings to date, -Wfree-nonheap-object isn't without false positives. pr54202
is one that even the exceedingly simplistic -Wfree-nonheap-object is
susceptible to. The patch above doesn't change things.
In file included from
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/memory:76,
from t.C:2:
In member function ‘typename std::enable_if<std::is_convertible<_Up (*)[], _Tp
(*)[]>::value>::type std::default_delete<_Tp []>::operator()(_Up*) const [with
_Up = int; _Tp = int]’,
inlined from ‘std::unique_ptr<_Tp [], _Dp>::~unique_ptr() [with _Tp = int;
_Dp = std::default_delete<int []>]’ at
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/unique_ptr.h:612:17,
inlined from ‘int main()’ at t.C:6:32:
/build/gcc-trunk/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/unique_ptr.h:120:11:
warning: ‘void operator delete [](void*)’ called on unallocated object ‘arr’
[-Wfree-nonheap-object]
120 | delete [] __ptr;
| ^~~~~~~~~~~~~~~
t.C: In function ‘int main()’:
t.C:5:7: note: declared here
5 | int arr[]={1,2};
| ^~~
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (9 preceding siblings ...)
2020-11-05 17:52 ` msebor at gcc dot gnu.org
@ 2020-11-09 14:51 ` redi at gcc dot gnu.org
2020-12-03 22:56 ` msebor at gcc dot gnu.org
` (6 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: redi at gcc dot gnu.org @ 2020-11-09 14:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #11)
> It detects the bug in the test case in comment #0 but only with optimization
> (to see through inlined calls) and with -Wsystem-headers.
This seems like a warning that should not be suppressed in system headers.
Diagnostic pragmas could be added to system headers to suppress false
positives.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (10 preceding siblings ...)
2020-11-09 14:51 ` redi at gcc dot gnu.org
@ 2020-12-03 22:56 ` msebor at gcc dot gnu.org
2020-12-08 20:51 ` msebor at gcc dot gnu.org
` (5 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-12-03 22:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
--- Comment #13 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #12)
> (In reply to Martin Sebor from comment #11)
> > It detects the bug in the test case in comment #0 but only with optimization
> > (to see through inlined calls) and with -Wsystem-headers.
>
> This seems like a warning that should not be suppressed in system headers.
>
> Diagnostic pragmas could be added to system headers to suppress false
> positives.
I agree. I thought it was due to an omission on my part but after checking I
see that the code does jump through all the necessary hoops to trigger even in
system headers, so it's a bug that it doesn't. Let me see what's going on.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (11 preceding siblings ...)
2020-12-03 22:56 ` msebor at gcc dot gnu.org
@ 2020-12-08 20:51 ` msebor at gcc dot gnu.org
2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-12-08 20:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #14 from Martin Sebor <msebor at gcc dot gnu.org> ---
The following enables the warning for the test case reported in comment #0 (and
all libstdc++ code):
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/561378.html
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (12 preceding siblings ...)
2020-12-08 20:51 ` msebor at gcc dot gnu.org
@ 2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
2020-12-14 20:34 ` msebor at gcc dot gnu.org
` (3 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-14 20:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #15 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:
https://gcc.gnu.org/g:fe7f75cf16783589eedbab597e6d0b8d35d7e470
commit r11-6028-gfe7f75cf16783589eedbab597e6d0b8d35d7e470
Author: Martin Sebor <msebor@redhat.com>
Date: Mon Dec 14 13:30:00 2020 -0700
Correct/improve maybe_emit_free_warning (PR middle-end/98166, PR c++/57111,
PR middle-end/98160).
Resolves:
PR middle-end/98166 - bogus -Wmismatched-dealloc on user-defined allocator
and inlining
PR c++/57111 - 57111 - Generalize -Wfree-nonheap-object to delete
PR middle-end/98160 - ICE in default_tree_printer at
gcc/tree-diagnostic.c:270
gcc/ChangeLog:
PR middle-end/98166
PR c++/57111
PR middle-end/98160
* builtins.c (check_access): Call tree_inlined_location
fndecl_alloc_p): Handle BUILT_IN_ALIGNED_ALLOC and
BUILT_IN_GOMP_ALLOC.
call_dealloc_p): Remove unused function.
(new_delete_mismatch_p): Call valid_new_delete_pair_p and rework.
(matching_alloc_calls_p): Handle built-in deallocation functions.
(warn_dealloc_offset): Corrct the handling of user-defined
operators
delete.
(maybe_emit_free_warning): Avoid assuming expression is a decl.
Simplify.
* doc/extend.texi (attribute malloc): Update.
* tree-ssa-dce.c (valid_new_delete_pair_p): Factor code out into
valid_new_delete_pair_p in tree.c.
* tree.c (tree_inlined_location): Define new function.
(valid_new_delete_pair_p): Define.
* tree.h (tree_inlined_location): Declare.
(valid_new_delete_pair_p): Declare.
gcc/c-family/ChangeLog:
PR middle-end/98166
PR c++/57111
PR middle-end/98160
* c-attribs.c (maybe_add_noinline): New function.
(handle_malloc_attribute): Call it. Use ATTR_FLAG_INTERNAL.
Implicitly add attribute noinline to functions not declared inline
and warn on those.
libstdc++-v3/ChangeLog:
* testsuite/ext/vstring/requirements/exception/basic.cc: Suppress
a false positive warning.
*
testsuite/ext/vstring/requirements/exception/propagation_consistent.cc:
Same.
gcc/testsuite/ChangeLog:
PR middle-end/98166
PR c++/57111
PR middle-end/98160
* g++.dg/warn/Wmismatched-dealloc-2.C: Adjust test of expected
warning.
* g++.dg/warn/Wmismatched-new-delete.C: Same.
* gcc.dg/Wmismatched-dealloc.c: Same.
* c-c++-common/Wfree-nonheap-object-2.c: New test.
* c-c++-common/Wfree-nonheap-object-3.c: New test.
* c-c++-common/Wfree-nonheap-object.c: New test.
* c-c++-common/Wmismatched-dealloc.c: New test.
* g++.dg/warn/Wfree-nonheap-object-3.C: New test.
* g++.dg/warn/Wfree-nonheap-object-4.C: New test.
* g++.dg/warn/Wmismatched-dealloc-2.C: New test.
* g++.dg/warn/Wmismatched-new-delete-2.C: New test.
* g++.dg/warn/Wmismatched-new-delete.C: New test.
* gcc.dg/Wmismatched-dealloc-2.c: New test.
* gcc.dg/Wmismatched-dealloc-3.c: New test.
* gcc.dg/Wmismatched-dealloc.c: New test.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (13 preceding siblings ...)
2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
@ 2020-12-14 20:34 ` msebor at gcc dot gnu.org
2021-01-10 23:21 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-12-14 20:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=54202
Status|ASSIGNED |RESOLVED
Target Milestone|--- |11.0
Resolution|--- |FIXED
--- Comment #16 from Martin Sebor <msebor at gcc dot gnu.org> ---
Done for GCC 11, including issuing warnings for system headers. As I
mentioned, the warning is not free of false positives (e.g., pr54202).
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (14 preceding siblings ...)
2020-12-14 20:34 ` msebor at gcc dot gnu.org
@ 2021-01-10 23:21 ` cvs-commit at gcc dot gnu.org
2023-06-14 9:43 ` cvs-commit at gcc dot gnu.org
2023-06-15 7:21 ` cvs-commit at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-10 23:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #17 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Edelsohn <dje@gcc.gnu.org>:
https://gcc.gnu.org/g:4a1d7f7e203d0ec4b9d67ea6fc9b84bee1e211d3
commit r11-6573-g4a1d7f7e203d0ec4b9d67ea6fc9b84bee1e211d3
Author: David Edelsohn <dje.gcc@gmail.com>
Date: Sun Jan 10 18:10:34 2021 -0500
libstdc++: Suppress more vstring testsuite warnings. [PR 98613]
PR c++/57111 - 57111 - Generalize -Wfree-nonheap-object to delete
can create false positive warnings for vstring _S_empty_rep.
This patch prunes the excess false positive warnings from two more
testcases.
libstdc++-v3/ChangeLog:
PR libstdc++/98613
* testsuite/ext/vstring/cons/moveable.cc: Suppress false positive
warning.
* testsuite/ext/vstring/modifiers/assign/move_assign.cc: Same.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (15 preceding siblings ...)
2021-01-10 23:21 ` cvs-commit at gcc dot gnu.org
@ 2023-06-14 9:43 ` cvs-commit at gcc dot gnu.org
2023-06-15 7:21 ` cvs-commit at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-14 9:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #18 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>:
https://gcc.gnu.org/g:9c03391ba447ff86038d6a34c90ae737c3915b5f
commit r14-1805-g9c03391ba447ff86038d6a34c90ae737c3915b5f
Author: Thomas Schwinge <thomas@codesourcery.com>
Date: Wed Jun 7 16:24:26 2023 +0200
Tighten 'dg-warning' alternatives in
'c-c++-common/Wfree-nonheap-object{,-2,-3}.c'
..., added in commit fe7f75cf16783589eedbab597e6d0b8d35d7e470
"Correct/improve maybe_emit_free_warning (PR middle-end/98166, PR
c++/57111, PR middle-end/98160)".
These use alternatives like, for example, "AB|CDE|FG", but what really
must've
been meant is "A(B|C)D(E|F)G". The former variant also does "work": it
matches
any of "AB", or "CDE", or "FG", which are components of the latter variant.
(That means, the former variant matches too loosely.)
gcc/testsuite/
* c-c++-common/Wfree-nonheap-object-2.c: Tighten 'dg-warning'
alternatives.
* c-c++-common/Wfree-nonheap-object-3.c: Likewise.
* c-c++-common/Wfree-nonheap-object.c: Likewise.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c++/57111] Generalize -Wfree-nonheap-object to delete
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
` (16 preceding siblings ...)
2023-06-14 9:43 ` cvs-commit at gcc dot gnu.org
@ 2023-06-15 7:21 ` cvs-commit at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-15 7:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111
--- Comment #19 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>:
https://gcc.gnu.org/g:df071fbd467f0cb3711119ef41d74792fc5e6c8c
commit r14-1838-gdf071fbd467f0cb3711119ef41d74792fc5e6c8c
Author: Thomas Schwinge <thomas@codesourcery.com>
Date: Wed Jun 7 17:12:01 2023 +0200
Fix 'dg-warning' in 'c-c++-common/Wfree-nonheap-object-3.c' for C++
[...]/c-c++-common/Wfree-nonheap-object-3.c:57:24: warning: 'malloc
(dealloc_float)' attribute ignored with deallocation functions declared
'inline' [-Wattributes]
[...]/c-c++-common/Wfree-nonheap-object-3.c:51:1: note: deallocation
function declared here
[...]/c-c++-common/Wfree-nonheap-object-3.c: In function 'void
test_nowarn_int(int)':
[...]/c-c++-common/Wfree-nonheap-object-3.c:25:20: warning: 'void
__builtin_free(void*)' called on pointer 'p' with nonzero offset 4
[-Wfree-nonheap-object]
[...]/c-c++-common/Wfree-nonheap-object-3.c:24:24: note: returned from
'int* alloc_int(int)'
[...]/c-c++-common/Wfree-nonheap-object-3.c: In function 'void
test_nowarn_long(int)':
[...]/c-c++-common/Wfree-nonheap-object-3.c:45:18: warning: 'void
dealloc_long(long int*)' called on pointer '<unknown>' with nonzero offset 8
[-Wfree-nonheap-object]
[...]/c-c++-common/Wfree-nonheap-object-3.c:44:26: note: returned from
'long int* alloc_long(int)'
In function 'void dealloc_float(float*)',
inlined from 'void test_nowarn_float(int)' at
[...]/c-c++-common/Wfree-nonheap-object-3.c:68:19:
[...]/c-c++-common/Wfree-nonheap-object-3.c:53:18: warning: 'void
__builtin_free(void*)' called on pointer '<unknown>' with nonzero offset 8
[-Wfree-nonheap-object]
[...]/c-c++-common/Wfree-nonheap-object-3.c: In function 'void
test_nowarn_float(int)':
[...]/c-c++-common/Wfree-nonheap-object-3.c:67:28: note: returned from
'float* alloc_float(int)'
PASS: c-c++-common/Wfree-nonheap-object-3.c -std=gnu++98 (test for
warnings, line 25)
FAIL: c-c++-common/Wfree-nonheap-object-3.c -std=gnu++98 (test for
warnings, line 45)
PASS: c-c++-common/Wfree-nonheap-object-3.c -std=gnu++98 (test for
warnings, line 51)
PASS: c-c++-common/Wfree-nonheap-object-3.c -std=gnu++98 (test for
warnings, line 53)
PASS: c-c++-common/Wfree-nonheap-object-3.c -std=gnu++98 (test for
warnings, line 57)
FAIL: c-c++-common/Wfree-nonheap-object-3.c -std=gnu++98 (test for
excess errors)
Excess errors:
[...]/c-c++-common/Wfree-nonheap-object-3.c:45:18: warning: 'void
dealloc_long(long int*)' called on pointer '<unknown>' with nonzero offset 8
[-Wfree-nonheap-object]
..., that is: decorated 'void dealloc_long(long int*)' instead of plain
'dealloc_long' -- similar to how all the other 'dg-warning's allow for the
decorated function signature in addition to the plain one.
This issue was latent since the test case was added in
commit fe7f75cf16783589eedbab597e6d0b8d35d7e470
"Correct/improve maybe_emit_free_warning (PR middle-end/98166, PR
c++/57111, PR middle-end/98160)",
and was finally exposed by my recent
commit 9c03391ba447ff86038d6a34c90ae737c3915b5f
"Tighten 'dg-warning' alternatives in
'c-c++-common/Wfree-nonheap-object{,-2,-3}.c'".
gcc/testsuite/
* c-c++-common/Wfree-nonheap-object-3.c: Fix 'dg-warning' for C++.
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2023-06-15 7:21 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-29 12:29 [Bug c++/57111] New: Core dump - invalid pointer detected after std::unique_ptr jb.1234abcd at gmail dot com
2013-04-29 12:57 ` [Bug c++/57111] " redi at gcc dot gnu.org
2013-04-29 14:04 ` jb.1234abcd at gmail dot com
2013-04-29 14:09 ` redi at gcc dot gnu.org
2013-04-30 18:37 ` glisse at gcc dot gnu.org
2013-04-30 21:57 ` jb.1234abcd at gmail dot com
2013-04-30 22:07 ` glisse at gcc dot gnu.org
2013-04-30 22:22 ` jb.1234abcd at gmail dot com
2013-04-30 22:58 ` [Bug c++/57111] Generalize -Wfree-nonheap-object to delete glisse at gcc dot gnu.org
2013-04-30 23:01 ` redi at gcc dot gnu.org
2020-11-05 17:52 ` msebor at gcc dot gnu.org
2020-11-09 14:51 ` redi at gcc dot gnu.org
2020-12-03 22:56 ` msebor at gcc dot gnu.org
2020-12-08 20:51 ` msebor at gcc dot gnu.org
2020-12-14 20:31 ` cvs-commit at gcc dot gnu.org
2020-12-14 20:34 ` msebor at gcc dot gnu.org
2021-01-10 23:21 ` cvs-commit at gcc dot gnu.org
2023-06-14 9:43 ` cvs-commit at gcc dot gnu.org
2023-06-15 7:21 ` cvs-commit 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).