[libcxx-commits] [libcxx] [llvm] [libc++] Honor __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ in libc++ (PR #168955)
Dan Blackwell via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 27 07:20:46 PST 2026
================
@@ -17,7 +17,32 @@
# pragma GCC system_header
#endif
-#if __has_feature(address_sanitizer)
+// Within libc++, _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS determines whether the containers should
+// provide ASAN container overflow checks. That setting attempts to honour ASAN's documented option
+// __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ which can be defined by users to disable container overflow
+// checks.
+//
+// However, since parts of some containers (e.g. std::string) are compiled separately into the built
+// library, there are caveats:
+// - __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ can't always be honoured, i.e. if the built library
+// was compiled with ASAN container checks, it's impossible to turn them off afterwards. We diagnose
+// this with an error to avoid the proliferation of invalid configurations that appear to work.
+//
+// - The container overflow checks themselves are not always available even when the user is compiling
+// with -fsanitize=address. If a container is compiled separately like std::string, it can't provide
+// container checks unless the separately compiled code was built with container checks enabled. These
+// containers need to also conditionalize whether they provide overflow checks on `_LIBCPP_INSTRUMENTED_WITH_ASAN`.
+#if __has_feature(address_sanitizer) && !defined(__SANITIZER_DISABLE_CONTAINER_OVERFLOW__)
+# define _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS 1
+#else
+# define _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS 0
+#endif
+
+#if _LIBCPP_INSTRUMENTED_WITH_ASAN && !_LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS
+# error "We can't disable ASAN container checks when libc++ has been built with these checks enabled"
----------------
DanBlackwell wrote:
NIT: should we be specifying what "these checks" are? I imagine this error might not appear anywhere near where these have been defined
https://github.com/llvm/llvm-project/pull/168955
More information about the libcxx-commits
mailing list