public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/102934] New: missing warning passing address of first member to free() Date: Mon, 25 Oct 2021 17:19:59 +0000 [thread overview] Message-ID: <bug-102934-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102934 Bug ID: 102934 Summary: missing warning passing address of first member to free() Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC diagnoses the first invalid call to free() below but fails to diagnose the second. The problem is due to the warning using Object Size Type 0 (whole objects) rather than 1 (subobjects) to determine the identity of the object being freed. $ cat z.c && gcc -O2 -S -Wall z.c struct A { int i, a[2]; }; void f (struct A *p) { __builtin_free (p->a); // -Wfree-nonheap-object (good) } struct B { int a[2], j; }; void g (struct B *p) { __builtin_free (p->a); // missing warning } z.c: In function ‘f’: z.c:5:3: warning: ‘__builtin_free’ called on pointer ‘p’ with nonzero offset 4 [-Wfree-nonheap-object] 5 | __builtin_free (p->a); // -Wfree-nonheap-object (good) | ^~~~~~~~~~~~~~~~~~~~~
next reply other threads:[~2021-10-25 17:19 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-25 17:19 msebor at gcc dot gnu.org [this message] 2021-10-25 17:20 ` [Bug middle-end/102934] " msebor at gcc dot gnu.org 2021-10-26 7:07 ` rguenth at gcc dot gnu.org 2022-01-26 17:19 ` msebor at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102934-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).