public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108187] New: False positive -Wfree-nonheap-object on impossible path with -O1
@ 2022-12-20 14:33 i.maximets at ovn dot org
  2022-12-21  7:53 ` [Bug tree-optimization/108187] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: i.maximets at ovn dot org @ 2022-12-20 14:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108187

            Bug ID: 108187
           Summary: False positive -Wfree-nonheap-object on impossible
                    path with -O1
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: i.maximets at ovn dot org
  Target Milestone: ---

Created attachment 54132
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54132&action=edit
Reproducer

This might be the same issue as 98753, but I'm not sure.

We're getting the following error while trying to build Open vSwitch
with AF_XDP support with GCC:

```
In file included from lib/netdev-linux-private.h:30,
                 from lib/netdev-afxdp.c:19:
In function ‘dp_packet_delete’,
    inlined from ‘dp_packet_delete’ at lib/dp-packet.h:246:1,
    inlined from ‘dp_packet_batch_add__’ at lib/dp-packet.h:775:9,
    inlined from ‘dp_packet_batch_add’ at lib/dp-packet.h:783:5,
    inlined from ‘netdev_afxdp_rxq_recv’ at lib/netdev-afxdp.c:898:9:
lib/dp-packet.h:260:9: warning: ‘free’ called on pointer ‘*umem.xpool.array’
with nonzero offset [8, 2558044588346441168] [-Wfree-nonheap-object]
  260 |         free(b);
      |         ^~~~~~~

```

The simplified code flow is following:

```
packet = &umem->xpool.array[index];
packet = &xpacket->packet;
dp_packet_use_afxdp(packet, pkt, FRAME_SIZE - FRAME_HEADROOM,
OVS_XDP_HEADROOM);
--> dp_packet_init__(packet, allocated, DPBUF_AFXDP);
    --> packet->source = source;
dp_packet_batch_add(batch, packet);
--> dp_packet_delete(packet);
    --> if (b->source == DPBUF_AFXDP) {
            free_afxdp_buf(b);
            return;
        }
        dp_packet_uninit(b);
        free(b);

```

The 'b->source' is always set unconditionally to DPBUF_AFXDP on that path,
so the free(b) cannot be reached, but compiler doesn't think so.
The issue is seen starting with -O1.

$ gcc --version
gcc (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)

Attached the file in question after -E.  To reproduce run:

$ gcc -O1 -c netdev-afxdp.E.c

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-21 18:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20 14:33 [Bug c/108187] New: False positive -Wfree-nonheap-object on impossible path with -O1 i.maximets at ovn dot org
2022-12-21  7:53 ` [Bug tree-optimization/108187] " rguenth at gcc dot gnu.org
2022-12-21 10:44 ` i.maximets at ovn dot org
2022-12-21 11:51 ` i.maximets at ovn dot org
2022-12-21 18:05 ` 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).