Avoid polluting user asan configs with ADDRESS_SANITIZE defines

This leverages Abseil's portable ASAN detection, relies primarily on __SANITIZE_ADDRESS__, which is set by gcc and msvc.  It falls back to __has_feature for clang.

PiperOrigin-RevId: 930262427
diff --git a/bazel/setup_configs.sh b/bazel/setup_configs.sh
index 8a6524b..5903a59 100755
--- a/bazel/setup_configs.sh
+++ b/bazel/setup_configs.sh
@@ -42,11 +42,6 @@
 build:asan --linkopt=-fsanitize=address
 build:asan --copt=-fsanitize=address
 
-# We rely on the following flag instead of the compiler provided
-# __has_feature(address_sanitizer) to know that we have an ASAN build even in
-# the uninstrumented runtime.
-build:asan --copt=-DADDRESS_SANITIZER
-
 EOF
 
 cat <<EOF
diff --git a/centipede/BUILD b/centipede/BUILD
index f16df04..66cef09 100644
--- a/centipede/BUILD
+++ b/centipede/BUILD
@@ -1430,6 +1430,7 @@
     deps = [
         ":rusage_stats",
         ":thread_pool",
+        "@abseil-cpp//absl/base:config",
         "@abseil-cpp//absl/base:nullability",
         "@abseil-cpp//absl/flags:flag",
         "@abseil-cpp//absl/synchronization",
@@ -1467,6 +1468,7 @@
     deps = [
         ":rusage_profiler",
         ":rusage_stats",
+        "@abseil-cpp//absl/base:config",
         "@abseil-cpp//absl/flags:flag",
         "@abseil-cpp//absl/time",
         "@com_google_fuzztest//common:logging",
diff --git a/centipede/rusage_profiler_test.cc b/centipede/rusage_profiler_test.cc
index 1ad46eb..803093d 100644
--- a/centipede/rusage_profiler_test.cc
+++ b/centipede/rusage_profiler_test.cc
@@ -22,6 +22,7 @@
 #include <string_view>
 
 #include "gtest/gtest.h"
+#include "absl/base/config.h"
 #include "absl/flags/flag.h"
 #include "absl/time/clock.h"
 #include "absl/time/time.h"
@@ -106,7 +107,7 @@
 // and skews the test's memory measurements. 2) The test allocates large
 // memory blocks to fight small number volatility of the system allocator, but
 // MSAN's custom allocator can't cope and intermittently OOMs.
-#if !defined(MEMORY_SANITIZER)
+#if !defined(ABSL_HAVE_MEMORY_SANITIZER)
 // Compare RUsageProfiler's manually taken snapshots against raw RUsageTiming
 // and RUsageMemory numbers acquired approximately at the same time.
 // "Approximately the same" is still not *the same*, so some discrepancies are
@@ -168,8 +169,9 @@
   // well as the delta timing partially determined by it, from validation.
   // 2) All *SANs slow down execution, so skip timing checks under them.
   // However, still run RUsageProfiler under them to catch any respective bugs.
-#if !defined(MEMORY_SANITIZER) && !defined(ADDRESS_SANITIZER) && \
-    !defined(THREAD_SANITIZER)
+#if !defined(ABSL_HAVE_MEMORY_SANITIZER) &&  \
+    !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
+    !defined(ABSL_HAVE_THREAD_SANITIZER)
   // EXPECT_SYS_TIMING_NEAR(before_snapshot.timing, before_timing);
   EXPECT_SYS_TIMING_NEAR(after_snapshot.timing, after_timing);
   // EXPECT_SYS_TIMING_NEAR(after_snapshot.delta_timing, delta_timing);
@@ -202,8 +204,9 @@
 
   // NOTE: The sanitizers heavily instrument the code and skew any time
   //  measurements.
-#if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \
-    !defined(MEMORY_SANITIZER)
+#if !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
+    !defined(ABSL_HAVE_THREAD_SANITIZER) &&  \
+    !defined(ABSL_HAVE_MEMORY_SANITIZER)
   const auto& snapshots = rprof.GetSnapshots();
   ASSERT_NEAR(snapshots.size(), absl::FDivDuration(kWasteTime, kInterval), 1);
   for (int i = 1; i < snapshots.size(); ++i) {
diff --git a/centipede/rusage_stats_test.cc b/centipede/rusage_stats_test.cc
index 7f5e058..2a0e008 100644
--- a/centipede/rusage_stats_test.cc
+++ b/centipede/rusage_stats_test.cc
@@ -21,6 +21,7 @@
 #include <vector>
 
 #include "gtest/gtest.h"
+#include "absl/base/config.h"
 #include "absl/base/nullability.h"
 #include "absl/flags/flag.h"
 #include "absl/synchronization/barrier.h"
@@ -266,8 +267,9 @@
 
 // NOTE: The sanitizers heavily instrument the code and skew any time
 //  measurements.
-#if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \
-    !defined(MEMORY_SANITIZER)
+#if !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
+    !defined(ABSL_HAVE_THREAD_SANITIZER) &&  \
+    !defined(ABSL_HAVE_MEMORY_SANITIZER)
     EXPECT_EQ(delta.mem_rss, after.mem_rss - before.mem_rss);
     EXPECT_EQ(delta.mem_data, after.mem_data - before.mem_data);
     // VPeak can only grow. VSize may grow to fit BigThing or fit it as-is.
@@ -293,8 +295,9 @@
 
 // NOTE: The sanitizers heavily instrument the code and skew any time
 //  measurements.
-#if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \
-    !defined(MEMORY_SANITIZER)
+#if !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
+    !defined(ABSL_HAVE_THREAD_SANITIZER) &&  \
+    !defined(ABSL_HAVE_MEMORY_SANITIZER)
   EXPECT_NEAR(mem_rss_histo.Average(), kBytes, kRssLeeway) << mem_rss_histo;
 #ifdef __APPLE__
   // `data` is not supported.
diff --git a/cmake/FuzzTestFlagSetup.cmake b/cmake/FuzzTestFlagSetup.cmake
index ac6a24a..e900b92 100644
--- a/cmake/FuzzTestFlagSetup.cmake
+++ b/cmake/FuzzTestFlagSetup.cmake
@@ -23,7 +23,7 @@
     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=fuzzer-no-link -DFUZZTEST_COMPATIBILITY_MODE")
   endif ()
   if (FUZZTEST_FUZZING_MODE OR (FUZZTEST_COMPATIBILITY_MODE STREQUAL "libfuzzer"))
-    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp -fsanitize=address -DADDRESS_SANITIZER")
-    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp -fsanitize=address -DADDRESS_SANITIZER")
+    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp -fsanitize=address")
+    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp -fsanitize=address")
   endif ()
 endmacro ()
diff --git a/doc/quickstart-cmake.md b/doc/quickstart-cmake.md
index e7f4a70..1479f6a 100644
--- a/doc/quickstart-cmake.md
+++ b/doc/quickstart-cmake.md
@@ -33,7 +33,7 @@
 
 *   `-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -UNDEBUG`
 *   `-fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp`
-*   `-fsanitize=address -DADDRESS_SANITIZER` (optionally enabling sanitizer)
+*   `-fsanitize=address` (optionally enabling sanitizer)
 
 The FuzzTest framework doesn't need to be built with these flags, only the target project.
 
@@ -233,18 +233,18 @@
 INFO: libFuzzer ignores flags that start with '--'
 INFO: Running with entropic power schedule (0xFF, 100).
 INFO: Seed: 1109364873
-INFO: Loaded 1 modules   (18692 inline 8-bit counters): 18692 [0x55edfe975548, 0x55edfe979e4c), 
-INFO: Loaded 1 PC tables (18692 PCs): 18692 [0x55edfe979e50,0x55edfe9c2e90), 
+INFO: Loaded 1 modules   (18692 inline 8-bit counters): 18692 [0x55edfe975548, 0x55edfe979e4c),
+INFO: Loaded 1 PC tables (18692 PCs): 18692 [0x55edfe979e50,0x55edfe9c2e90),
 INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
 INFO: A corpus is not provided, starting from an empty corpus
-#2	INITED cov: 17 ft: 18 corp: 1/1b exec/s: 0 rss: 38Mb
-#3	NEW    cov: 104 ft: 108 corp: 2/66b lim: 4096 exec/s: 0 rss: 38Mb L: 65/65 MS: 1 Custom-
-#4	NEW    cov: 105 ft: 112 corp: 3/121b lim: 4096 exec/s: 0 rss: 38Mb L: 55/65 MS: 1 Custom-
-#5	NEW    cov: 105 ft: 113 corp: 4/196b lim: 4096 exec/s: 0 rss: 38Mb L: 75/75 MS: 1 Custom-
-#16	REDUCE cov: 105 ft: 113 corp: 4/195b lim: 4096 exec/s: 0 rss: 38Mb L: 54/75 MS: 1 Custom-
-#41	NEW    cov: 105 ft: 114 corp: 5/247b lim: 4096 exec/s: 0 rss: 38Mb L: 52/75 MS: 5 Custom-Custom-Custom-Custom-Custom-
-#65	NEW    cov: 106 ft: 115 corp: 6/312b lim: 4096 exec/s: 0 rss: 38Mb L: 65/75 MS: 4 Custom-Custom-Custom-Custom-
-#69	NEW    cov: 108 ft: 119 corp: 7/365b lim: 4096 exec/s: 0 rss: 38Mb L: 53/75 MS: 4 Custom-Custom-Custom-Custom-
+#2  INITED cov: 17 ft: 18 corp: 1/1b exec/s: 0 rss: 38Mb
+#3  NEW    cov: 104 ft: 108 corp: 2/66b lim: 4096 exec/s: 0 rss: 38Mb L: 65/65 MS: 1 Custom-
+#4  NEW    cov: 105 ft: 112 corp: 3/121b lim: 4096 exec/s: 0 rss: 38Mb L: 55/65 MS: 1 Custom-
+#5  NEW    cov: 105 ft: 113 corp: 4/196b lim: 4096 exec/s: 0 rss: 38Mb L: 75/75 MS: 1 Custom-
+#16 REDUCE cov: 105 ft: 113 corp: 4/195b lim: 4096 exec/s: 0 rss: 38Mb L: 54/75 MS: 1 Custom-
+#41 NEW    cov: 105 ft: 114 corp: 5/247b lim: 4096 exec/s: 0 rss: 38Mb L: 52/75 MS: 5 Custom-Custom-Custom-Custom-Custom-
+#65 NEW    cov: 106 ft: 115 corp: 6/312b lim: 4096 exec/s: 0 rss: 38Mb L: 65/75 MS: 4 Custom-Custom-Custom-Custom-
+#69 NEW    cov: 108 ft: 119 corp: 7/365b lim: 4096 exec/s: 0 rss: 38Mb L: 53/75 MS: 4 Custom-Custom-Custom-Custom-
 ```
 
 ## Next steps
diff --git a/e2e_tests/BUILD b/e2e_tests/BUILD
index fc0e23f..2edd62c 100644
--- a/e2e_tests/BUILD
+++ b/e2e_tests/BUILD
@@ -63,6 +63,7 @@
     ],
     deps = [
         ":test_binary_util",
+        "@abseil-cpp//absl/base:config",
         "@abseil-cpp//absl/container:flat_hash_map",
         "@abseil-cpp//absl/strings",
         "@abseil-cpp//absl/strings:str_format",
diff --git a/e2e_tests/functional_test.cc b/e2e_tests/functional_test.cc
index 6133473..f9d3696 100644
--- a/e2e_tests/functional_test.cc
+++ b/e2e_tests/functional_test.cc
@@ -26,6 +26,7 @@
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include "absl/base/config.h"
 #include "absl/container/flat_hash_map.h"
 #include "absl/strings/str_cat.h"
 #include "absl/strings/str_format.h"
@@ -1603,7 +1604,7 @@
 
 TEST_P(FuzzingModeCrashFindingTest,
        BufferOverflowIsDetectedWithStringViewInFuzzingMode) {
-#ifndef ADDRESS_SANITIZER
+#ifndef ABSL_HAVE_ADDRESS_SANITIZER
   GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
 #endif
   auto [status, std_out, std_err] = Run("MySuite.BufferOverreadWithStringView");
@@ -1616,7 +1617,7 @@
 
 TEST_P(FuzzingModeCrashFindingTest,
        UninitializedReadIsDetectedWithStringInFuzzingMode) {
-#ifndef MEMORY_SANITIZER
+#ifndef ABSL_HAVE_MEMORY_SANITIZER
   GTEST_SKIP() << "Skipping crash finding test for MSAN errors without MSAN";
 #endif
   auto [status, std_out, std_err] = Run("MySuite.UninitializedReadWithString");
@@ -1639,7 +1640,7 @@
 
 TEST_P(FuzzingModeCrashFindingTest,
        BufferOverflowIsDetectedWithStringInFuzzingMode) {
-#ifndef ADDRESS_SANITIZER
+#ifndef ABSL_HAVE_ADDRESS_SANITIZER
   GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
 #endif
   auto [status, std_out, std_err] = Run("MySuite.BufferOverreadWithString");
@@ -1650,7 +1651,7 @@
 
 TEST_P(FuzzingModeCrashFindingTest,
        BufferOverflowIsDetectedWithStringAndLvalueStringViewRef) {
-#ifndef ADDRESS_SANITIZER
+#ifndef ABSL_HAVE_ADDRESS_SANITIZER
   GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
 #endif
   auto [status, std_out, std_err] =
@@ -1662,7 +1663,7 @@
 
 TEST_P(FuzzingModeCrashFindingTest,
        BufferOverflowIsDetectedWithStringAndRvalueStringViewRef) {
-#ifndef ADDRESS_SANITIZER
+#ifndef ABSL_HAVE_ADDRESS_SANITIZER
   GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
 #endif
   auto [status, std_out, std_err] =
@@ -1675,7 +1676,7 @@
 TEST_P(FuzzingModeCrashFindingTest, DivByZeroTestFindsAbortInFuzzingMode) {
   auto [status, std_out, std_err] = Run("MySuite.DivByZero");
   EXPECT_THAT_LOG(std_err, HasSubstr("argument 1: 0"));
-#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER)
+#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || defined(ABSL_HAVE_MEMORY_SANITIZER)
   EXPECT_THAT(status, Ne(ExitCode(0))) << std_err;
 #else
   EXPECT_THAT(status, Eq(Signal(SIGFPE))) << std_err;
@@ -1996,7 +1997,7 @@
 }
 
 TEST_P(FuzzingModeCrashFindingTest, AsanCrashMetadataIsDumpedIfEnvVarIsSet) {
-#ifndef ADDRESS_SANITIZER
+#ifndef ABSL_HAVE_ADDRESS_SANITIZER
   GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
 #endif
   TempDir out_dir;
diff --git a/fuzztest/internal/BUILD b/fuzztest/internal/BUILD
index f515591..c2a2cea 100644
--- a/fuzztest/internal/BUILD
+++ b/fuzztest/internal/BUILD
@@ -405,6 +405,7 @@
         ":seed_seq",
         ":serialization",
         ":status",
+        "@abseil-cpp//absl/base:config",
         "@abseil-cpp//absl/base:core_headers",
         "@abseil-cpp//absl/functional:any_invocable",
         "@abseil-cpp//absl/functional:bind_front",
diff --git a/fuzztest/internal/runtime.cc b/fuzztest/internal/runtime.cc
index f03dbaf..79ea2ff 100644
--- a/fuzztest/internal/runtime.cc
+++ b/fuzztest/internal/runtime.cc
@@ -38,6 +38,7 @@
 #include <utility>
 #include <vector>
 
+#include "absl/base/config.h"
 #include "absl/functional/bind_front.h"
 #include "absl/functional/function_ref.h"
 #include "absl/random/bit_gen_ref.h"
@@ -71,7 +72,7 @@
 #include "./fuzztest/internal/serialization.h"
 #include "./fuzztest/internal/status.h"
 
-#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER)
+#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || defined(ABSL_HAVE_MEMORY_SANITIZER)
 #define FUZZTEST_HAS_SANITIZER
 #include <sanitizer/common_interface_defs.h>