Home | History | Annotate | Download | only in CodeGenCXX
      1 // Test -fsanitize-memory-use-after-dtor
      2 // RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
      3 // RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
      4 
      5 // 24 bytes total
      6 struct Packed {
      7   // Packed into 4 bytes
      8   unsigned int a : 1;
      9   unsigned int b : 1;
     10   //unsigned int c : 1;
     11   // Force alignment to next 4 bytes
     12   unsigned int   : 0;
     13   unsigned int d : 1;
     14   // Force alignment, 8 more bytes
     15   double e = 5.0;
     16   // 4 bytes
     17   unsigned int f : 1;
     18   ~Packed() {}
     19 };
     20 Packed p;
     21 
     22 
     23 // 1 byte total
     24 struct Empty {
     25   unsigned int : 0;
     26   ~Empty() {}
     27 };
     28 Empty e;
     29 
     30 
     31 // 4 byte total
     32 struct Simple {
     33   unsigned int a : 1;
     34   ~Simple() {}
     35 };
     36 Simple s;
     37 
     38 
     39 // 8 bytes total
     40 struct Anon {
     41   // 1 byte
     42   unsigned int a : 1;
     43   unsigned int b : 2;
     44   // Force alignment to next byte
     45   unsigned int   : 0;
     46   unsigned int c : 1;
     47   ~Anon() {}
     48 };
     49 Anon an;
     50 
     51 
     52 struct CharStruct {
     53   char c;
     54   ~CharStruct();
     55 };
     56 
     57 struct Adjacent {
     58   CharStruct a;
     59   int b : 1;
     60   CharStruct c;
     61   ~Adjacent() {}
     62 };
     63 Adjacent ad;
     64 
     65 
     66 // CHECK-LABEL: define {{.*}}PackedD2Ev
     67 // CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 17
     68 // CHECK: ret void
     69 
     70 // CHECK-LABEL: define {{.*}}EmptyD2Ev
     71 // CHECK-NOT: call void @__sanitizer_dtor_callback{{.*}}i64 0
     72 // CHECK: ret void
     73 
     74 // CHECK-LABEL: define {{.*}}SimpleD2Ev
     75 // CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 1
     76 // CHECK: ret void
     77 
     78 // CHECK-LABEL: define {{.*}}AnonD2Ev
     79 // CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 5
     80 // CHECK: ret void
     81 
     82 // CHECK-LABEL: define {{.*}}AdjacentD2Ev
     83 // CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 1
     84 // CHECK: ret void
     85