llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Analysis: Possible regression/False Positive in GCC 14/15 compared to Clang regarding -Wfree-nonheap-object with std::vector

Open keeAzlynth opened this issue 7 months ago • 4 comments

Hello LLVM team,

  • I am encountering a confusing diagnostic issue while cross-testing my project with different compilers. I’ve noticed a persistent -Wfree-nonheap-object warning in GCC 14.2 and 15.2 (trunk) when compiling at -O3, whereas Clang 18/19 handles the same code perfectly without any warnings. I suspect this might be a false positive in GCC's escape analysis during aggressive inlining, but I am having difficulty reporting this to the GCC team due to registration restrictions on their Bugzilla platform. I am sharing this here hoping to get some insights from the experts who work on compiler diagnostics and optimization, or perhaps someone who has access to GCC's tracker could help bridge this report.

The Issue:

When using std::vector::reserve followed by multiple inlined push_back calls, GCC's analyzer seems to lose track of the vector's base pointer at -O3, incorrectly claiming that operator delete is called on a pointer with a non-zero offset.

Comparison:

  • Clang 18/19 (-O3 -std=c++20 -Wall): Clean. No warnings.
  • GCC 14.2 / 15.2 (-O3 -std=c++20 -Wall): Throws warning: 'void operator delete(void*, std::size_t)' called on pointer '' with nonzero offset.

Godbolt Link:

GCC Clang

The code compiles successfully with GCC under both Debug mode and O2 optimization. I have not yet identified the underlying cause of this behavior, and I would greatly appreciate your assistance in helping me resolve this issue.

  • Thank you for your time and for the amazing work on LLVM!

keeAzlynth avatar Apr 17 '26 02:04 keeAzlynth

Appears to be a problem caused by a mid-level optimization error in gcc.

TPPPP72 avatar Apr 17 '26 02:04 TPPPP72

Appears to be a problem caused by a mid-level optimization error in gcc.

  • This stems from my side,and i actually have little understanding of it

keeAzlynth avatar Apr 17 '26 03:04 keeAzlynth

No longer reproducible with GCC trunk. I believe this is a bug of GCC and has been fixed.

frederick-vs-ja avatar Apr 17 '26 06:04 frederick-vs-ja

No longer reproducible with GCC trunk. I believe this is a bug of GCC and has been fixed.

Thanks for the update! I'm on GCC 14.2 right now and can't upgrade to trunk yet, but I plan to move to a newer version later on.

keeAzlynth avatar Apr 17 '26 07:04 keeAzlynth