[compiler-rt] [compiler-rt][asan] _aligned_malloc/_aligned_free interception. (PR #82049)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 12:12:52 PST 2024
================
@@ -0,0 +1,25 @@
+// RUN: %clang_cl_asan %Od %s %Fe%t
+// RUN: %run %t
+
+#include <windows.h>
+
+#define CHECK_ALIGNED(ptr, alignment) \
+ do { \
+ if (((uintptr_t)(ptr) % (alignment)) != 0) \
+ return __LINE__; \
+ } while (0)
+
+int main(void) {
+ char *p = reinterpret_cast<char *>(_aligned_malloc(16, 8));
+ CHECK_ALIGNED(p, 8);
+ char *n = reinterpret_cast<char *>(_aligned_realloc(32, 16));
+ CHECK_ALIGNED(n, 16);
+ _aligned_free(n);
+ p = reinterpret_cast<char *>(_aligned_malloc(128, 8));
+ CHECK_ALIGNED(p, 8);
+ p[-1] = 'a';
+ // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
----------------
zmodem wrote:
There needs to be a FileCheck invocation on the RUN line for the CHECKs to get checked.
Also, can we update compiler-rt/test/asan/TestCases/Windows/aligned_mallocs.cpp instead of adding a new one?
https://github.com/llvm/llvm-project/pull/82049
More information about the llvm-commits
mailing list