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.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
5// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
6// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
7// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cpp -o %t && %env_asan_opts=check_initialization_order=true:report_globals=3 %run %t 2>&1 | FileCheck %s --implicit-check-not "DynInitPoison"
8
9// Simple access:
10// Make sure that accessing a global in the same TU is safe
11
12bool condition = true;
13__attribute__((noinline, weak)) int initializeSameTU() {
14 return condition ? 0x2a : 052;
15}
16int sameTU = initializeSameTU();
17
18// Linker initialized:
19// Check that access to linker initialized globals originating from a different
20// TU's initializer is safe.
21
22int A = (1 << 1) + (1 << 3) + (1 << 5), B;
23int getAB() {
24 return A * B;
25}
26
27// Function local statics:
28// Check that access to function local statics originating from a different
29// TU's initializer is safe.
30
31int countCalls() {
32 static int calls;
33 return ++calls;
34}
35
36// Trivial constructor, non-trivial destructor.
37struct StructWithDtor {
38 ~StructWithDtor() { }
39 int value;
40};
41StructWithDtor struct_with_dtor;
42int getStructWithDtorValue() { return struct_with_dtor.value; }
43
44int main() { return 0; }
45
46// CHECK: DynInitPoison
47// CHECK: DynInitPoison
48
49// In general case entire set of DynInitPoison must be followed by at lest one
50// DynInitUnpoison. In some cases we can limit the number of DynInitUnpoison,
51// see initialization-nobug-lld.cpp.
52
53// CHECK: DynInitUnpoison
54

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of compiler-rt/test/asan/TestCases/initialization-nobug.cpp