[asan][test] Fix `TestCases/alloca_*` ptr-to-long cast on Windows
authorAlvin Wong <alvin@alvinhc.com>
Thu, 30 Mar 2023 11:21:56 +0000 (19:21 +0800)
committerAlvin Wong <alvin@alvinhc.com>
Sat, 1 Apr 2023 17:06:15 +0000 (01:06 +0800)
64-bit Windows uses 32-bit long so these casts fail to compile with the
error "cast from pointer to smaller type". Change to instead use
uintptr_t like other tests.

Differential Revision: https://reviews.llvm.org/D147232

compiler-rt/test/asan/TestCases/alloca_big_alignment.cpp
compiler-rt/test/asan/TestCases/alloca_detect_custom_size_.cpp
compiler-rt/test/asan/TestCases/alloca_instruments_all_paddings.cpp
compiler-rt/test/asan/TestCases/alloca_overflow_partial.cpp
compiler-rt/test/asan/TestCases/alloca_overflow_right.cpp
compiler-rt/test/asan/TestCases/alloca_safe_access.cpp
compiler-rt/test/asan/TestCases/alloca_underflow_left.cpp

index 0b49424..a451e87 100644 (file)
@@ -3,10 +3,11 @@
 //
 
 #include <assert.h>
+#include <stdint.h>
 
 __attribute__((noinline)) void foo(int index, int len) {
   volatile char str[len] __attribute__((aligned(128)));
-  assert(!(reinterpret_cast<long>(str) & 127L));
+  assert(!(reinterpret_cast<uintptr_t>(str) & 127L));
   str[index] = '1'; // BOOM
 // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
 // CHECK: WRITE of size 1 at [[ADDR]] thread T0
index 271359b..8b207aa 100644 (file)
@@ -3,6 +3,7 @@
 //
 
 #include <assert.h>
+#include <stdint.h>
 
 struct A {
   char a[3];
@@ -11,7 +12,7 @@ struct A {
 
 __attribute__((noinline)) void foo(int index, int len) {
   volatile struct A str[len] __attribute__((aligned(32)));
-  assert(!(reinterpret_cast<long>(str) & 31L));
+  assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
   str[index].a[0] = '1'; // BOOM
 // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
 // CHECK: WRITE of size 1 at [[ADDR]] thread T0
index 5bf6f80..912c8b0 100644 (file)
@@ -5,10 +5,11 @@
 
 #include "sanitizer/asan_interface.h"
 #include <assert.h>
+#include <stdint.h>
 
 __attribute__((noinline)) void foo(int index, int len) {
   volatile char str[len] __attribute__((aligned(32)));
-  assert(!(reinterpret_cast<long>(str) & 31L));
+  assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
   char *q = (char *)__asan_region_is_poisoned((char *)str, 64);
   assert(q && ((q - str) == index));
 }
index afac40c..25c6d75 100644 (file)
@@ -3,10 +3,11 @@
 //
 
 #include <assert.h>
+#include <stdint.h>
 
 __attribute__((noinline)) void foo(int index, int len) {
   volatile char str[len] __attribute__((aligned(32)));
-  assert(!(reinterpret_cast<long>(str) & 31L));
+  assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
   str[index] = '1'; // BOOM
 // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
 // CHECK: WRITE of size 1 at [[ADDR]] thread T0
index 615dd14..7ec4b86 100644 (file)
@@ -3,10 +3,11 @@
 //
 
 #include <assert.h>
+#include <stdint.h>
 
 __attribute__((noinline)) void foo(int index, int len) {
   volatile char str[len] __attribute__((aligned(32)));
-  assert(!(reinterpret_cast<long>(str) & 31L));
+  assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
   str[index] = '1'; // BOOM
 // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
 // CHECK: WRITE of size 1 at [[ADDR]] thread T0
index 1cd0dad..98e3176 100644 (file)
@@ -3,10 +3,11 @@
 //
 
 #include <assert.h>
+#include <stdint.h>
 
 __attribute__((noinline)) void foo(int index, int len) {
   volatile char str[len] __attribute__((aligned(32)));
-  assert(!(reinterpret_cast<long>(str) & 31L));
+  assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
   str[index] = '1';
 }
 
index 8720e8c..52cd781 100644 (file)
@@ -3,10 +3,11 @@
 //
 
 #include <assert.h>
+#include <stdint.h>
 
 __attribute__((noinline)) void foo(int index, int len) {
   volatile char str[len] __attribute__((aligned(32)));
-  assert(!(reinterpret_cast<long>(str) & 31L));
+  assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
   str[index] = '1'; // BOOM
 // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
 // CHECK: WRITE of size 1 at [[ADDR]] thread T0