| 1 |
// RUN: %clang_cc1 -std=c++2a -fblocks %s -triple x86_64-unknown-unknown -emit-llvm -o %t.ll |
| 2 |
// RUN: %clang_cc1 -std=c++14 -fblocks %s -triple x86_64-unknown-unknown -emit-llvm -o %t.ll |
| 3 |
|
| 4 |
|
| 5 |
// This needs to be performed before #line directives which alter filename |
| 6 |
// RUN: %clang_cc1 -fno-file-reproducible -fmacro-prefix-map=%p=/UNLIKELY/PATH -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-PREFIX-MAP |
| 7 |
// |
| 8 |
// CHECK-PREFIX-MAP: /UNLIKELY/PATH{{/|\\\\}}builtin-source-location.cpp |
| 9 |
void testRemap() { |
| 10 |
const char *file = __builtin_FILE(); |
| 11 |
} |
| 12 |
|
| 13 |
#line 8 "builtin-source-location.cpp" |
| 14 |
|
| 15 |
namespace std { |
| 16 |
class source_location { |
| 17 |
public: |
| 18 |
static constexpr source_location current(const void *__p = __builtin_source_location()) noexcept { |
| 19 |
source_location __loc; |
| 20 |
__loc.__m_impl = static_cast<const __impl *>(__p); |
| 21 |
return __loc; |
| 22 |
} |
| 23 |
static source_location bad_current(const void *__p = __builtin_source_location()) noexcept { |
| 24 |
return current(__p); |
| 25 |
} |
| 26 |
constexpr source_location() = default; |
| 27 |
constexpr source_location(source_location const &) = default; |
| 28 |
constexpr unsigned int line() const noexcept { return __m_impl->_M_line; } |
| 29 |
constexpr unsigned int column() const noexcept { return __m_impl->_M_column; } |
| 30 |
constexpr const char *file() const noexcept { return __m_impl->_M_file_name; } |
| 31 |
constexpr const char *function() const noexcept { return __m_impl->_M_function_name; } |
| 32 |
|
| 33 |
private: |
| 34 |
// Note: The type name "std::source_location::__impl", and its constituent |
| 35 |
// field-names are required by __builtin_source_location(). |
| 36 |
struct __impl { |
| 37 |
const char *_M_file_name; |
| 38 |
const char *_M_function_name; |
| 39 |
unsigned _M_line; |
| 40 |
unsigned _M_column; |
| 41 |
}; |
| 42 |
const __impl *__m_impl = nullptr; |
| 43 |
}; |
| 44 |
} // namespace std |
| 45 |
|
| 46 |
using SL = std::source_location; |
| 47 |
|
| 48 |
extern "C" int sink(...); |
| 49 |
|
| 50 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-GLOBAL-ONE |
| 51 |
// |
| 52 |
// CHECK-GLOBAL-ONE-DAG: @[[FILE:.*]] = {{.*}}c"test_const_init.cpp\00" |
| 53 |
// CHECK-GLOBAL-ONE-DAG: @[[FUNC:.*]] = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 |
| 54 |
// CHECK-GLOBAL-ONE-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 1000, i32 {{[0-9]+}} }, align 8 |
| 55 |
// CHECK-GLOBAL-ONE: @const_init_global ={{.*}} global %"class.std::source_location" { ptr @[[IMPL]] }, align 8 |
| 56 |
#line 1000 "test_const_init.cpp" |
| 57 |
SL const_init_global = SL::current(); |
| 58 |
|
| 59 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-GLOBAL-TWO |
| 60 |
// |
| 61 |
// CHECK-GLOBAL-TWO-DAG: @runtime_init_global ={{.*}} global %"class.std::source_location" zeroinitializer, align 8 |
| 62 |
// |
| 63 |
// CHECK-GLOBAL-TWO-DAG: @[[FILE:.*]] = {{.*}}c"test_runtime_init.cpp\00" |
| 64 |
// CHECK-GLOBAL-TWO-DAG: @[[FUNC:.*]] = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 |
| 65 |
// CHECK-GLOBAL-TWO-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 1100, i32 {{[0-9]+}} }, align 8 |
| 66 |
// |
| 67 |
// CHECK-GLOBAL-TWO: define internal void @__cxx_global_var_init() |
| 68 |
// CHECK-GLOBAL-TWO-NOT: ret |
| 69 |
// CHECK-GLOBAL-TWO: %call = call ptr @_ZNSt15source_location11bad_currentEPKv({{.*}} @[[IMPL]] |
| 70 |
// CHECK-GLOBAL-TWO: store ptr %call, {{.*}} @runtime_init_global |
| 71 |
|
| 72 |
#line 1100 "test_runtime_init.cpp" |
| 73 |
SL runtime_init_global = SL::bad_current(); |
| 74 |
|
| 75 |
#line 2000 "test_function.cpp" |
| 76 |
extern "C" void test_function() { |
| 77 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-LOCAL-ONE |
| 78 |
// |
| 79 |
// CHECK-LOCAL-ONE-DAG: @[[FILE:.*]] = {{.*}}c"test_current.cpp\00" |
| 80 |
// CHECK-LOCAL-ONE-DAG: @[[FUNC:.*]] = {{.*}}c"void test_function()\00" |
| 81 |
// CHECK-LOCAL-ONE-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 2100, i32 {{[0-9]+}} }, align 8 |
| 82 |
// |
| 83 |
// CHECK-LOCAL-ONE: define {{.*}} @test_function |
| 84 |
// CHECK-LOCAL-ONE: call ptr @_ZNSt15source_location7currentEPKv({{.*}} @[[IMPL]] |
| 85 |
#line 2100 "test_current.cpp" |
| 86 |
SL local = SL::current(); |
| 87 |
} |
| 88 |
|
| 89 |
#line 3000 "TestInitClass.cpp" |
| 90 |
struct TestInit { |
| 91 |
SL info = SL::current(); |
| 92 |
SL arg_info; |
| 93 |
|
| 94 |
#line 3100 "TestInitCtor.cpp" |
| 95 |
TestInit(SL arg_info = SL::current()) : arg_info(arg_info) {} |
| 96 |
}; |
| 97 |
|
| 98 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-CTOR-GLOBAL |
| 99 |
// |
| 100 |
// CHECK-CTOR-GLOBAL-DAG: @GlobalInitVal ={{.*}} global %struct.TestInit zeroinitializer, align 8 |
| 101 |
// CHECK-CTOR-GLOBAL-DAG: @[[FILE:.*]] = {{.*}}c"GlobalInitVal.cpp\00" |
| 102 |
// CHECK-CTOR-GLOBAL-DAG: @[[FUNC:.*]] = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 |
| 103 |
// CHECK-CTOR-GLOBAL-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 3400, i32 {{[0-9]+}} }, align 8 |
| 104 |
// |
| 105 |
// CHECK-CTOR-GLOBAL: define internal void @__cxx_global_var_init.{{[0-9]+}}() |
| 106 |
// CHECK-CTOR-GLOBAL-NOT: ret |
| 107 |
// |
| 108 |
// CHECK-CTOR-GLOBAL: call ptr @_ZNSt15source_location7currentEPKv({{.*}} @[[IMPL]] |
| 109 |
// CHECK-CTOR-GLOBAL-NOT: ret |
| 110 |
// CHECK-CTOR-GLOBAL: call void @_ZN8TestInitC1ESt15source_location(ptr {{[^,]*}} @GlobalInitVal, ptr |
| 111 |
#line 3400 "GlobalInitVal.cpp" |
| 112 |
TestInit GlobalInitVal; |
| 113 |
|
| 114 |
extern "C" void test_init_function() { |
| 115 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-CTOR-LOCAL |
| 116 |
// |
| 117 |
// CHECK-CTOR-LOCAL-DAG: @[[FILE:.*]] = {{.*}}c"LocalInitVal.cpp\00" |
| 118 |
// CHECK-CTOR-LOCAL-DAG: @[[FUNC:.*]] = {{.*}}c"void test_init_function()\00" |
| 119 |
// CHECK-CTOR-LOCAL-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 3500, i32 {{[0-9]+}} }, align 8 |
| 120 |
// |
| 121 |
// CHECK-CTOR-LOCAL: define{{.*}} void @test_init_function() |
| 122 |
// CHECK-CTOR-LOCAL-NOT: ret |
| 123 |
// |
| 124 |
// CHECK-CTOR-LOCAL: call ptr @_ZNSt15source_location7currentEPKv({{.*}} @[[IMPL]] |
| 125 |
// CHECK-CTOR-LOCAL-NOT: ret |
| 126 |
// CHECK-CTOR-LOCAL: call void @_ZN8TestInitC1ESt15source_location(ptr {{[^,]*}} %init_local, ptr |
| 127 |
|
| 128 |
#line 3500 "LocalInitVal.cpp" |
| 129 |
TestInit init_local; |
| 130 |
sink(init_local); |
| 131 |
} |
| 132 |
|
| 133 |
#line 4000 "ConstexprClass.cpp" |
| 134 |
struct TestInitConstexpr { |
| 135 |
SL info = SL::current(); |
| 136 |
SL arg_info; |
| 137 |
#line 4200 "ConstexprCtor.cpp" |
| 138 |
constexpr TestInitConstexpr(SL arg_info = SL::current()) : arg_info(arg_info) {} |
| 139 |
}; |
| 140 |
|
| 141 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-CONSTEXPR-T2 |
| 142 |
// |
| 143 |
// CHECK-CONSTEXPR-T2-DAG: @[[FILE_INIT:.*]] = {{.*}}c"ConstexprCtor.cpp\00" |
| 144 |
// CHECK-CONSTEXPR-T2-DAG: @[[FUNC_INIT:.*]] = {{.*}}c"TestInitConstexpr::TestInitConstexpr(SL)\00" |
| 145 |
// CHECK-CONSTEXPR-T2-DAG: @[[IMPL_INIT:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE_INIT]], {{[^@]*}}@[[FUNC_INIT]], i32 4200, i32 {{[0-9]+}} }, align 8 |
| 146 |
// CHECK-CONSTEXPR-T2-DAG: @[[FILE_ARG:.*]] = {{.*}}c"ConstexprGlobal.cpp\00" |
| 147 |
// CHECK-CONSTEXPR-T2-DAG: @[[EMPTY:.*]] = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 |
| 148 |
// CHECK-CONSTEXPR-T2-DAG: @[[IMPL_ARG:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE_ARG]], {{[^@]*}}@[[EMPTY]], i32 4400, i32 {{[0-9]+}} }, align 8 |
| 149 |
// |
| 150 |
// CHECK-CONSTEXPR-T2: @ConstexprGlobal ={{.*}} global %struct.TestInitConstexpr { |
| 151 |
// CHECK-CONSTEXPR-T2-SAME: %"class.std::source_location" { ptr @[[IMPL_INIT]] }, |
| 152 |
// CHECK-CONSTEXPR-T2-SAME: %"class.std::source_location" { ptr @[[IMPL_ARG]] } |
| 153 |
#line 4400 "ConstexprGlobal.cpp" |
| 154 |
TestInitConstexpr ConstexprGlobal; |
| 155 |
|
| 156 |
extern "C" void test_init_function_constexpr() { |
| 157 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-CONSTEXPR-LOCAL |
| 158 |
// |
| 159 |
// CHECK-CONSTEXPR-LOCAL-DAG: @[[FUNC:.*]] = {{.*}}c"void test_init_function_constexpr()\00" |
| 160 |
// CHECK-CONSTEXPR-LOCAL-DAG: @[[FILE:.*]] = {{.*}}c"ConstexprLocal.cpp\00" |
| 161 |
// CHECK-CONSTEXPR-LOCAL-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 4600, i32 {{[0-9]+}} }, align 8 |
| 162 |
// |
| 163 |
// CHECK-CONSTEXPR-LOCAL: define{{.*}} void @test_init_function_constexpr() |
| 164 |
// CHECK-CONSTEXPR-LOCAL-NOT: ret |
| 165 |
// CHECK-CONSTEXPR-LOCAL: call ptr @_ZNSt15source_location7currentEPKv({{.*}} @[[IMPL]] |
| 166 |
// CHECK-CONSTEXPR-LOCAL-NOT: ret |
| 167 |
// CHECK-CONSTEXPR-LOCAL: call void @_ZN17TestInitConstexprC1ESt15source_location(ptr {{[^,]*}} %local_val, ptr |
| 168 |
#line 4600 "ConstexprLocal.cpp" |
| 169 |
TestInitConstexpr local_val; |
| 170 |
} |
| 171 |
|
| 172 |
#line 5000 "TestInitAgg.cpp" |
| 173 |
struct TestInitAgg { |
| 174 |
#line 5100 "i1.cpp" |
| 175 |
SL i1; |
| 176 |
#line 5200 "i2.cpp" |
| 177 |
SL i2 = SL::current(); |
| 178 |
#line 5300 "TestInitAggEnd.cpp" |
| 179 |
}; |
| 180 |
|
| 181 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-AGG-DEFAULT |
| 182 |
// |
| 183 |
// CHECK-AGG-DEFAULT-DAG: @[[FILE:.*]] = {{.*}}c"TestInitAgg.cpp\00" |
| 184 |
// CHECK-AGG-DEFAULT-DAG: @[[FUNC:.*]] = {{.*}}c"TestInitAgg::TestInitAgg()\00" |
| 185 |
// CHECK-AGG-DEFAULT-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 5000, i32 {{[0-9]+}} }, align 8 |
| 186 |
// |
| 187 |
// CHECK-AGG-DEFAULT: @GlobalAggDefault ={{.*}} global %struct.TestInitAgg { |
| 188 |
// CHECK-AGG-DEFAULT-SAME: %"class.std::source_location" zeroinitializer, |
| 189 |
// CHECK-AGG-DEFAULT-SAME: %"class.std::source_location" { ptr @[[IMPL]] } |
| 190 |
#line 5400 "GlobalAggDefault.cpp" |
| 191 |
TestInitAgg GlobalAggDefault; |
| 192 |
|
| 193 |
#line 5500 "test_agg_init_test.cpp" |
| 194 |
extern "C" void test_agg_init() { |
| 195 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-AGG-INIT |
| 196 |
|
| 197 |
// CHECK-AGG-INIT-DAG: @[[FUNC:.*]] = {{.*}}c"void test_agg_init()\00" |
| 198 |
|
| 199 |
// CHECK-AGG-INIT-DAG: @[[FILE:.*]] = {{.*}}c"BraceInitEnd.cpp\00" |
| 200 |
// CHECK-AGG-INIT-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 5700, i32 {{[0-9]+}} }, align 8 |
| 201 |
|
| 202 |
#line 5600 "BraceInitStart.cpp" |
| 203 |
TestInitAgg local_brace_init{ |
| 204 |
#line 5700 "BraceInitEnd.cpp" |
| 205 |
}; |
| 206 |
|
| 207 |
// CHECK-AGG-INIT-DAG: @[[FILE:.*]] = {{.*}}c"EqualInitEnd.cpp\00" |
| 208 |
// CHECK-AGG-INIT-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 5900, i32 {{[0-9]+}} }, align 8 |
| 209 |
|
| 210 |
#line 5800 "EqualInitStart.cpp" |
| 211 |
TestInitAgg local_equal_init = |
| 212 |
{ |
| 213 |
#line 5900 "EqualInitEnd.cpp" |
| 214 |
}; |
| 215 |
|
| 216 |
|
| 217 |
// CHECK-AGG-INIT-DAG: @[[FILE_DEFAULT:.*]] = {{.*}}c"InitListEnd.cpp\00" |
| 218 |
// CHECK-AGG-INIT-DAG: @[[FILE_ELEM:.*]] = {{.*}}c"ListElem.cpp\00" |
| 219 |
// CHECK-AGG-INIT-DAG: @[[IMPL_DEFAULT:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE_ELEM]], {{[^@]*}}@[[FUNC]], i32 6100, i32 {{[0-9]+}} }, align 8 |
| 220 |
// CHECK-AGG-INIT-DAG: @[[IMPL_ELEM:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE_DEFAULT]], {{[^@]*}}@[[FUNC]], i32 6200, i32 {{[0-9]+}} }, align 8 |
| 221 |
|
| 222 |
#line 6000 "InitListStart.cpp" |
| 223 |
TestInitAgg local_list_init = |
| 224 |
{ |
| 225 |
#line 6100 "ListElem.cpp" |
| 226 |
{SL::current()} |
| 227 |
#line 6200 "InitListEnd.cpp" |
| 228 |
}; |
| 229 |
} |
| 230 |
|
| 231 |
#line 7000 "TestTemplate.cpp" |
| 232 |
template <class Tp, int> |
| 233 |
struct TestTemplate { |
| 234 |
Tp info = Tp::current(); |
| 235 |
Tp arg_info; |
| 236 |
#line 7100 "TestTemplateCtor.cpp" |
| 237 |
constexpr TestTemplate(Tp arg_info = Tp::current()) : arg_info(arg_info) {} |
| 238 |
}; |
| 239 |
|
| 240 |
#line 7200 "test_template.cpp" |
| 241 |
template <class T, int V> |
| 242 |
void test_template() { |
| 243 |
|
| 244 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-TEMPL -DINT_ID=0 |
| 245 |
// RUN: FileCheck --input-file %t.ll %s --check-prefix=CHECK-TEMPL -DINT_ID=1 |
| 246 |
// |
| 247 |
// CHECK-TEMPL-DAG: @[[FILE:.*]] = {{.*}}c"local_templ.cpp\00" |
| 248 |
// CHECK-TEMPL-DAG: @[[FUNC:.*]] = {{.*}}c"void test_template() [T = std::source_location, V = [[INT_ID]]]\00" |
| 249 |
// CHECK-TEMPL-DAG: @[[IMPL:.*]] = private unnamed_addr constant %"struct.std::source_location::__impl" { {{[^@]*}}@[[FILE]], {{[^@]*}}@[[FUNC]], i32 7300, i32 {{[0-9]+}} }, align 8 |
| 250 |
#line 7300 "local_templ.cpp" |
| 251 |
TestTemplate<T, V> local_templ; |
| 252 |
} |
| 253 |
#line 7400 "EndTestTemplate.cpp" |
| 254 |
template void test_template<SL, 0>(); |
| 255 |
template void test_template<SL, 1>(); |