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

            Bug ID: 116893
           Summary: -fipa-cp-clone breaks mismatched-dealloc diagnostic
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: a1ba.omarov at gmail dot com
  Target Milestone: ---

Created attachment 59224
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59224&action=edit
-save-temps output from GCC 13.2

I've been adding `__attribute__((malloc(deallocator, ptr-index))))` to my
library. As it allows users to pass custom alloc/free function and malloc
attribute can only be applied to functions, I added simple wrappers and applied
this attribute to them.

However, when I turned `-O3`, it caused `-Wmismatched-dealloc` to trigger on
seemingly valid code. After checking each flag that turns on `-O3` level, I
figured out that it's caused by `-fipa-cp-clone`. My assumption is that GCC
performs cloning on the wrapper function, and it breaks alloc-free link set by
malloc attribute. Forcibly setting `__attribute__((noclone))` on the function
helps to avoid the issue.

Minimal reproducible example: https://godbolt.org/z/rnoGfKrY4

Locally I only have GCC 13.2 installed, therefore attached -save-temps output
is from 13.2, but on link above reported GCC version is
"(Compiler-Explorer-Build-gcc-74a0ff6c2c680b8b4554af80f55361af58e6fb1b-binutils-2.42)
15.0.0 20240929 (experimental)".

Reply via email to