// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -std=c++17 -emit-llvm -DIMPORT=1 -fmodules %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IMPORT,CHECK-NO-NS,CHECK-IMPORT-NO-NS --implicit-check-not=unused
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -std=c++17 -emit-llvm -DIMPORT=1 -DNS -fmodules %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IMPORT,CHECK-NS,CHECK-IMPORT-NS --implicit-check-not=unused
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -std=c++17 -emit-llvm -DIMPORT=2 -fmodules %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NO-NS --implicit-check-not=unused
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -std=c++17 -emit-llvm -DIMPORT=2 -DNS -fmodules %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NS --implicit-check-not=unused
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -std=c++17 -emit-llvm -fmodules %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NO-NS --implicit-check-not=unused
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -std=c++17 -emit-llvm -DNS -fmodules %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NS --implicit-check-not=unused
// Check that we behave sensibly when importing a header containing strong and
// weak, ordered and unordered global initializers.
//
// Our behavior is as follows:
//
// -- for variables with one or more specific points of initialization
// (non-template variables, whether or not they are inline or thread_local),
// emit them if (and only if) a header containing a point of initialization
// is transitively #included / imported.
//
// -- for variables with unordered initialization (any kind of templated
// variable -- excluding explicit specializations), emit them if any part
// of any module that triggers an instantiation is imported.
//
// The intent is to:
//
// 1) preserve order of initialization guarantees
// 2) preserve the behavior of globals with ctors in headers, and specifically
// of std::ios_base::Init (do not run the iostreams initializer nor force
// linking in the iostreams portion of the static library unless <iostream>
// is included)
// 3) behave conservatively-correctly with regard to unordered initializers: we
// might run them in cases where a traditional compilation would not, but
// will never fail to run them in cases where a traditional compilation
// would do so
//
// Perfect handling of unordered initializers would require tracking all
// submodules containing points of instantiation, which is very hard when those
// points of instantiation are within definitions that we skip because we
// already have a (non-visible) definition for the entity:
//
// // a.h
// template<typename> int v = f();
// inline int get() { return v<int>; }
//
// // b.h
// template<typename> int v = f();
// inline int get() { return v<int>; }
//
// If a.h and b.h are built as a module, we will only have a point of
// instantiation for v<int> in one of the two headers, because we will only
// parse one of the two get() functions.
module m
inline int