[llvm-commits] [ASan/tests] Replace __attribute__((noinline)) and a bunch of other stuff portable (issue 5882058)

timurrrr at google.com timurrrr at google.com
Fri Mar 23 05:33:21 PDT 2012


Reviewers: glider,

Message:
Hi Alexander,

Can you please review this simple patch?
FYI, the #ifdef'ed parts were copied from asan_internal.h

Thanks,
Timur



Please review this at http://codereview.appspot.com/5882058/

Affected files:
   M     tests/asan_test.cc
   M     tests/asan_test_utils.h


Index: tests/asan_test.cc
===================================================================
--- tests/asan_test.cc	(revision 153332)
+++ tests/asan_test.cc	(working copy)
@@ -67,12 +67,12 @@
  const size_t kLargeMalloc = 1 << 24;

  template<class T>
-__attribute__((noinline))
+NOINLINE
  void asan_write(T *a) {
    *a = 0;
  }

-__attribute__((noinline))
+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);
@@ -81,44 +81,44 @@
    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))
+NOINLINE
    void free_ccc(void *p) { free(p); break_optimization(0);}
-__attribute__((noinline))
+NOINLINE
    void free_bbb(void *p) { free_ccc(p); break_optimization(0);}
-__attribute__((noinline))
+NOINLINE
    void free_aaa(void *p) { free_bbb(p); break_optimization(0);}

  template<class T>
-__attribute__((noinline))
+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",
@@ -129,7 +129,7 @@


  template<class T>
-__attribute__((noinline))
+NOINLINE
  void uaf_test(int size, int off) {
    char *p = (char *)malloc_aaa(size);
    free_aaa(p);
@@ -576,7 +576,7 @@
  }

  template<int kSize>
-__attribute__((noinline))
+NOINLINE
  void SizedStackTest() {
    char a[kSize];
    char  *A = Ident((char*)&a);
@@ -618,7 +618,7 @@
    EXPECT_DEATH(Ident(ZZZ)[-1] = 0, ASAN_PCRE_DOTALL "XXX.*YYY.*ZZZ");
  }

-__attribute__((noinline))
+NOINLINE
  static void Frame0(int frame, char *a, char *b, char *c) {
    char d[4] = {0};
    char *D = Ident(d);
@@ -629,15 +629,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,7 +655,7 @@
    EXPECT_DEATH(Frame3(3), "located .*in frame <.*Frame3");
  }

-__attribute__((noinline))
+NOINLINE
  void LongJmpFunc1(jmp_buf buf) {
    // create three red zones for these two stack objects.
    int a;
@@ -667,7 +667,7 @@
    longjmp(buf, 1);
  }

-__attribute__((noinline))
+NOINLINE
  void UnderscopeLongJmpFunc1(jmp_buf buf) {
    // create three red zones for these two stack objects.
    int a;
@@ -679,7 +679,7 @@
    _longjmp(buf, 1);
  }

-__attribute__((noinline))
+NOINLINE
  void SigLongJmpFunc1(sigjmp_buf buf) {
    // create three red zones for these two stack objects.
    int a;
@@ -692,7 +692,7 @@
  }


-__attribute__((noinline))
+NOINLINE
  void TouchStackFunc() {
    int a[100];  // long array will intersect with redzones from  
LongJmpFunc1.
    int *A = Ident(a);
@@ -729,7 +729,7 @@
  }

  #ifdef __EXCEPTIONS
-__attribute__((noinline))
+NOINLINE
  void ThrowFunc() {
    // create three red zones for these two stack objects.
    int a;
@@ -1403,7 +1403,7 @@
  // TODO(samsonov): Add a test with malloc(0)
  // TODO(samsonov): Add tests for str* and mem* functions.

-__attribute__((noinline))
+NOINLINE
  static int LargeFunction(bool do_bad_access) {
    int *x = new int[100];
    x[0]++;
@@ -1501,7 +1501,7 @@
  #endif  // ASAN_NEEDS_SEGV

  extern "C" {
-__attribute__((noinline))
+NOINLINE
  static void UseThenFreeThenUse() {
    char *x = Ident((char*)malloc(8));
    *x = 1;
@@ -1605,7 +1605,7 @@
  #endif

  template <int kSize>
-__attribute__((noinline))
+NOINLINE
  static void FuncWithStack() {
    char x[kSize];
    Ident(x)[0] = 0;
@@ -1659,7 +1659,7 @@
  }

  #ifdef __EXCEPTIONS
-__attribute__((noinline))
+NOINLINE
  static void StackReuseAndException() {
    int large_stack[1000];
    Ident(large_stack);
Index: tests/asan_test_utils.h
===================================================================
--- tests/asan_test_utils.h	(revision 153332)
+++ tests/asan_test_utils.h	(working copy)
@@ -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