Home | History | Annotate | Download | only in lit_tests
      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 -m64 -O0 %s %p/Helpers/initialization-nobug-extra.cc\
      5 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
      6 // RUN: %clangxx_asan -m64 -O1 %s %p/Helpers/initialization-nobug-extra.cc\
      7 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
      8 // RUN: %clangxx_asan -m64 -O2 %s %p/Helpers/initialization-nobug-extra.cc\
      9 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
     10 // RUN: %clangxx_asan -m64 -O3 %s %p/Helpers/initialization-nobug-extra.cc\
     11 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
     12 // RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-nobug-extra.cc\
     13 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
     14 // RUN: %clangxx_asan -m32 -O0 %s %p/Helpers/initialization-nobug-extra.cc\
     15 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
     16 // RUN: %clangxx_asan -m32 -O1 %s %p/Helpers/initialization-nobug-extra.cc\
     17 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
     18 // RUN: %clangxx_asan -m32 -O2 %s %p/Helpers/initialization-nobug-extra.cc\
     19 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
     20 // RUN: %clangxx_asan -m32 -O3 %s %p/Helpers/initialization-nobug-extra.cc\
     21 // RUN:   --std=c++11 -mllvm -asan-initialization-order -o %t && %t 2>&1
     22 
     23 // Simple access:
     24 // Make sure that accessing a global in the same TU is safe
     25 
     26 bool condition = true;
     27 int initializeSameTU() {
     28   return condition ? 0x2a : 052;
     29 }
     30 int sameTU = initializeSameTU();
     31 
     32 // Linker initialized:
     33 // Check that access to linker initialized globals originating from a different
     34 // TU's initializer is safe.
     35 
     36 int A = (1 << 1) + (1 << 3) + (1 << 5), B;
     37 int getAB() {
     38   return A * B;
     39 }
     40 
     41 // Function local statics:
     42 // Check that access to function local statics originating from a different
     43 // TU's initializer is safe.
     44 
     45 int countCalls() {
     46   static int calls;
     47   return ++calls;
     48 }
     49 
     50 // Constexpr:
     51 // We need to check that a global variable initialized with a constexpr
     52 // constructor can be accessed during dynamic initialization (as a constexpr
     53 // constructor implies that it was initialized during constant initialization,
     54 // not dynamic initialization).
     55 
     56 class Integer {
     57   private:
     58   int value;
     59 
     60   public:
     61   constexpr Integer(int x = 0) : value(x) {}
     62   int getValue() {return value;}
     63 };
     64 Integer coolestInteger(42);
     65 int getCoolestInteger() { return coolestInteger.getValue(); }
     66 
     67 int main() { return 0; }
     68