[PATCH] [compiler-rt] Fix gc-test.cc to work under higher -O levels

Kuba Brecka kuba.brecka at gmail.com
Sat Feb 21 02:25:16 PST 2015


Based on the failure from http://reviews.llvm.org/D7741.  The gc-test.cc currently tests various accesses (underflows and overflows) to a local array and asserts that they are contained in the same stack, something like:

	char var[15];
	for (int i = -32; i < 15; i++) {
		void *stack_A = __asan_addr_is_in_fake_stack(&var[0]);
		void *stack_B = __asan_addr_is_in_fake_stack(&var[i]);
		assert(stack_A == stack_B);
	}

However, on i386, the left redzone is not 32 bytes, it’s only 16 bytes and therefore the access to var[-32] is completely off.  The reason why this test didn’t fail before is that we’ve been lucky and there was another variable before the var array, which was also instrumented.  This fix uses “-32” for 64-bit systems and “-16” for 32-bit.

http://reviews.llvm.org/D7809

Files:
  test/asan/TestCases/gc-test.cc

Index: test/asan/TestCases/gc-test.cc
===================================================================
--- test/asan/TestCases/gc-test.cc
+++ test/asan/TestCases/gc-test.cc
@@ -1,14 +1,18 @@
 // RUN: %clangxx_asan %s -pthread -o %t
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: %clangxx_asan -O3 %s -pthread -o %t
+// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
 // REQUIRES: stable-runtime
 
 #include <assert.h>
 #include <stdio.h>
 #include <pthread.h>
 #include <sanitizer/asan_interface.h>
 
 static const int kNumThreads = 2;
+static const int kLeftRedzoneSize = sizeof(void *) * 4;
 
 void *Thread(void *unused)  {
   void *fake_stack = __asan_get_current_fake_stack();
@@ -23,7 +27,7 @@
     assert(real_stack);
     assert((char*)beg <= (char*)&var[0]);
     assert((char*)end > (char*)&var[0]);
-    for (int i = -32; i < 15; i++) {
+    for (int i = -kLeftRedzoneSize; i < 15; i++) {
       void *beg1, *end1;
       char *ptr = &var[0] + i;
       void *real_stack1 =

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7809.20459.patch
Type: text/x-patch
Size: 1331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150221/c3030259/attachment.bin>


More information about the llvm-commits mailing list