// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux -fblocks -emit-llvm -o - %s -std=c++1y | FileCheck %s
// CHECK: @"_ZZZNK17pr18020_constexpr3$_1clEvENKUlvE_clEvE2l2" =
// CHECK: internal global i32* @"_ZZNK17pr18020_constexpr3$_1clEvE2l1"
// CHECK: @_ZZL14deduced_returnvE1n = internal global i32 42
// CHECK: @_ZZZL20block_deduced_returnvEUb_E1n = internal global i32 42
// CHECK: @_ZZ18static_local_labelPvE1q = linkonce_odr global i8* blockaddress(@_Z18static_local_labelPv, %{{.*}})
// CHECK: @"_ZZNK3$_2clEvE1x" = internal global i32 42
// These tests all break the assumption that the static var decl has to be
// emitted before use of the var decl. This happens because we defer emission
// of variables with internal linkage and no initialization side effects, such
// as 'x'. Then we hit operator()() in 'f', and emit the callee before we emit
// the arguments, so we emit the innermost function first.
// CHECK-LABEL: define internal noundef i32 @"_ZZNK14pr18020_lambda3$_0clEvENKUlvE_clEv"
// CHECK: load i32, i32* @"_ZZNK14pr18020_lambda3$_0clEvE2l1"
// CHECK-LABEL: define internal noundef i32 @"_ZZNK17pr18020_constexpr3$_1clEvENKUlvE_clEv"
// CHECK: load i32*, i32** @"_ZZZNK17pr18020_constexpr3$_1clEvENKUlvE_clEvE2l2"
// Lambda-less reduction that references l1 before emitting it. This didn't
// crash if you put it in a namespace.
;
static pr18020_class x;
int
// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN13pr18020_classclEvEN1UclEv
// CHECK: load i32, i32* @_ZZN13pr18020_classclEvE2l1
// In this test case, the function containing the static local will not be
// emitted because it is unneeded. However, the operator call of the inner class
// is called, and the static local is referenced and must be emitted.
static auto
extern "C" int
// CHECK-LABEL: define{{.*}} i32 @call_deduced_return_operator()
// CHECK: call noundef i32* @_ZZL14deduced_returnvEN1SclEv(
// CHECK: load i32, i32* %
// CHECK: ret i32 %
// CHECK-LABEL: define internal noundef i32* @_ZZL14deduced_returnvEN1SclEv(%struct.S* {{[^,]*}} %this)
// CHECK: ret i32* @_ZZL14deduced_returnvE1n
static auto
extern "C" int
// CHECK-LABEL: define{{.*}} i32 @call_block_deduced_return()
// CHECK: call noundef i32* @_ZZZL20block_deduced_returnvEUb_EN1SclEv(
// CHECK: load i32, i32* %
// CHECK: ret i32 %
// CHECK-LABEL: define internal noundef i32* @_ZZZL20block_deduced_returnvEUb_EN1SclEv(%struct.S.6* {{[^,]*}} %this) #1 align 2 {
// CHECK: ret i32* @_ZZZL20block_deduced_returnvEUb_E1n
inline auto
void *global_label = decltype;
// CHECK-LABEL: define linkonce_odr noundef i8* @_ZZ18static_local_labelPvEN1S3getEv()
// CHECK: %[[lbl:[^ ]*]] = load i8*, i8** @_ZZ18static_local_labelPvE1q
// CHECK: ret i8* %[[lbl]]
auto global_lambda = ;
extern "C" int
// CHECK-LABEL: define{{.*}} i32 @use_global_lambda()
// CHECK: call noundef i32* @"_ZZNK3$_2clEvEN1S3getEv"()
// CHECK-LABEL: define internal noundef i32* @"_ZZNK3$_2clEvEN1S3getEv"()
// CHECK: ret i32* @"_ZZNK3$_2clEvE1x"