[llvm-commits] [compiler-rt] r153333 - in /compiler-rt/trunk/lib/asan/tests: asan_test.cc asan_test_utils.h

Timur Iskhodzhanov timurrrr at google.com
Fri Mar 23 06:10:59 PDT 2012


Author: timurrrr
Date: Fri Mar 23 08:10:59 2012
New Revision: 153333

URL: http://llvm.org/viewvc/llvm-project?rev=153333&view=rev
Log:
[ASan/tests] Make 'noinline' and a bunch of other stuff portable

Modified:
    compiler-rt/trunk/lib/asan/tests/asan_test.cc
    compiler-rt/trunk/lib/asan/tests/asan_test_utils.h

Modified: compiler-rt/trunk/lib/asan/tests/asan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test.cc?rev=153333&r1=153332&r2=153333&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_test.cc Fri Mar 23 08:10:59 2012
@@ -67,13 +67,11 @@
 const size_t kLargeMalloc = 1 << 24;
 
 template<class T>
-__attribute__((noinline))
-void asan_write(T *a) {
+NOINLINE void asan_write(T *a) {
   *a = 0;
 }
 
-__attribute__((noinline))
-void asan_write_sized_aligned(uint8_t *p, size_t size) {
+NOINLINE void asan_write_sized_aligned(uint8_t *p, size_t size) {
   EXPECT_EQ(0, ((uintptr_t)p % size));
   if      (size == 1) asan_write((uint8_t*)p);
   else if (size == 2) asan_write((uint16_t*)p);
@@ -81,45 +79,41 @@
   else if (size == 8) asan_write((uint64_t*)p);
 }
 
-__attribute__((noinline)) void *malloc_fff(size_t size) {
+NOINLINE void *malloc_fff(size_t size) {
   void *res = malloc/**/(size); break_optimization(0); return res;}
-__attribute__((noinline)) void *malloc_eee(size_t size) {
+NOINLINE void *malloc_eee(size_t size) {
   void *res = malloc_fff(size); break_optimization(0); return res;}
-__attribute__((noinline)) void *malloc_ddd(size_t size) {
+NOINLINE void *malloc_ddd(size_t size) {
   void *res = malloc_eee(size); break_optimization(0); return res;}
-__attribute__((noinline)) void *malloc_ccc(size_t size) {
+NOINLINE void *malloc_ccc(size_t size) {
   void *res = malloc_ddd(size); break_optimization(0); return res;}
-__attribute__((noinline)) void *malloc_bbb(size_t size) {
+NOINLINE void *malloc_bbb(size_t size) {
   void *res = malloc_ccc(size); break_optimization(0); return res;}
-__attribute__((noinline)) void *malloc_aaa(size_t size) {
+NOINLINE void *malloc_aaa(size_t size) {
   void *res = malloc_bbb(size); break_optimization(0); return res;}
 
 #ifndef __APPLE__
-__attribute__((noinline)) void *memalign_fff(size_t alignment, size_t size) {
+NOINLINE void *memalign_fff(size_t alignment, size_t size) {
   void *res = memalign/**/(alignment, size); break_optimization(0); return res;}
-__attribute__((noinline)) void *memalign_eee(size_t alignment, size_t size) {
+NOINLINE void *memalign_eee(size_t alignment, size_t size) {
   void *res = memalign_fff(alignment, size); break_optimization(0); return res;}
-__attribute__((noinline)) void *memalign_ddd(size_t alignment, size_t size) {
+NOINLINE void *memalign_ddd(size_t alignment, size_t size) {
   void *res = memalign_eee(alignment, size); break_optimization(0); return res;}
-__attribute__((noinline)) void *memalign_ccc(size_t alignment, size_t size) {
+NOINLINE void *memalign_ccc(size_t alignment, size_t size) {
   void *res = memalign_ddd(alignment, size); break_optimization(0); return res;}
-__attribute__((noinline)) void *memalign_bbb(size_t alignment, size_t size) {
+NOINLINE void *memalign_bbb(size_t alignment, size_t size) {
   void *res = memalign_ccc(alignment, size); break_optimization(0); return res;}
-__attribute__((noinline)) void *memalign_aaa(size_t alignment, size_t size) {
+NOINLINE void *memalign_aaa(size_t alignment, size_t size) {
   void *res = memalign_bbb(alignment, size); break_optimization(0); return res;}
 #endif  // __APPLE__
 
 
-__attribute__((noinline))
-  void free_ccc(void *p) { free(p); break_optimization(0);}
-__attribute__((noinline))
-  void free_bbb(void *p) { free_ccc(p); break_optimization(0);}
-__attribute__((noinline))
-  void free_aaa(void *p) { free_bbb(p); break_optimization(0);}
+NOINLINE void free_ccc(void *p) { free(p); break_optimization(0);}
+NOINLINE void free_bbb(void *p) { free_ccc(p); break_optimization(0);}
+NOINLINE void free_aaa(void *p) { free_bbb(p); break_optimization(0);}
 
 template<class T>
-__attribute__((noinline))
-void oob_test(int size, int off) {
+NOINLINE void oob_test(int size, int off) {
   char *p = (char*)malloc_aaa(size);
   // fprintf(stderr, "writing %d byte(s) into [%p,%p) with offset %d\n",
   //        sizeof(T), p, p + size, off);
@@ -129,8 +123,7 @@
 
 
 template<class T>
-__attribute__((noinline))
-void uaf_test(int size, int off) {
+NOINLINE void uaf_test(int size, int off) {
   char *p = (char *)malloc_aaa(size);
   free_aaa(p);
   for (int i = 1; i < 100; i++)
@@ -576,8 +569,7 @@
 }
 
 template<int kSize>
-__attribute__((noinline))
-void SizedStackTest() {
+NOINLINE void SizedStackTest() {
   char a[kSize];
   char  *A = Ident((char*)&a);
   for (size_t i = 0; i < kSize; i++)
@@ -618,8 +610,7 @@
   EXPECT_DEATH(Ident(ZZZ)[-1] = 0, ASAN_PCRE_DOTALL "XXX.*YYY.*ZZZ");
 }
 
-__attribute__((noinline))
-static void Frame0(int frame, char *a, char *b, char *c) {
+NOINLINE static void Frame0(int frame, char *a, char *b, char *c) {
   char d[4] = {0};
   char *D = Ident(d);
   switch (frame) {
@@ -629,15 +620,15 @@
     case 0: D[5]++; break;
   }
 }
-__attribute__((noinline)) static void Frame1(int frame, char *a, char *b) {
+NOINLINE static void Frame1(int frame, char *a, char *b) {
   char c[4] = {0}; Frame0(frame, a, b, c);
   break_optimization(0);
 }
-__attribute__((noinline)) static void Frame2(int frame, char *a) {
+NOINLINE static void Frame2(int frame, char *a) {
   char b[4] = {0}; Frame1(frame, a, b);
   break_optimization(0);
 }
-__attribute__((noinline)) static void Frame3(int frame) {
+NOINLINE static void Frame3(int frame) {
   char a[4] = {0}; Frame2(frame, a);
   break_optimization(0);
 }
@@ -655,8 +646,7 @@
   EXPECT_DEATH(Frame3(3), "located .*in frame <.*Frame3");
 }
 
-__attribute__((noinline))
-void LongJmpFunc1(jmp_buf buf) {
+NOINLINE void LongJmpFunc1(jmp_buf buf) {
   // create three red zones for these two stack objects.
   int a;
   int b;
@@ -667,8 +657,7 @@
   longjmp(buf, 1);
 }
 
-__attribute__((noinline))
-void UnderscopeLongJmpFunc1(jmp_buf buf) {
+NOINLINE void UnderscopeLongJmpFunc1(jmp_buf buf) {
   // create three red zones for these two stack objects.
   int a;
   int b;
@@ -679,8 +668,7 @@
   _longjmp(buf, 1);
 }
 
-__attribute__((noinline))
-void SigLongJmpFunc1(sigjmp_buf buf) {
+NOINLINE void SigLongJmpFunc1(sigjmp_buf buf) {
   // create three red zones for these two stack objects.
   int a;
   int b;
@@ -692,8 +680,7 @@
 }
 
 
-__attribute__((noinline))
-void TouchStackFunc() {
+NOINLINE void TouchStackFunc() {
   int a[100];  // long array will intersect with redzones from LongJmpFunc1.
   int *A = Ident(a);
   for (int i = 0; i < 100; i++)
@@ -729,8 +716,7 @@
 }
 
 #ifdef __EXCEPTIONS
-__attribute__((noinline))
-void ThrowFunc() {
+NOINLINE void ThrowFunc() {
   // create three red zones for these two stack objects.
   int a;
   int b;
@@ -1403,8 +1389,7 @@
 // TODO(samsonov): Add a test with malloc(0)
 // TODO(samsonov): Add tests for str* and mem* functions.
 
-__attribute__((noinline))
-static int LargeFunction(bool do_bad_access) {
+NOINLINE static int LargeFunction(bool do_bad_access) {
   int *x = new int[100];
   x[0]++;
   x[1]++;
@@ -1501,8 +1486,7 @@
 #endif  // ASAN_NEEDS_SEGV
 
 extern "C" {
-__attribute__((noinline))
-static void UseThenFreeThenUse() {
+NOINLINE static void UseThenFreeThenUse() {
   char *x = Ident((char*)malloc(8));
   *x = 1;
   free_aaa(x);
@@ -1605,8 +1589,7 @@
 #endif
 
 template <int kSize>
-__attribute__((noinline))
-static void FuncWithStack() {
+NOINLINE static void FuncWithStack() {
   char x[kSize];
   Ident(x)[0] = 0;
   Ident(x)[kSize-1] = 0;
@@ -1659,8 +1642,7 @@
 }
 
 #ifdef __EXCEPTIONS
-__attribute__((noinline))
-static void StackReuseAndException() {
+NOINLINE static void StackReuseAndException() {
   int large_stack[1000];
   Ident(large_stack);
   ASAN_THROW(1);

Modified: compiler-rt/trunk/lib/asan/tests/asan_test_utils.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test_utils.h?rev=153333&r1=153332&r2=153333&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_test_utils.h (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_test_utils.h Fri Mar 23 08:10:59 2012
@@ -14,13 +14,39 @@
 #ifndef ASAN_TEST_UTILS_H
 #define ASAN_TEST_UTILS_H
 
+#if defined(_WIN32)
+typedef unsigned __int8  uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+typedef __int8           int8_t;
+typedef __int16          int16_t;
+typedef __int32          int32_t;
+typedef __int64          int64_t;
+# define NOINLINE __declspec(noinline)
+#else  // defined(_WIN32)
+# define NOINLINE __attribute__((noinline))
+#endif  // defined(_WIN32)
+
+#if !defined(__has_feature)
+#define __has_feature(x) 0
+#endif
+
+#ifndef __WORDSIZE
+#if __LP64__ || defined(_WIN64)
+#define __WORDSIZE 64
+#else
+#define __WORDSIZE 32
+#endif
+#endif
+
 // Make the compiler think that something is going on there.
 extern "C" void break_optimization(void *);
 
 // This function returns its parameter but in such a way that compiler
 // can not prove it.
 template<class T>
-__attribute__((noinline))
+NOINLINE
 static T Ident(T t) {
   T ret = t;
   break_optimization(&ret);





More information about the llvm-commits mailing list