[compiler-rt] [asan][test] Fix Posix/new_array_cookie_with_new_from_class.cpp to work for arm targets (PR #208378)
Ian Anderson via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 00:56:22 PDT 2026
https://github.com/ian-twilightcoder updated https://github.com/llvm/llvm-project/pull/208378
>From 571274a4924ef8270bbe3ca5881d219fa0ab9cf2 Mon Sep 17 00:00:00 2001
From: Ian Anderson <iana at apple.com>
Date: Wed, 8 Jul 2026 22:12:23 -0700
Subject: [PATCH] [asan][test] Fix
Posix/new_array_cookie_with_new_from_class.cpp to work for arm targets
arm targets and arm64 targets on Darwin use a 2-pointer array cookie size. Update the test to support that.
Assisted-by: Claude Code
rdar://181775880
---
.../Posix/new_array_cookie_with_new_from_class.cpp | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/compiler-rt/test/asan/TestCases/Posix/new_array_cookie_with_new_from_class.cpp b/compiler-rt/test/asan/TestCases/Posix/new_array_cookie_with_new_from_class.cpp
index 23d65100f96a8..d7e04268b779e 100644
--- a/compiler-rt/test/asan/TestCases/Posix/new_array_cookie_with_new_from_class.cpp
+++ b/compiler-rt/test/asan/TestCases/Posix/new_array_cookie_with_new_from_class.cpp
@@ -1,16 +1,19 @@
// Test that we do not poison the array cookie if the operator new is defined
// inside the class.
// RUN: %clangxx_asan %s -o %t && %run %t
-//
-// XFAIL: target=arm{{.*}}
-
-// UNSUPPORTED: darwin-remote
#include <new>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
+
+#if defined(__arm__) || defined(__arm64__)
+constexpr size_t kArrayCookieSize = 2 * sizeof(void *);
+#else
+constexpr size_t kArrayCookieSize = sizeof(void *);
+#endif
+
struct Foo {
void *operator new(size_t s) { return Allocate(s); }
void *operator new[] (size_t s) { return Allocate(s); }
@@ -34,7 +37,7 @@ int main() {
fprintf(stderr, "foo : %p\n", foo);
fprintf(stderr, "alloc: %p\n", Foo::allocated);
assert(reinterpret_cast<uintptr_t>(foo) ==
- reinterpret_cast<uintptr_t>(Foo::allocated) + sizeof(void*));
+ reinterpret_cast<uintptr_t>(Foo::allocated) + kArrayCookieSize);
*reinterpret_cast<uintptr_t*>(Foo::allocated) = 42;
return 0;
}
More information about the llvm-commits
mailing list