globals.carbon 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/interop/cpp/globals.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/globals.carbon
  12. // ============================================================================
  13. // Global variables
  14. // ============================================================================
  15. // --- global.h
  16. class C {};
  17. C global;
  18. // --- import_global.carbon
  19. library "[[@TEST_NAME]]";
  20. import Cpp library "global.h";
  21. fn MyF() {
  22. let _: Cpp.C = Cpp.global;
  23. }
  24. // ============================================================================
  25. // Inline variable
  26. // ============================================================================
  27. // --- inline.h
  28. struct C {
  29. C();
  30. ~C();
  31. void f();
  32. };
  33. inline C inline_global;
  34. // --- import_inline.carbon
  35. library "[[@TEST_NAME]]";
  36. import Cpp library "inline.h";
  37. fn CallF() {
  38. Cpp.inline_global.f();
  39. }
  40. // ============================================================================
  41. // Thread-local variable
  42. // ============================================================================
  43. // --- thread_local.h
  44. thread_local int thread_local_global;
  45. int init();
  46. thread_local int thread_local_global_with_init = init();
  47. // --- todo_import_thread_local.carbon
  48. library "[[@TEST_NAME]]";
  49. import Cpp library "thread_local.h";
  50. // TODO: We should call the C++ thread wrapper function here instead of directly
  51. // accessing the global. We fail to trigger the initialization of the global.
  52. fn ThreadLocalStore() {
  53. Cpp.thread_local_global = 42;
  54. }
  55. fn ThreadLocalTriggerInit() -> i32 {
  56. return Cpp.thread_local_global_with_init;
  57. }
  58. // ============================================================================
  59. // Static data members
  60. // ============================================================================
  61. // --- static.h
  62. struct X {
  63. static inline int n = 42;
  64. };
  65. // --- import_static.carbon
  66. library "[[@TEST_NAME]]";
  67. import Cpp library "static.h";
  68. fn ReadStatic() -> i32 {
  69. return Cpp.X.n;
  70. }
  71. // ============================================================================
  72. // Variable templates
  73. // ============================================================================
  74. // --- var_template.h
  75. template<typename T> T tmpl = T();
  76. struct Y {
  77. Y();
  78. };
  79. // --- import_var_template.carbon
  80. library "[[@TEST_NAME]]";
  81. import Cpp library "var_template.h";
  82. fn ReadVarTemplate() -> i32 {
  83. return Cpp.tmpl(i32);
  84. }
  85. fn ReadVarTemplateWithConstructor() -> Cpp.Y* {
  86. return &Cpp.tmpl(Cpp.Y);
  87. }
  88. // ============================================================================
  89. // Static data member templates
  90. // ============================================================================
  91. // --- static_template.h
  92. struct X {
  93. template<typename T> static T static_tmpl = T();
  94. };
  95. struct Y {
  96. Y();
  97. };
  98. // --- import_static_template.carbon
  99. library "[[@TEST_NAME]]";
  100. import Cpp library "static_template.h";
  101. fn ReadStaticVarTemplate() -> i32 {
  102. return Cpp.X.static_tmpl(i32);
  103. }
  104. fn ReadStaticVarTemplateWithConstructor() -> Cpp.Y* {
  105. return &Cpp.X.static_tmpl(Cpp.Y);
  106. }
  107. // CHECK:STDOUT: ; ModuleID = 'import_global.carbon'
  108. // CHECK:STDOUT: source_filename = "import_global.carbon"
  109. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  110. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: %class.C = type { i8 }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: @global = dso_local global %class.C zeroinitializer, align 1
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: ; Function Attrs: nounwind
  117. // CHECK:STDOUT: define void @_CMyF.Main() #0 !dbg !11 {
  118. // CHECK:STDOUT: entry:
  119. // CHECK:STDOUT: ret void, !dbg !14
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: attributes #0 = { nounwind }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  125. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  126. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  129. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  130. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  131. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  132. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  133. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  134. // CHECK:STDOUT: !6 = !DIFile(filename: "import_global.carbon", directory: "")
  135. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  136. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  137. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  138. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  139. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "MyF", linkageName: "_CMyF.Main", scope: null, file: !6, line: 6, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  140. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  141. // CHECK:STDOUT: !13 = !{null}
  142. // CHECK:STDOUT: !14 = !DILocation(line: 6, column: 1, scope: !11)
  143. // CHECK:STDOUT: ; ModuleID = 'import_inline.carbon'
  144. // CHECK:STDOUT: source_filename = "import_inline.carbon"
  145. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  146. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: %struct.C = type { i8 }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: $inline_global = comdat any
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: @inline_global = linkonce_odr dso_local global %struct.C zeroinitializer, comdat, align 1
  153. // CHECK:STDOUT: @_ZGV13inline_global = linkonce_odr dso_local global i64 0, comdat($inline_global), align 8
  154. // CHECK:STDOUT: @__dso_handle = external hidden global i8
  155. // CHECK:STDOUT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr @inline_global }]
  156. // CHECK:STDOUT: @llvm.used = appending global [1 x ptr] [ptr @inline_global], section "llvm.metadata"
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: ; Function Attrs: uwtable
  159. // CHECK:STDOUT: define internal void @__cxx_global_var_init() #0 section ".text.startup" comdat($inline_global) personality ptr @__gxx_personality_v0 {
  160. // CHECK:STDOUT: entry:
  161. // CHECK:STDOUT: %exn.slot = alloca ptr, align 8
  162. // CHECK:STDOUT: %ehselector.slot = alloca i32, align 4
  163. // CHECK:STDOUT: %0 = load atomic i8, ptr @_ZGV13inline_global acquire, align 8
  164. // CHECK:STDOUT: %guard.uninitialized = icmp eq i8 %0, 0
  165. // CHECK:STDOUT: br i1 %guard.uninitialized, label %init.check, label %init.end
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: init.check: ; preds = %entry
  168. // CHECK:STDOUT: %1 = call i32 @__cxa_guard_acquire(ptr @_ZGV13inline_global) #1
  169. // CHECK:STDOUT: %tobool = icmp ne i32 %1, 0
  170. // CHECK:STDOUT: br i1 %tobool, label %init, label %init.end
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: init: ; preds = %init.check
  173. // CHECK:STDOUT: invoke void @_ZN1CC1Ev(ptr noundef nonnull align 1 dereferenceable(1) @inline_global)
  174. // CHECK:STDOUT: to label %invoke.cont unwind label %lpad
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: invoke.cont: ; preds = %init
  177. // CHECK:STDOUT: %2 = call i32 @__cxa_atexit(ptr @_ZN1CD1Ev, ptr @inline_global, ptr @__dso_handle) #1
  178. // CHECK:STDOUT: call void @__cxa_guard_release(ptr @_ZGV13inline_global) #1
  179. // CHECK:STDOUT: br label %init.end
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: init.end: ; preds = %invoke.cont, %init.check, %entry
  182. // CHECK:STDOUT: ret void
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: lpad: ; preds = %init
  185. // CHECK:STDOUT: %3 = landingpad { ptr, i32 }
  186. // CHECK:STDOUT: cleanup
  187. // CHECK:STDOUT: %4 = extractvalue { ptr, i32 } %3, 0
  188. // CHECK:STDOUT: store ptr %4, ptr %exn.slot, align 8
  189. // CHECK:STDOUT: %5 = extractvalue { ptr, i32 } %3, 1
  190. // CHECK:STDOUT: store i32 %5, ptr %ehselector.slot, align 4
  191. // CHECK:STDOUT: call void @__cxa_guard_abort(ptr @_ZGV13inline_global) #1
  192. // CHECK:STDOUT: br label %eh.resume
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: eh.resume: ; preds = %lpad
  195. // CHECK:STDOUT: %exn = load ptr, ptr %exn.slot, align 8
  196. // CHECK:STDOUT: %sel = load i32, ptr %ehselector.slot, align 4
  197. // CHECK:STDOUT: %lpad.val = insertvalue { ptr, i32 } poison, ptr %exn, 0
  198. // CHECK:STDOUT: %lpad.val1 = insertvalue { ptr, i32 } %lpad.val, i32 %sel, 1
  199. // CHECK:STDOUT: resume { ptr, i32 } %lpad.val1
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: ; Function Attrs: nounwind
  203. // CHECK:STDOUT: declare i32 @__cxa_guard_acquire(ptr) #1
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: declare void @_ZN1CC1Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #2
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: declare i32 @__gxx_personality_v0(...)
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: ; Function Attrs: nounwind
  210. // CHECK:STDOUT: declare void @_ZN1CD1Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #3
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: ; Function Attrs: nounwind
  213. // CHECK:STDOUT: declare i32 @__cxa_atexit(ptr, ptr, ptr) #1
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: ; Function Attrs: nounwind
  216. // CHECK:STDOUT: declare void @__cxa_guard_abort(ptr) #1
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: ; Function Attrs: nounwind
  219. // CHECK:STDOUT: declare void @__cxa_guard_release(ptr) #1
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: ; Function Attrs: nounwind
  222. // CHECK:STDOUT: define void @_CCallF.Main() #1 !dbg !11 {
  223. // CHECK:STDOUT: entry:
  224. // CHECK:STDOUT: call void @_ZN1C1fEv(ptr @inline_global), !dbg !14
  225. // CHECK:STDOUT: ret void, !dbg !15
  226. // CHECK:STDOUT: }
  227. // CHECK:STDOUT:
  228. // CHECK:STDOUT: declare void @_ZN1C1fEv(ptr noundef nonnull align 1 dereferenceable(1)) #2
  229. // CHECK:STDOUT:
  230. // CHECK:STDOUT: ; uselistorder directives
  231. // CHECK:STDOUT: uselistorder ptr @inline_global, { 2, 3, 4, 0, 1 }
  232. // CHECK:STDOUT: uselistorder ptr @_ZGV13inline_global, { 1, 0, 2, 3 }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: attributes #0 = { uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  235. // CHECK:STDOUT: attributes #1 = { nounwind }
  236. // CHECK:STDOUT: attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  237. // CHECK:STDOUT: attributes #3 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  240. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  241. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  244. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  245. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  246. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  247. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  248. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  249. // CHECK:STDOUT: !6 = !DIFile(filename: "import_inline.carbon", directory: "")
  250. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  251. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  252. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  253. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  254. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "CallF", linkageName: "_CCallF.Main", scope: null, file: !6, line: 6, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  255. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  256. // CHECK:STDOUT: !13 = !{null}
  257. // CHECK:STDOUT: !14 = !DILocation(line: 7, column: 3, scope: !11)
  258. // CHECK:STDOUT: !15 = !DILocation(line: 6, column: 1, scope: !11)
  259. // CHECK:STDOUT: ; ModuleID = 'todo_import_thread_local.carbon'
  260. // CHECK:STDOUT: source_filename = "todo_import_thread_local.carbon"
  261. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  262. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  263. // CHECK:STDOUT:
  264. // CHECK:STDOUT: $_ZTW19thread_local_global = comdat any
  265. // CHECK:STDOUT:
  266. // CHECK:STDOUT: $_ZTW29thread_local_global_with_init = comdat any
  267. // CHECK:STDOUT:
  268. // CHECK:STDOUT: @thread_local_global = dso_local thread_local global i32 0, align 4
  269. // CHECK:STDOUT: @thread_local_global_with_init = dso_local thread_local global i32 0, align 4
  270. // CHECK:STDOUT: @__tls_guard = internal thread_local global i8 0, align 1
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: @_ZTH29thread_local_global_with_init = dso_local alias void (), ptr @__tls_init
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: ; Function Attrs: uwtable
  275. // CHECK:STDOUT: define internal void @__cxx_global_var_init() #0 section ".text.startup" {
  276. // CHECK:STDOUT: entry:
  277. // CHECK:STDOUT: %call = call noundef i32 @_Z4initv()
  278. // CHECK:STDOUT: %0 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @thread_local_global_with_init)
  279. // CHECK:STDOUT: store i32 %call, ptr %0, align 4, !tbaa !7
  280. // CHECK:STDOUT: ret void
  281. // CHECK:STDOUT: }
  282. // CHECK:STDOUT:
  283. // CHECK:STDOUT: declare noundef i32 @_Z4initv() #1
  284. // CHECK:STDOUT:
  285. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
  286. // CHECK:STDOUT: declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2
  287. // CHECK:STDOUT:
  288. // CHECK:STDOUT: ; Function Attrs: nounwind
  289. // CHECK:STDOUT: define void @_CThreadLocalStore.Main() #3 !dbg !11 {
  290. // CHECK:STDOUT: entry:
  291. // CHECK:STDOUT: store i32 42, ptr @thread_local_global, align 4, !dbg !14
  292. // CHECK:STDOUT: ret void, !dbg !15
  293. // CHECK:STDOUT: }
  294. // CHECK:STDOUT:
  295. // CHECK:STDOUT: ; Function Attrs: nounwind
  296. // CHECK:STDOUT: define i32 @_CThreadLocalTriggerInit.Main() #3 !dbg !16 {
  297. // CHECK:STDOUT: entry:
  298. // CHECK:STDOUT: %.loc14 = load i32, ptr @thread_local_global_with_init, align 4, !dbg !20
  299. // CHECK:STDOUT: ret i32 %.loc14, !dbg !21
  300. // CHECK:STDOUT: }
  301. // CHECK:STDOUT:
  302. // CHECK:STDOUT: ; Function Attrs: uwtable
  303. // CHECK:STDOUT: define internal void @__tls_init() #0 {
  304. // CHECK:STDOUT: entry:
  305. // CHECK:STDOUT: %0 = load i8, ptr @__tls_guard, align 1
  306. // CHECK:STDOUT: %guard.uninitialized = icmp eq i8 %0, 0
  307. // CHECK:STDOUT: br i1 %guard.uninitialized, label %init, label %exit, !prof !22
  308. // CHECK:STDOUT:
  309. // CHECK:STDOUT: init: ; preds = %entry
  310. // CHECK:STDOUT: store i8 1, ptr @__tls_guard, align 1
  311. // CHECK:STDOUT: %1 = call ptr @llvm.invariant.start.p0(i64 1, ptr @__tls_guard)
  312. // CHECK:STDOUT: call void @__cxx_global_var_init()
  313. // CHECK:STDOUT: br label %exit
  314. // CHECK:STDOUT:
  315. // CHECK:STDOUT: exit: ; preds = %init, %entry
  316. // CHECK:STDOUT: ret void
  317. // CHECK:STDOUT: }
  318. // CHECK:STDOUT:
  319. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  320. // CHECK:STDOUT: declare ptr @llvm.invariant.start.p0(i64 immarg, ptr captures(none)) #4
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: ; Function Attrs: uwtable
  323. // CHECK:STDOUT: define weak_odr hidden noundef ptr @_ZTW19thread_local_global() #5 comdat {
  324. // CHECK:STDOUT: %1 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @thread_local_global)
  325. // CHECK:STDOUT: ret ptr %1
  326. // CHECK:STDOUT: }
  327. // CHECK:STDOUT:
  328. // CHECK:STDOUT: ; Function Attrs: uwtable
  329. // CHECK:STDOUT: define weak_odr hidden noundef ptr @_ZTW29thread_local_global_with_init() #5 comdat {
  330. // CHECK:STDOUT: call void @_ZTH29thread_local_global_with_init()
  331. // CHECK:STDOUT: %1 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @thread_local_global_with_init)
  332. // CHECK:STDOUT: ret ptr %1
  333. // CHECK:STDOUT: }
  334. // CHECK:STDOUT:
  335. // CHECK:STDOUT: attributes #0 = { uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  336. // CHECK:STDOUT: attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  337. // CHECK:STDOUT: attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
  338. // CHECK:STDOUT: attributes #3 = { nounwind }
  339. // CHECK:STDOUT: attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  340. // CHECK:STDOUT: attributes #5 = { uwtable "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  341. // CHECK:STDOUT:
  342. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  343. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  344. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  345. // CHECK:STDOUT:
  346. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  347. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  348. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  349. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  350. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  351. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  352. // CHECK:STDOUT: !6 = !DIFile(filename: "todo_import_thread_local.carbon", directory: "")
  353. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  354. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  355. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  356. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  357. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "ThreadLocalStore", linkageName: "_CThreadLocalStore.Main", scope: null, file: !6, line: 9, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  358. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  359. // CHECK:STDOUT: !13 = !{null}
  360. // CHECK:STDOUT: !14 = !DILocation(line: 10, column: 3, scope: !11)
  361. // CHECK:STDOUT: !15 = !DILocation(line: 9, column: 1, scope: !11)
  362. // CHECK:STDOUT: !16 = distinct !DISubprogram(name: "ThreadLocalTriggerInit", linkageName: "_CThreadLocalTriggerInit.Main", scope: null, file: !6, line: 13, type: !17, spFlags: DISPFlagDefinition, unit: !5)
  363. // CHECK:STDOUT: !17 = !DISubroutineType(types: !18)
  364. // CHECK:STDOUT: !18 = !{!19}
  365. // CHECK:STDOUT: !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  366. // CHECK:STDOUT: !20 = !DILocation(line: 14, column: 10, scope: !16)
  367. // CHECK:STDOUT: !21 = !DILocation(line: 14, column: 3, scope: !16)
  368. // CHECK:STDOUT: !22 = !{!"branch_weights", i32 1, i32 1023}
  369. // CHECK:STDOUT: ; ModuleID = 'import_static.carbon'
  370. // CHECK:STDOUT: source_filename = "import_static.carbon"
  371. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  372. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  373. // CHECK:STDOUT:
  374. // CHECK:STDOUT: $_ZN1X1nE = comdat any
  375. // CHECK:STDOUT:
  376. // CHECK:STDOUT: @_ZN1X1nE = linkonce_odr dso_local global i32 42, comdat, align 4
  377. // CHECK:STDOUT:
  378. // CHECK:STDOUT: ; Function Attrs: nounwind
  379. // CHECK:STDOUT: define i32 @_CReadStatic.Main() #0 !dbg !11 {
  380. // CHECK:STDOUT: entry:
  381. // CHECK:STDOUT: %.loc7 = load i32, ptr @_ZN1X1nE, align 4, !dbg !15
  382. // CHECK:STDOUT: ret i32 %.loc7, !dbg !16
  383. // CHECK:STDOUT: }
  384. // CHECK:STDOUT:
  385. // CHECK:STDOUT: attributes #0 = { nounwind }
  386. // CHECK:STDOUT:
  387. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  388. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  389. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  390. // CHECK:STDOUT:
  391. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  392. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  393. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  394. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  395. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  396. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  397. // CHECK:STDOUT: !6 = !DIFile(filename: "import_static.carbon", directory: "")
  398. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  399. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  400. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  401. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  402. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "ReadStatic", linkageName: "_CReadStatic.Main", scope: null, file: !6, line: 6, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  403. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  404. // CHECK:STDOUT: !13 = !{!14}
  405. // CHECK:STDOUT: !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  406. // CHECK:STDOUT: !15 = !DILocation(line: 7, column: 10, scope: !11)
  407. // CHECK:STDOUT: !16 = !DILocation(line: 7, column: 3, scope: !11)
  408. // CHECK:STDOUT: ; ModuleID = 'import_var_template.carbon'
  409. // CHECK:STDOUT: source_filename = "import_var_template.carbon"
  410. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  411. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  412. // CHECK:STDOUT:
  413. // CHECK:STDOUT: %struct.Y = type { i8 }
  414. // CHECK:STDOUT:
  415. // CHECK:STDOUT: @_Z4tmplIiE = external global i32, align 4
  416. // CHECK:STDOUT: @_Z4tmplI1YE = external global %struct.Y, align 1
  417. // CHECK:STDOUT:
  418. // CHECK:STDOUT: ; Function Attrs: nounwind
  419. // CHECK:STDOUT: define i32 @_CReadVarTemplate.Main() #0 !dbg !11 {
  420. // CHECK:STDOUT: entry:
  421. // CHECK:STDOUT: %.loc7 = load i32, ptr @_Z4tmplIiE, align 4, !dbg !15
  422. // CHECK:STDOUT: ret i32 %.loc7, !dbg !16
  423. // CHECK:STDOUT: }
  424. // CHECK:STDOUT:
  425. // CHECK:STDOUT: ; Function Attrs: nounwind
  426. // CHECK:STDOUT: define ptr @_CReadVarTemplateWithConstructor.Main() #0 !dbg !17 {
  427. // CHECK:STDOUT: entry:
  428. // CHECK:STDOUT: ret ptr @_Z4tmplI1YE, !dbg !21
  429. // CHECK:STDOUT: }
  430. // CHECK:STDOUT:
  431. // CHECK:STDOUT: attributes #0 = { nounwind }
  432. // CHECK:STDOUT:
  433. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  434. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  435. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  436. // CHECK:STDOUT:
  437. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  438. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  439. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  440. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  441. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  442. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  443. // CHECK:STDOUT: !6 = !DIFile(filename: "import_var_template.carbon", directory: "")
  444. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  445. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  446. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  447. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  448. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "ReadVarTemplate", linkageName: "_CReadVarTemplate.Main", scope: null, file: !6, line: 6, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  449. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  450. // CHECK:STDOUT: !13 = !{!14}
  451. // CHECK:STDOUT: !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  452. // CHECK:STDOUT: !15 = !DILocation(line: 7, column: 10, scope: !11)
  453. // CHECK:STDOUT: !16 = !DILocation(line: 7, column: 3, scope: !11)
  454. // CHECK:STDOUT: !17 = distinct !DISubprogram(name: "ReadVarTemplateWithConstructor", linkageName: "_CReadVarTemplateWithConstructor.Main", scope: null, file: !6, line: 10, type: !18, spFlags: DISPFlagDefinition, unit: !5)
  455. // CHECK:STDOUT: !18 = !DISubroutineType(types: !19)
  456. // CHECK:STDOUT: !19 = !{!20}
  457. // CHECK:STDOUT: !20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
  458. // CHECK:STDOUT: !21 = !DILocation(line: 11, column: 3, scope: !17)
  459. // CHECK:STDOUT: ; ModuleID = 'import_static_template.carbon'
  460. // CHECK:STDOUT: source_filename = "import_static_template.carbon"
  461. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  462. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  463. // CHECK:STDOUT:
  464. // CHECK:STDOUT: %struct.Y = type { i8 }
  465. // CHECK:STDOUT:
  466. // CHECK:STDOUT: @_ZN1X11static_tmplIiEE = external global i32, align 4
  467. // CHECK:STDOUT: @_ZN1X11static_tmplI1YEE = external global %struct.Y, align 1
  468. // CHECK:STDOUT:
  469. // CHECK:STDOUT: ; Function Attrs: nounwind
  470. // CHECK:STDOUT: define i32 @_CReadStaticVarTemplate.Main() #0 !dbg !11 {
  471. // CHECK:STDOUT: entry:
  472. // CHECK:STDOUT: %.loc7 = load i32, ptr @_ZN1X11static_tmplIiEE, align 4, !dbg !15
  473. // CHECK:STDOUT: ret i32 %.loc7, !dbg !16
  474. // CHECK:STDOUT: }
  475. // CHECK:STDOUT:
  476. // CHECK:STDOUT: ; Function Attrs: nounwind
  477. // CHECK:STDOUT: define ptr @_CReadStaticVarTemplateWithConstructor.Main() #0 !dbg !17 {
  478. // CHECK:STDOUT: entry:
  479. // CHECK:STDOUT: ret ptr @_ZN1X11static_tmplI1YEE, !dbg !21
  480. // CHECK:STDOUT: }
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: attributes #0 = { nounwind }
  483. // CHECK:STDOUT:
  484. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  485. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  486. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  487. // CHECK:STDOUT:
  488. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  489. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  490. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  491. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  492. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  493. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  494. // CHECK:STDOUT: !6 = !DIFile(filename: "import_static_template.carbon", directory: "")
  495. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  496. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  497. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  498. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  499. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "ReadStaticVarTemplate", linkageName: "_CReadStaticVarTemplate.Main", scope: null, file: !6, line: 6, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  500. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  501. // CHECK:STDOUT: !13 = !{!14}
  502. // CHECK:STDOUT: !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  503. // CHECK:STDOUT: !15 = !DILocation(line: 7, column: 10, scope: !11)
  504. // CHECK:STDOUT: !16 = !DILocation(line: 7, column: 3, scope: !11)
  505. // CHECK:STDOUT: !17 = distinct !DISubprogram(name: "ReadStaticVarTemplateWithConstructor", linkageName: "_CReadStaticVarTemplateWithConstructor.Main", scope: null, file: !6, line: 10, type: !18, spFlags: DISPFlagDefinition, unit: !5)
  506. // CHECK:STDOUT: !18 = !DISubroutineType(types: !19)
  507. // CHECK:STDOUT: !19 = !{!20}
  508. // CHECK:STDOUT: !20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
  509. // CHECK:STDOUT: !21 = !DILocation(line: 11, column: 3, scope: !17)