Home | History | Annotate | Download | only in TestCases
      1 // A collection of various initializers which shouldn't trip up initialization
      2 // order checking.  If successful, this will just return 0.
      3 
      4 // RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-nobug-extra.cc -fsanitize=init-order -o %t
      5 // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
      6 // RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cc -fsanitize=init-order -o %t
      7 // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
      8 // RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cc -fsanitize=init-order -o %t
      9 // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
     10 // RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cc -fsanitize=init-order -o %t
     11 // RUN: ASAN_OPTIONS=check_initialization_order=true %t 2>&1
     12 
     13 // Simple access:
     14 // Make sure that accessing a global in the same TU is safe
     15 
     16 bool condition = true;
     17 int initializeSameTU() {
     18   return condition ? 0x2a : 052;
     19 }
     20 int sameTU = initializeSameTU();
     21 
     22 // Linker initialized:
     23 // Check that access to linker initialized globals originating from a different
     24 // TU's initializer is safe.
     25 
     26 int A = (1 << 1) + (1 << 3) + (1 << 5), B;
     27 int getAB() {
     28   return A * B;
     29 }
     30 
     31 // Function local statics:
     32 // Check that access to function local statics originating from a different
     33 // TU's initializer is safe.
     34 
     35 int countCalls() {
     36   static int calls;
     37   return ++calls;
     38 }
     39 
     40 // Trivial constructor, non-trivial destructor.
     41 struct StructWithDtor {
     42   ~StructWithDtor() { }
     43   int value;
     44 };
     45 StructWithDtor struct_with_dtor;
     46 int getStructWithDtorValue() { return struct_with_dtor.value; }
     47 
     48 int main() { return 0; }
     49