[compiler-rt] [ASan][Windows] Honor asan config flags on windows when set through the user function (PR #122990)
David Justo via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 24 17:19:15 PST 2025
https://github.com/davidmrdavid updated https://github.com/llvm/llvm-project/pull/122990
>From f5b0f9657e71477b9ee178dbefca65009d6a9922 Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Tue, 14 Jan 2025 16:10:48 -0800
Subject: [PATCH 01/10] honor asan config flags on windows when set through the
user function
---
compiler-rt/lib/asan/asan_allocator.cpp | 12 +++++-
compiler-rt/lib/asan/asan_allocator.h | 1 +
compiler-rt/lib/asan/asan_flags.cpp | 23 +++++------
compiler-rt/lib/asan/asan_internal.h | 1 +
compiler-rt/lib/asan/asan_rtl.cpp | 54 ++++++++++++++++++++-----
5 files changed, 66 insertions(+), 25 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index 9e66f77217ec6b..cf041d0a62fc20 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -423,10 +423,15 @@ struct Allocator {
PoisonShadow(chunk, allocated_size, kAsanHeapLeftRedzoneMagic);
}
- void ReInitialize(const AllocatorOptions &options) {
+ // Apply provided AllocatorOptions to an Allocator
+ void ApplyOptions(const AllocatorOptions &options) {
SetAllocatorMayReturnNull(options.may_return_null);
allocator.SetReleaseToOSIntervalMs(options.release_to_os_interval_ms);
SharedInitCode(options);
+ }
+
+ void ReInitialize(const AllocatorOptions &options) {
+ ApplyOptions(options);
// Poison all existing allocation's redzones.
if (CanPoisonMemory()) {
@@ -975,6 +980,11 @@ void ReInitializeAllocator(const AllocatorOptions &options) {
instance.ReInitialize(options);
}
+// Apply provided AllocatorOptions to an Allocator
+void ApplyAllocatorOptions(const AllocatorOptions &options) {
+ instance.ApplyOptions(options);
+}
+
void GetAllocatorOptions(AllocatorOptions *options) {
instance.GetOptions(options);
}
diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h
index db8dc3bebfc620..a94ef958aa75ec 100644
--- a/compiler-rt/lib/asan/asan_allocator.h
+++ b/compiler-rt/lib/asan/asan_allocator.h
@@ -47,6 +47,7 @@ struct AllocatorOptions {
void InitializeAllocator(const AllocatorOptions &options);
void ReInitializeAllocator(const AllocatorOptions &options);
void GetAllocatorOptions(AllocatorOptions *options);
+void ApplyAllocatorOptions(const AllocatorOptions &options);
class AsanChunkView {
public:
diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp
index 9cfb70bd00c786..9be2273998e40a 100644
--- a/compiler-rt/lib/asan/asan_flags.cpp
+++ b/compiler-rt/lib/asan/asan_flags.cpp
@@ -144,7 +144,8 @@ static void InitializeDefaultFlags() {
DisplayHelpMessages(&asan_parser);
}
-static void ProcessFlags() {
+// Validate flags and report incompatible configurations
+static void ValidateFlags()s() {
Flags *f = flags();
// Flag validation:
@@ -214,11 +215,11 @@ static void ProcessFlags() {
void InitializeFlags() {
InitializeDefaultFlags();
- ProcessFlags();
+ ValidateFlags();
#if SANITIZER_WINDOWS
- // On Windows, weak symbols are emulated by having the user program
- // register which weak functions are defined.
+ // On Windows, weak symbols (such as the `__asan_default_options` function)
+ // are emulated by having the user program register which weak functions are defined.
// The ASAN DLL will initialize flags prior to user module initialization,
// so __asan_default_options will not point to the user definition yet.
// We still want to ensure we capture when options are passed via
@@ -239,14 +240,8 @@ void InitializeFlags() {
asan_parser.ParseString(__asan_default_options());
DisplayHelpMessages(&asan_parser);
- ProcessFlags();
-
- // TODO: Update other globals and data structures that may need to change
- // after initialization due to new flags potentially being set changing after
- // `__asan_default_options` is registered.
- // See GH issue 'https://github.com/llvm/llvm-project/issues/117925' for
- // details.
- SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
+ ValidateFlags();
+ ApplyFlags();
});
# if CAN_SANITIZE_UB
@@ -259,7 +254,7 @@ void InitializeFlags() {
ubsan_parser.ParseString(__ubsan_default_options());
// To match normal behavior, do not print UBSan help.
- ProcessFlags();
+ ValidateFlags();
});
# endif
@@ -273,7 +268,7 @@ void InitializeFlags() {
lsan_parser.ParseString(__lsan_default_options());
// To match normal behavior, do not print LSan help.
- ProcessFlags();
+ ValidateFlags();
});
# endif
diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h
index 06dfc4b1773397..464faad56f32d1 100644
--- a/compiler-rt/lib/asan/asan_internal.h
+++ b/compiler-rt/lib/asan/asan_internal.h
@@ -61,6 +61,7 @@ using __sanitizer::StackTrace;
void AsanInitFromRtl();
bool TryAsanInitFromRtl();
+void ApplyFlags();
// asan_win.cpp
void InitializePlatformExceptionHandlers();
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp
index 19c6c210b564c5..65c40d8bf8b13d 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -390,6 +390,39 @@ void PrintAddressSpaceLayout() {
kHighShadowBeg > kMidMemEnd);
}
+// Apply most options specified either through the ASAN_OPTIONS
+// environment variable, or through the `__asan_default_options` user function.
+//
+// This function may be called multiple times, once per weak reference callback on
+// Windows, so it needs to be idempotent.
+//
+// Context:
+// For maximum compatibility on Windows, it is necessary for ASan options to be
+// configured/registered/applied inside this method (instead of in ASanInitInternal,
+// for example). That's because, on Windows, the user-provided definition for `__asan_default_opts`
+// may not be bound when `ASanInitInternal` is invoked (it is bound later).
+//
+// To work around the late binding on windows, `ApplyOptions` will be called, again,
+// after binding to the user-provided `__asan_default_opts` function. Therefore,
+// any flags not configured here are not guaranteed to be configurable
+// through `__asan_default_opts` on Windows.
+//
+//
+// For more details on this issue, see: https://github.com/llvm/llvm-project/issues/117925
+void ApplyFlags() {
+ SetCanPoisonMemory(flags()->poison_heap);
+ SetMallocContextSize(common_flags()->malloc_context_size);
+
+ __sanitizer_set_report_path(common_flags()->log_path);
+
+ __asan_option_detect_stack_use_after_return =
+ flags()->detect_stack_use_after_return;
+
+ AllocatorOptions allocator_options;
+ allocator_options.SetFrom(flags(), common_flags());
+ ApplyAllocatorOptions(allocator_options);
+}
+
static bool AsanInitInternal() {
if (LIKELY(AsanInited()))
return true;
@@ -397,10 +430,13 @@ static bool AsanInitInternal() {
CacheBinaryName();
- // Initialize flags. This must be done early, because most of the
- // initialization steps look at flags().
+ // Initialize flags and register weak function callbacks for windows.
+ // This must be done early, because most of the initialization steps look at flags().
InitializeFlags();
+ // NOTE: The sleep before/after init` flags will not work on Windows when set through
+ // `__asan_default_options`, because that function is not guaranteed to be bound
+ // this early in initialization.
WaitForDebugger(flags()->sleep_before_init, "before init");
// Stop performing init at this point if we are being loaded via
@@ -416,9 +452,6 @@ static bool AsanInitInternal() {
AsanCheckDynamicRTPrereqs();
AvoidCVE_2016_2143();
- SetCanPoisonMemory(flags()->poison_heap);
- SetMallocContextSize(common_flags()->malloc_context_size);
-
InitializePlatformExceptionHandlers();
InitializeHighMemEnd();
@@ -428,11 +461,6 @@ static bool AsanInitInternal() {
SetCheckUnwindCallback(CheckUnwind);
SetPrintfAndReportCallback(AppendToErrorMessageBuffer);
- __sanitizer_set_report_path(common_flags()->log_path);
-
- __asan_option_detect_stack_use_after_return =
- flags()->detect_stack_use_after_return;
-
__sanitizer::InitializePlatformEarly();
// Setup internal allocator callback.
@@ -460,6 +488,12 @@ static bool AsanInitInternal() {
allocator_options.SetFrom(flags(), common_flags());
InitializeAllocator(allocator_options);
+ // Apply ASan flags.
+ // NOTE: In order for options specified through `__asan_default_options` to be honored on Windows,
+ // it is necessary for those options to be configured inside the `ApplyOptions` method.
+ // See the function-level comment for `ApplyFlags` for more details.
+ ApplyFlags();
+
if (SANITIZER_START_BACKGROUND_THREAD_IN_ASAN_INTERNAL)
MaybeStartBackgroudThread();
>From 4674c0e0ef6984573e560debaae0415f2f8c7c0f Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Tue, 14 Jan 2025 17:51:13 -0800
Subject: [PATCH 02/10] run: git-clang-format
---
compiler-rt/lib/asan/asan_flags.cpp | 11 ++++----
compiler-rt/lib/asan/asan_rtl.cpp | 39 ++++++++++++++++-------------
2 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp
index 9be2273998e40a..14eac16e8e53f4 100644
--- a/compiler-rt/lib/asan/asan_flags.cpp
+++ b/compiler-rt/lib/asan/asan_flags.cpp
@@ -145,7 +145,7 @@ static void InitializeDefaultFlags() {
}
// Validate flags and report incompatible configurations
-static void ValidateFlags()s() {
+static void ValidateFlags() {
Flags *f = flags();
// Flag validation:
@@ -219,10 +219,11 @@ void InitializeFlags() {
#if SANITIZER_WINDOWS
// On Windows, weak symbols (such as the `__asan_default_options` function)
- // are emulated by having the user program register which weak functions are defined.
- // The ASAN DLL will initialize flags prior to user module initialization,
- // so __asan_default_options will not point to the user definition yet.
- // We still want to ensure we capture when options are passed via
+ // are emulated by having the user program register which weak functions are
+ // defined. The ASAN DLL will initialize flags prior to user module
+ // initialization, so __asan_default_options will not point to the user
+ // definition yet. We still want to ensure we capture when options are passed
+ // via
// __asan_default_options, so we add a callback to be run
// when it is registered with the runtime.
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp
index 65c40d8bf8b13d..54c90403426a22 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -393,22 +393,24 @@ void PrintAddressSpaceLayout() {
// Apply most options specified either through the ASAN_OPTIONS
// environment variable, or through the `__asan_default_options` user function.
//
-// This function may be called multiple times, once per weak reference callback on
-// Windows, so it needs to be idempotent.
+// This function may be called multiple times, once per weak reference callback
+// on Windows, so it needs to be idempotent.
//
// Context:
// For maximum compatibility on Windows, it is necessary for ASan options to be
-// configured/registered/applied inside this method (instead of in ASanInitInternal,
-// for example). That's because, on Windows, the user-provided definition for `__asan_default_opts`
-// may not be bound when `ASanInitInternal` is invoked (it is bound later).
+// configured/registered/applied inside this method (instead of in
+// ASanInitInternal, for example). That's because, on Windows, the user-provided
+// definition for `__asan_default_opts` may not be bound when `ASanInitInternal`
+// is invoked (it is bound later).
//
-// To work around the late binding on windows, `ApplyOptions` will be called, again,
-// after binding to the user-provided `__asan_default_opts` function. Therefore,
-// any flags not configured here are not guaranteed to be configurable
-// through `__asan_default_opts` on Windows.
+// To work around the late binding on windows, `ApplyOptions` will be called,
+// again, after binding to the user-provided `__asan_default_opts` function.
+// Therefore, any flags not configured here are not guaranteed to be
+// configurable through `__asan_default_opts` on Windows.
//
//
-// For more details on this issue, see: https://github.com/llvm/llvm-project/issues/117925
+// For more details on this issue, see:
+// https://github.com/llvm/llvm-project/issues/117925
void ApplyFlags() {
SetCanPoisonMemory(flags()->poison_heap);
SetMallocContextSize(common_flags()->malloc_context_size);
@@ -431,12 +433,14 @@ static bool AsanInitInternal() {
CacheBinaryName();
// Initialize flags and register weak function callbacks for windows.
- // This must be done early, because most of the initialization steps look at flags().
+ // This must be done early, because most of the initialization steps look at
+ // flags().
InitializeFlags();
- // NOTE: The sleep before/after init` flags will not work on Windows when set through
- // `__asan_default_options`, because that function is not guaranteed to be bound
- // this early in initialization.
+ // NOTE: The sleep before/after init` flags will not work on Windows when set
+ // through
+ // `__asan_default_options`, because that function is not guaranteed to be
+ // bound this early in initialization.
WaitForDebugger(flags()->sleep_before_init, "before init");
// Stop performing init at this point if we are being loaded via
@@ -489,9 +493,10 @@ static bool AsanInitInternal() {
InitializeAllocator(allocator_options);
// Apply ASan flags.
- // NOTE: In order for options specified through `__asan_default_options` to be honored on Windows,
- // it is necessary for those options to be configured inside the `ApplyOptions` method.
- // See the function-level comment for `ApplyFlags` for more details.
+ // NOTE: In order for options specified through `__asan_default_options` to be
+ // honored on Windows, it is necessary for those options to be configured
+ // inside the `ApplyOptions` method. See the function-level comment for
+ // `ApplyFlags` for more details.
ApplyFlags();
if (SANITIZER_START_BACKGROUND_THREAD_IN_ASAN_INTERNAL)
>From d45c846c07946671a5b865bd0bbf54cd29707e95 Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Fri, 24 Jan 2025 15:51:27 -0800
Subject: [PATCH 03/10] undo renaming of ProcessFlags to ValidateFlags
---
compiler-rt/lib/asan/asan_flags.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp
index 14eac16e8e53f4..3b7d030e385525 100644
--- a/compiler-rt/lib/asan/asan_flags.cpp
+++ b/compiler-rt/lib/asan/asan_flags.cpp
@@ -145,7 +145,7 @@ static void InitializeDefaultFlags() {
}
// Validate flags and report incompatible configurations
-static void ValidateFlags() {
+static void ProcessFlags() {
Flags *f = flags();
// Flag validation:
@@ -215,7 +215,7 @@ static void ValidateFlags() {
void InitializeFlags() {
InitializeDefaultFlags();
- ValidateFlags();
+ ProcessFlags();
#if SANITIZER_WINDOWS
// On Windows, weak symbols (such as the `__asan_default_options` function)
@@ -241,7 +241,7 @@ void InitializeFlags() {
asan_parser.ParseString(__asan_default_options());
DisplayHelpMessages(&asan_parser);
- ValidateFlags();
+ ProcessFlags();
ApplyFlags();
});
@@ -255,7 +255,7 @@ void InitializeFlags() {
ubsan_parser.ParseString(__ubsan_default_options());
// To match normal behavior, do not print UBSan help.
- ValidateFlags();
+ ProcessFlags();
});
# endif
@@ -269,7 +269,7 @@ void InitializeFlags() {
lsan_parser.ParseString(__lsan_default_options());
// To match normal behavior, do not print LSan help.
- ValidateFlags();
+ ProcessFlags();
});
# endif
>From 0728fb856266af3ba3badb01a4b5c110b8170a0f Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Fri, 24 Jan 2025 15:54:24 -0800
Subject: [PATCH 04/10] agnostify comment
---
compiler-rt/lib/asan/asan_rtl.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp
index 54c90403426a22..33c019824dd4f2 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -432,7 +432,7 @@ static bool AsanInitInternal() {
CacheBinaryName();
- // Initialize flags and register weak function callbacks for windows.
+ // Initialize flags. On Windows it also also register weak function callbacks.
// This must be done early, because most of the initialization steps look at
// flags().
InitializeFlags();
>From ba740aa73d052e7e68ccdea1d9531bc71eaad53c Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Fri, 24 Jan 2025 15:54:59 -0800
Subject: [PATCH 05/10] remove irrelevant comment
---
compiler-rt/lib/asan/asan_rtl.cpp | 4 ----
1 file changed, 4 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp
index 33c019824dd4f2..a697cbd60ef158 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -437,10 +437,6 @@ static bool AsanInitInternal() {
// flags().
InitializeFlags();
- // NOTE: The sleep before/after init` flags will not work on Windows when set
- // through
- // `__asan_default_options`, because that function is not guaranteed to be
- // bound this early in initialization.
WaitForDebugger(flags()->sleep_before_init, "before init");
// Stop performing init at this point if we are being loaded via
>From 84027d68248093f1ecc806f2d5d89acddf19206e Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Fri, 24 Jan 2025 16:31:59 -0800
Subject: [PATCH 06/10] add test
---
.../asan/TestCases/alloc_dealloc_mismatch.cpp | 25 +++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 compiler-rt/test/asan/TestCases/alloc_dealloc_mismatch.cpp
diff --git a/compiler-rt/test/asan/TestCases/alloc_dealloc_mismatch.cpp b/compiler-rt/test/asan/TestCases/alloc_dealloc_mismatch.cpp
new file mode 100644
index 00000000000000..678d49b888fd0f
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/alloc_dealloc_mismatch.cpp
@@ -0,0 +1,25 @@
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH
+// RUN: %env_asan_opts=alloc_dealloc_mismatch=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUCCESS
+
+// RUN: %clangxx_asan -O0 %s -o %t -DUSER_FUNCTION
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH
+
+#if USER_FUNCTION
+// It's important to test the `alloc_dealloc_mismatch` flag set through the user function because, on Windows,
+// flags configured through the user-defined function `__asan_default_options` are not always be honored.
+// See: https://github.com/llvm/llvm-project/issues/117925
+extern "C" __declspec(dllexport) extern const char *__asan_default_options() {
+ return "alloc_dealloc_mismatch=1";
+}
+#endif
+
+#include <cstdio>
+#include <cstdlib>
+
+// Tests the `alloc_dealloc_mismatch` flag set both via user function and through the environment variable.
+int main() {
+ delete (new int[10]); // CHECK-MISMATCH: AddressSanitizer:
+ printf("Success"); // CHECK-SUCCESS: Success
+ return 0;
+}
>From a4c342a19a65acf64b0d922bd976d02d9962bed9 Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Fri, 24 Jan 2025 16:33:05 -0800
Subject: [PATCH 07/10] move test to windows directory
---
.../test/asan/TestCases/{ => Windows}/alloc_dealloc_mismatch.cpp | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename compiler-rt/test/asan/TestCases/{ => Windows}/alloc_dealloc_mismatch.cpp (100%)
diff --git a/compiler-rt/test/asan/TestCases/alloc_dealloc_mismatch.cpp b/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
similarity index 100%
rename from compiler-rt/test/asan/TestCases/alloc_dealloc_mismatch.cpp
rename to compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
>From 52bfccc70c3b160307e3ab62b380fdc9060e8f87 Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Fri, 24 Jan 2025 16:43:18 -0800
Subject: [PATCH 08/10] run: clang-format
---
.../test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp b/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
index 678d49b888fd0f..db2479978f886f 100644
--- a/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
@@ -20,6 +20,6 @@ extern "C" __declspec(dllexport) extern const char *__asan_default_options() {
// Tests the `alloc_dealloc_mismatch` flag set both via user function and through the environment variable.
int main() {
delete (new int[10]); // CHECK-MISMATCH: AddressSanitizer:
- printf("Success"); // CHECK-SUCCESS: Success
+ printf("Success"); // CHECK-SUCCESS: Success
return 0;
}
>From 450fec7c6c57606df8016acd1865753cec9c8618 Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Fri, 24 Jan 2025 17:08:37 -0800
Subject: [PATCH 09/10] run: clang-format
---
.../test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp b/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
index db2479978f886f..3e3d4c7acacf85 100644
--- a/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
@@ -3,7 +3,7 @@
// RUN: %env_asan_opts=alloc_dealloc_mismatch=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUCCESS
// RUN: %clangxx_asan -O0 %s -o %t -DUSER_FUNCTION
-// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUCCESS
#if USER_FUNCTION
// It's important to test the `alloc_dealloc_mismatch` flag set through the user function because, on Windows,
@@ -19,7 +19,8 @@ extern "C" __declspec(dllexport) extern const char *__asan_default_options() {
// Tests the `alloc_dealloc_mismatch` flag set both via user function and through the environment variable.
int main() {
+ // In the 'CHECK-MISMATCH' case, we simply check that the AddressSanitizer reports an error.
delete (new int[10]); // CHECK-MISMATCH: AddressSanitizer:
printf("Success"); // CHECK-SUCCESS: Success
return 0;
-}
+}
\ No newline at end of file
>From 20b4a5f99dcac0fe9da968f0b73b828003d7e098 Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Fri, 24 Jan 2025 17:18:59 -0800
Subject: [PATCH 10/10] fix wrong prefix
---
.../test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp b/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
index 3e3d4c7acacf85..c51416b661cc82 100644
--- a/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp
@@ -3,7 +3,7 @@
// RUN: %env_asan_opts=alloc_dealloc_mismatch=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUCCESS
// RUN: %clangxx_asan -O0 %s -o %t -DUSER_FUNCTION
-// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUCCESS
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH
#if USER_FUNCTION
// It's important to test the `alloc_dealloc_mismatch` flag set through the user function because, on Windows,
More information about the llvm-commits
mailing list