Fixes bogus Pointer Analysis with C++ delete calls
Correctly handles C++ delete expressions in Pointer Analysis (PTA) to avoid incorrect aliasing information.
This commit corrects an error in GCC’s Pointer Analysis (PTA) that incorrectly ignored delete calls originating from C++ delete expressions. A previous change intended to simplify pointer analysis by eliding new/delete pairs globally was too broad. This fix restores the original behavior, only ignoring calls to the standard library’s delete, and adds a check for the -fassume-sane-operators-new-delete flag. This ensures that PTA accurately reflects memory management, preventing potential bugs related to aliasing.
In Details
This patch corrects an overzealous change in gimple-ssa-pta-constraints.cc's find_func_aliases_for_call. Previously, all delete calls were being ignored for PTA constraints, based on r11-3612-g4f4ced28826ece which aimed to simplify new/delete elision. The fix reinstates the original restriction: only ignore calls to the standard library's operator delete when DECL_IS_REPLACEABLE_OPERATOR is true. This reverts a bug introduced by a too-broad interpretation of the new/delete elision improvements, ensuring PTA constraints are correctly generated for user-defined delete operators.
- Pointer Analysis (PTA)
- A compiler technique that determines which memory locations a pointer might refer to. Accurate PTA is crucial for many optimizations, including alias analysis, dead code elimination, and memory safety checks.
- C++ delete expression
- In C++, a statement that deallocates memory previously allocated with
new. This can involve calling a destructors followed by deallocating the memory itself, potentially involving customoperator deletefunctions. - aliasing
- In programming, aliasing occurs when two or more different names (e.g., pointers or variables) refer to the same memory location. Compiler optimizations often depend on knowing whether different memory accesses might alias.
- g++
- The GNU C++ compiler, part of the GNU Compiler Collection (GCC).
- operator delete
- A C++ special function that deallocates memory, typically called after a
newexpression to free the allocated memory. It can be overloaded by users.