[asan] Fix asan_new_delete.cpp C++ header resolution under -nostdinc++ (#202816)

The COMPILER_RT_ASAN_ENABLE_EXCEPTIONS gate in asan/CMakeLists.txt
enables -fexceptions on the C++ slice (RTAsan_cxx /
RTAsan_dynamic_cxx — asan_new_delete.cpp) and tries to expose C++
standard headers to that TU (for forthcoming std::bad_alloc support)
by stripping -nostdinc++ from its cflags. The strip works for native
standalone builds but is wrong for cross builds: the host C++ headers
aren't valid for the target.

Split the C++-slice flag handling into two paths inside the existing
EXCEPTIONS gate:

  * In-tree libc++ available (TARGET cxx-headers OR HAVE_LIBCXX):
    keep -nostdinc++, append ${COMPILER_RT_CXX_CFLAGS} (a generator
    expression that expands to "-isystem <prepared cxx-headers dir>"),
    and add cxx-headers to DEPS so the header tree is staged before
    the compile. Mirrors the pattern in orc / fuzzer / memprof /
    tsan / xray.

  * No in-tree libc++ (typical standalone build): drop -nostdinc++
for the C++ slice TU only so the host toolchain supplies C++ headers.

Reject COMPILER_RT_CXX_LIBRARY=none +
COMPILER_RT_ASAN_ENABLE_EXCEPTIONS=ON
at configure time: that combination opts out of any C++ stdlib while
asking for an exception-enabled C++ slice, silently leaking host headers
into a `none`-mode build.

Assisted by: Claude Opus 4.7

GitOrigin-RevId: c5c33597bfdba185a6f8d04c0330e386a2e52abf
1 file changed