From 12e3b80a1311379957a419f8a7c24df01c8b6c36 Mon Sep 17 00:00:00 2001 From: Hyxogen <8938732+Hyxogen@users.noreply.github.com> Date: Wed, 24 Jan 2024 09:24:51 +0100 Subject: [PATCH] asan: properly run asan test The test was meant to crash by heap-buffer-overflow. However, the test only checked if the program crashed, not what caused it. Because there are no program arguments (yet) it would always crash through nullptr deref, making the test falsely pass. --- .../test/asan/TestCases/heap-overflow-large.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler-rt/test/asan/TestCases/heap-overflow-large.cpp b/compiler-rt/test/asan/TestCases/heap-overflow-large.cpp index 566b1158a5da..244417904a75 100644 --- a/compiler-rt/test/asan/TestCases/heap-overflow-large.cpp +++ b/compiler-rt/test/asan/TestCases/heap-overflow-large.cpp @@ -1,10 +1,13 @@ // Regression test for // https://code.google.com/p/address-sanitizer/issues/detail?id=183 -// RUN: %clangxx_asan -O2 %s -o %t -// RUN: not %run %t 12 2>&1 | FileCheck %s -// RUN: not %run %t 100 2>&1 | FileCheck %s -// RUN: not %run %t 10000 2>&1 | FileCheck %s +// RUN: %clangxx_asan -DOFFSET=12 -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -DOFFSET=1000 -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -DOFFSET=100000 -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s + +// RUN: %clangxx_asan -cheerp-linear-output=asmjs -DOFFSET=12 -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -cheerp-linear-output=asmjs -DOFFSET=1000 -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -cheerp-linear-output=asmjs -DOFFSET=100000 -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s #include #include @@ -14,8 +17,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "main\n"); int *x = new int[5]; memset(x, 0, sizeof(x[0]) * 5); - int index = atoi(argv[1]); - unsigned res = x[index]; + unsigned res = x[OFFSET]; // CHECK: main // CHECK-NOT: CHECK failed delete[] x;