[compiler-rt] [asan][test] Fix Posix/new_array_cookie_with_new_from_class.cpp to work for arm targets (PR #208378)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 22:20:08 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Ian Anderson (ian-twilightcoder)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/208378.diff


1 Files Affected:

- (modified) compiler-rt/test/asan/TestCases/Posix/new_array_cookie_with_new_from_class.cpp (+8-3) 


``````````diff
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..da7e99681bbf5 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,8 +1,6 @@
 // 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
 
@@ -11,6 +9,13 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <assert.h>
+
+#if defined(__arm__) || defined(__arm64__)
+static const size_t kArrayCookieSize = 2 * sizeof(void *);
+#else
+static const 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 +39,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;
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/208378


More information about the llvm-commits mailing list