I would like to propose Valgrind integration previously sent as RFC for trunk.
Arsen and Sam, since you commented on the RFC I wonder if you can have a look at the proposed configure and documentation changes and let me know if they look fine for you? For reference, gccinstall.info will say: ‘--enable-valgrind-interop’ Provide wrappers for Valgrind client requests in libgcc, which are used for ‘-fvalgrind-annotations’. Requires Valgrind header files for the target (in the build-time sysroot if building a cross-compiler). and GCC manual will document the new option as: -fvalgrind-annotations Emit Valgrind client requests annotating object lifetime boundaries. This allows to detect attempts to access fields of a C++ object after its destructor has completed (but storage was not deallocated yet), or to initialize it in advance from "operator new" rather than the constructor. This instrumentation relies on presence of "__gcc_vgmc_make_mem_undefined" function that wraps the corresponding Valgrind client request. It is provided by libgcc when it is configured with --enable-valgrind-interop. Otherwise, you can implement it like this: #include <valgrind/memcheck.h> void __gcc_vgmc_make_mem_undefined (void *addr, size_t size) { VALGRIND_MAKE_MEM_UNDEFINED (addr, size); } Changes since the RFC: * Add documentation and tests. * Drop 'emit-' from -fvalgrind-emit-annotations. * Use --enable-valgrind-interop instead of overloading --enable-valgrind-annotations. * Do not build the wrapper unless --enable-valgrind-interop is given and Valgrind headers are present. * Clean up libgcc configure changes. * Reword comments. Daniil Frolov (1): object lifetime instrumentation for Valgrind [PR66487] gcc/Makefile.in | 1 + gcc/builtins.def | 3 + gcc/common.opt | 4 + gcc/doc/install.texi | 5 + gcc/doc/invoke.texi | 27 +++++ gcc/gimple-valgrind-interop.cc | 112 ++++++++++++++++++ gcc/passes.def | 1 + gcc/testsuite/g++.dg/valgrind-annotations-1.C | 22 ++++ gcc/testsuite/g++.dg/valgrind-annotations-2.C | 12 ++ gcc/tree-pass.h | 1 + libgcc/Makefile.in | 3 + libgcc/config.in | 6 + libgcc/configure | 22 +++- libgcc/configure.ac | 15 ++- libgcc/libgcc2.h | 2 + libgcc/valgrind-interop.c | 40 +++++++ 16 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 gcc/gimple-valgrind-interop.cc create mode 100644 gcc/testsuite/g++.dg/valgrind-annotations-1.C create mode 100644 gcc/testsuite/g++.dg/valgrind-annotations-2.C create mode 100644 libgcc/valgrind-interop.c -- 2.39.2