public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110694] New: False Positive -Werror=free-nonheap-object
@ 2023-07-17 0:54 biggs at biggs dot xyz
2023-07-17 0:59 ` [Bug middle-end/110694] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: biggs at biggs dot xyz @ 2023-07-17 0:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110694
Bug ID: 110694
Summary: False Positive -Werror=free-nonheap-object
Product: gcc
Version: 13.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: biggs at biggs dot xyz
Target Milestone: ---
Created attachment 55559
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55559&action=edit
Source File
Observed on Trunk and 13.1.1
Consider:
```c
#include <stdlib.h>
typedef struct S S;
struct S {
int* i;
};
static S* s_constructor(void) {
S* s = malloc(sizeof(*s));
if (s) s->i = calloc(1, sizeof(*(s->i)));
return s;
}
static void s_destructor(S* s) {
if (!s) return;
free(s->i);
free(s);
}
static void s_destructor2(S s[static 1]) {
free(s->i);
free(s);
}
int main(void) {
S* s = s_constructor();
s_destructor(s);
s = s_constructor();
if (s) s_destructor2(s);
s = (void*) 0;
return EXIT_SUCCESS;
}
```
Compiling with gcc -Wall -Werror produces the error:
<source>: In function 's_destructor2':
<source>:23:5: error: 'free' called on unallocated object 's'
[-Werror=free-nonheap-object]
23 | free(s);
| ^~~~~~~
<source>:21:29: note: declared here
21 | static void s_destructor2(S s[static 1]) {
| ~~^~~~~~~~~~~
cc1: all warnings being treated as errors
However, there is no error when compiled with -O1 or higher optimization flag.
I don't think s_destructor2(S s[static 1]) should emit an error in the first
place though. The function definition should be compatible with s_destructor(S*
s).
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/110694] [11/12/13/14 Regression] False Positive -Werror=free-nonheap-object
2023-07-17 0:54 [Bug c/110694] New: False Positive -Werror=free-nonheap-object biggs at biggs dot xyz
@ 2023-07-17 0:59 ` pinskia at gcc dot gnu.org
2023-11-01 19:07 ` roman.zilka at gmail dot com
2024-03-07 23:28 ` law at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-17 0:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110694
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Target Milestone|--- |11.5
Known to fail| |11.1.0
Status|UNCONFIRMED |NEW
Known to work| |10.5.0
Last reconfirmed| |2023-07-17
Summary|False Positive |[11/12/13/14 Regression]
|-Werror=free-nonheap-object |False Positive
| |-Werror=free-nonheap-object
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/110694] [11/12/13/14 Regression] False Positive -Werror=free-nonheap-object
2023-07-17 0:54 [Bug c/110694] New: False Positive -Werror=free-nonheap-object biggs at biggs dot xyz
2023-07-17 0:59 ` [Bug middle-end/110694] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-11-01 19:07 ` roman.zilka at gmail dot com
2024-03-07 23:28 ` law at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: roman.zilka at gmail dot com @ 2023-11-01 19:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110694
Roman Žilka <roman.zilka at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |roman.zilka at gmail dot com
--- Comment #2 from Roman Žilka <roman.zilka at gmail dot com> ---
I can see it on 13.2.1 20230826. The warning triggers even without any -W*
args. The manpage implies that shouldn't be the case.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/110694] [11/12/13/14 Regression] False Positive -Werror=free-nonheap-object
2023-07-17 0:54 [Bug c/110694] New: False Positive -Werror=free-nonheap-object biggs at biggs dot xyz
2023-07-17 0:59 ` [Bug middle-end/110694] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-11-01 19:07 ` roman.zilka at gmail dot com
@ 2024-03-07 23:28 ` law at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-07 23:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110694
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |law at gcc dot gnu.org
Priority|P3 |P2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-07 23:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-17 0:54 [Bug c/110694] New: False Positive -Werror=free-nonheap-object biggs at biggs dot xyz
2023-07-17 0:59 ` [Bug middle-end/110694] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-11-01 19:07 ` roman.zilka at gmail dot com
2024-03-07 23:28 ` law 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).