generic.carbon 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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/primitives.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/class/generic.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/class/generic.carbon
  12. // --- classes.carbon
  13. package Classes;
  14. base class Base(T:! type) {
  15. var b: T;
  16. }
  17. class Derived(T:! type) {
  18. extend base: Base(T);
  19. var d: T;
  20. }
  21. class Adapter(T:! type) {
  22. extend adapt Derived(T);
  23. }
  24. // --- create.carbon
  25. package Create;
  26. import Classes;
  27. fn CreateDerived() -> Classes.Derived(i32) {
  28. return {.base = {.b = 1}, .d = 2};
  29. }
  30. fn CreateAdapter() -> Classes.Adapter(i32) {
  31. return CreateDerived() as Classes.Adapter(i32);
  32. }
  33. // --- create_generic.carbon
  34. library "[[@TEST_NAME]]";
  35. class A(T:! type) {
  36. var x: T;
  37. var y: T;
  38. }
  39. fn Make[T:! Core.Copy](x: T, y: T) -> A(T) {
  40. return {.x = x, .y = y};
  41. }
  42. fn Ints() -> A(i32) {
  43. return Make(1 as i32, 2 as i32);
  44. }
  45. fn Empty() -> A(()) {
  46. return Make((), ());
  47. }
  48. fn Tuples() -> A((i32, i32)) {
  49. let x: (i32, i32) = (1, 2);
  50. return Make(x, x);
  51. }
  52. // --- access.carbon
  53. library "[[@TEST_NAME]]";
  54. class C(T:! Core.Copy) {
  55. fn GetBool[self: Self]() -> bool {
  56. return self.v;
  57. }
  58. fn GetT[self: Self]() -> T {
  59. return self.w;
  60. }
  61. var v: bool;
  62. var w: T;
  63. }
  64. fn AccessBool() -> bool {
  65. var c: C(i32) = {.v = true, .w = 0};
  66. return c.GetBool();
  67. }
  68. fn AccessInt() -> i32 {
  69. var c: C(i32) = {.v = true, .w = 0};
  70. return c.GetT();
  71. }
  72. fn AccessEmpty() -> () {
  73. var c: C(()) = {.v = true, .w = ()};
  74. return c.GetT();
  75. }
  76. fn AccessTuple() -> (i32, i32, i32) {
  77. var c: C((i32, i32, i32)) = {.v = true, .w = (1, 2, 3)};
  78. return c.GetT();
  79. }
  80. // CHECK:STDOUT: ; ModuleID = 'classes.carbon'
  81. // CHECK:STDOUT: source_filename = "classes.carbon"
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  84. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  87. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  88. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  89. // CHECK:STDOUT: !3 = !DIFile(filename: "classes.carbon", directory: "")
  90. // CHECK:STDOUT: ; ModuleID = 'create.carbon'
  91. // CHECK:STDOUT: source_filename = "create.carbon"
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: @Derived.val.loc7_36 = internal constant { { i32 }, i32 } { { i32 } { i32 1 }, i32 2 }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: ; Function Attrs: nounwind
  96. // CHECK:STDOUT: define void @_CCreateDerived.Create(ptr sret({ { i32 }, i32 }) %return) #0 !dbg !4 {
  97. // CHECK:STDOUT: entry:
  98. // CHECK:STDOUT: %.loc7_35.2.base = getelementptr inbounds nuw { { i32 }, i32 }, ptr %return, i32 0, i32 0, !dbg !7
  99. // CHECK:STDOUT: %.loc7_26.3.b = getelementptr inbounds nuw { i32 }, ptr %.loc7_35.2.base, i32 0, i32 0, !dbg !8
  100. // CHECK:STDOUT: %.loc7_35.5.d = getelementptr inbounds nuw { { i32 }, i32 }, ptr %return, i32 0, i32 1, !dbg !7
  101. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %return, ptr align 4 @Derived.val.loc7_36, i64 8, i1 false), !dbg !9
  102. // CHECK:STDOUT: ret void, !dbg !9
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: ; Function Attrs: nounwind
  106. // CHECK:STDOUT: define void @_CCreateAdapter.Create(ptr sret({ { i32 }, i32 }) %return) #0 !dbg !10 {
  107. // CHECK:STDOUT: entry:
  108. // CHECK:STDOUT: call void @_CCreateDerived.Create(ptr %return), !dbg !11
  109. // CHECK:STDOUT: ret void, !dbg !12
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  113. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #1
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: attributes #0 = { nounwind }
  116. // CHECK:STDOUT: attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  119. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  122. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  123. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  124. // CHECK:STDOUT: !3 = !DIFile(filename: "create.carbon", directory: "")
  125. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "CreateDerived", linkageName: "_CCreateDerived.Create", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  126. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  127. // CHECK:STDOUT: !6 = !{}
  128. // CHECK:STDOUT: !7 = !DILocation(line: 7, column: 10, scope: !4)
  129. // CHECK:STDOUT: !8 = !DILocation(line: 7, column: 19, scope: !4)
  130. // CHECK:STDOUT: !9 = !DILocation(line: 7, column: 3, scope: !4)
  131. // CHECK:STDOUT: !10 = distinct !DISubprogram(name: "CreateAdapter", linkageName: "_CCreateAdapter.Create", scope: null, file: !3, line: 10, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  132. // CHECK:STDOUT: !11 = !DILocation(line: 11, column: 10, scope: !10)
  133. // CHECK:STDOUT: !12 = !DILocation(line: 11, column: 3, scope: !10)
  134. // CHECK:STDOUT: ; ModuleID = 'create_generic.carbon'
  135. // CHECK:STDOUT: source_filename = "create_generic.carbon"
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: @tuple.21c.loc22_28.6 = internal constant { i32, i32 } { i32 1, i32 2 }
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: ; Function Attrs: nounwind
  140. // CHECK:STDOUT: define void @_CInts.Main(ptr sret({ i32, i32 }) %return) #0 !dbg !4 {
  141. // CHECK:STDOUT: entry:
  142. // CHECK:STDOUT: call void @_CMake.Main.5450dc8e8b8e0899(ptr %return, i32 1, i32 2), !dbg !7
  143. // CHECK:STDOUT: ret void, !dbg !8
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: ; Function Attrs: nounwind
  147. // CHECK:STDOUT: define void @_CEmpty.Main(ptr sret({ {}, {} }) %return) #0 !dbg !9 {
  148. // CHECK:STDOUT: entry:
  149. // CHECK:STDOUT: call void @_CMake.Main.cf13cead63317d44(ptr %return), !dbg !10
  150. // CHECK:STDOUT: ret void, !dbg !11
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: ; Function Attrs: nounwind
  154. // CHECK:STDOUT: define void @_CTuples.Main(ptr sret({ { i32, i32 }, { i32, i32 } }) %return) #0 !dbg !12 {
  155. // CHECK:STDOUT: entry:
  156. // CHECK:STDOUT: call void @_CMake.Main.a862d5c8b748242e(ptr %return, ptr @tuple.21c.loc22_28.6, ptr @tuple.21c.loc22_28.6), !dbg !13
  157. // CHECK:STDOUT: ret void, !dbg !14
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: ; Function Attrs: nounwind
  161. // CHECK:STDOUT: define linkonce_odr void @_CMake.Main.5450dc8e8b8e0899(ptr sret({ i32, i32 }) %return, i32 %x, i32 %y) #0 !dbg !15 {
  162. // CHECK:STDOUT: entry:
  163. // CHECK:STDOUT: %.loc10_25.2.x = getelementptr inbounds nuw { i32, i32 }, ptr %return, i32 0, i32 0, !dbg !16
  164. // CHECK:STDOUT: store i32 %x, ptr %.loc10_25.2.x, align 4, !dbg !16
  165. // CHECK:STDOUT: %.loc10_25.4.y = getelementptr inbounds nuw { i32, i32 }, ptr %return, i32 0, i32 1, !dbg !16
  166. // CHECK:STDOUT: store i32 %y, ptr %.loc10_25.4.y, align 4, !dbg !16
  167. // CHECK:STDOUT: ret void, !dbg !17
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: ; Function Attrs: nounwind
  171. // CHECK:STDOUT: define linkonce_odr void @_CMake.Main.cf13cead63317d44(ptr sret({ {}, {} }) %return) #0 !dbg !18 {
  172. // CHECK:STDOUT: entry:
  173. // CHECK:STDOUT: %.loc10_25.2.x = getelementptr inbounds nuw { {}, {} }, ptr %return, i32 0, i32 0, !dbg !19
  174. // CHECK:STDOUT: %.loc10_25.4.y = getelementptr inbounds nuw { {}, {} }, ptr %return, i32 0, i32 1, !dbg !19
  175. // CHECK:STDOUT: ret void, !dbg !20
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: ; Function Attrs: nounwind
  179. // CHECK:STDOUT: define linkonce_odr void @_CMake.Main.a862d5c8b748242e(ptr sret({ { i32, i32 }, { i32, i32 } }) %return, ptr %x, ptr %y) #0 !dbg !21 {
  180. // CHECK:STDOUT: entry:
  181. // CHECK:STDOUT: %.loc10_25.2.x = getelementptr inbounds nuw { { i32, i32 }, { i32, i32 } }, ptr %return, i32 0, i32 0, !dbg !22
  182. // CHECK:STDOUT: call void @"_COp.2b3ba83e01542f11:Copy.Core.4193728889277ad1"(ptr %.loc10_25.2.x, ptr %x), !dbg !23
  183. // CHECK:STDOUT: %.loc10_25.4.y = getelementptr inbounds nuw { { i32, i32 }, { i32, i32 } }, ptr %return, i32 0, i32 1, !dbg !22
  184. // CHECK:STDOUT: call void @"_COp.2b3ba83e01542f11:Copy.Core.4193728889277ad1"(ptr %.loc10_25.4.y, ptr %y), !dbg !24
  185. // CHECK:STDOUT: ret void, !dbg !25
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: ; Function Attrs: nounwind
  189. // CHECK:STDOUT: define linkonce_odr void @"_COp.2b3ba83e01542f11:Copy.Core.4193728889277ad1"(ptr sret({ i32, i32 }) %return, ptr %self) #0 !dbg !26 {
  190. // CHECK:STDOUT: %tuple.elem = getelementptr inbounds nuw { i32, i32 }, ptr %self, i32 0, i32 0, !dbg !28
  191. // CHECK:STDOUT: %tuple.elem.load = load i32, ptr %tuple.elem, align 4, !dbg !28
  192. // CHECK:STDOUT: %tuple.elem1 = getelementptr inbounds nuw { i32, i32 }, ptr %return, i32 0, i32 0, !dbg !29
  193. // CHECK:STDOUT: %tuple.elem2 = getelementptr inbounds nuw { i32, i32 }, ptr %self, i32 0, i32 1, !dbg !30
  194. // CHECK:STDOUT: %tuple.elem.load3 = load i32, ptr %tuple.elem2, align 4, !dbg !30
  195. // CHECK:STDOUT: %tuple.elem4 = getelementptr inbounds nuw { i32, i32 }, ptr %return, i32 0, i32 1, !dbg !29
  196. // CHECK:STDOUT: store i32 %tuple.elem.load, ptr %tuple.elem1, align 4, !dbg !29
  197. // CHECK:STDOUT: store i32 %tuple.elem.load3, ptr %tuple.elem4, align 4, !dbg !29
  198. // CHECK:STDOUT: ret void, !dbg !31
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: ; uselistorder directives
  202. // CHECK:STDOUT: uselistorder ptr @"_COp.2b3ba83e01542f11:Copy.Core.4193728889277ad1", { 1, 0 }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: attributes #0 = { nounwind }
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  207. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  210. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  211. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  212. // CHECK:STDOUT: !3 = !DIFile(filename: "create_generic.carbon", directory: "")
  213. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Ints", linkageName: "_CInts.Main", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  214. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  215. // CHECK:STDOUT: !6 = !{}
  216. // CHECK:STDOUT: !7 = !DILocation(line: 14, column: 10, scope: !4)
  217. // CHECK:STDOUT: !8 = !DILocation(line: 14, column: 3, scope: !4)
  218. // CHECK:STDOUT: !9 = distinct !DISubprogram(name: "Empty", linkageName: "_CEmpty.Main", scope: null, file: !3, line: 17, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  219. // CHECK:STDOUT: !10 = !DILocation(line: 18, column: 10, scope: !9)
  220. // CHECK:STDOUT: !11 = !DILocation(line: 18, column: 3, scope: !9)
  221. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Tuples", linkageName: "_CTuples.Main", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  222. // CHECK:STDOUT: !13 = !DILocation(line: 23, column: 10, scope: !12)
  223. // CHECK:STDOUT: !14 = !DILocation(line: 23, column: 3, scope: !12)
  224. // CHECK:STDOUT: !15 = distinct !DISubprogram(name: "Make", linkageName: "_CMake.Main.5450dc8e8b8e0899", scope: null, file: !3, line: 9, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  225. // CHECK:STDOUT: !16 = !DILocation(line: 10, column: 10, scope: !15)
  226. // CHECK:STDOUT: !17 = !DILocation(line: 10, column: 3, scope: !15)
  227. // CHECK:STDOUT: !18 = distinct !DISubprogram(name: "Make", linkageName: "_CMake.Main.cf13cead63317d44", scope: null, file: !3, line: 9, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  228. // CHECK:STDOUT: !19 = !DILocation(line: 10, column: 10, scope: !18)
  229. // CHECK:STDOUT: !20 = !DILocation(line: 10, column: 3, scope: !18)
  230. // CHECK:STDOUT: !21 = distinct !DISubprogram(name: "Make", linkageName: "_CMake.Main.a862d5c8b748242e", scope: null, file: !3, line: 9, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  231. // CHECK:STDOUT: !22 = !DILocation(line: 10, column: 10, scope: !21)
  232. // CHECK:STDOUT: !23 = !DILocation(line: 10, column: 16, scope: !21)
  233. // CHECK:STDOUT: !24 = !DILocation(line: 10, column: 24, scope: !21)
  234. // CHECK:STDOUT: !25 = !DILocation(line: 10, column: 3, scope: !21)
  235. // CHECK:STDOUT: !26 = distinct !DISubprogram(name: "Op", linkageName: "_COp.2b3ba83e01542f11:Copy.Core.4193728889277ad1", scope: null, file: !27, line: 48, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  236. // CHECK:STDOUT: !27 = !DIFile(filename: "min_prelude/parts/copy.carbon", directory: "")
  237. // CHECK:STDOUT: !28 = !DILocation(line: 49, column: 13, scope: !26)
  238. // CHECK:STDOUT: !29 = !DILocation(line: 49, column: 12, scope: !26)
  239. // CHECK:STDOUT: !30 = !DILocation(line: 49, column: 26, scope: !26)
  240. // CHECK:STDOUT: !31 = !DILocation(line: 49, column: 5, scope: !26)
  241. // CHECK:STDOUT: ; ModuleID = 'access.carbon'
  242. // CHECK:STDOUT: source_filename = "access.carbon"
  243. // CHECK:STDOUT:
  244. // CHECK:STDOUT: @C.val.9ee.loc16_3 = internal constant { i1, i32 } { i1 true, i32 0 }
  245. // CHECK:STDOUT: @C.val.f52.loc26_3 = internal constant { i1, {} } { i1 true, {} zeroinitializer }
  246. // CHECK:STDOUT: @C.val.029.loc31_3 = internal constant { i1, { i32, i32, i32 } } { i1 true, { i32, i32, i32 } { i32 1, i32 2, i32 3 } }
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: ; Function Attrs: nounwind
  249. // CHECK:STDOUT: define i1 @_CAccessBool.Main() #0 !dbg !4 {
  250. // CHECK:STDOUT: entry:
  251. // CHECK:STDOUT: %c.var = alloca { i1, i32 }, align 8, !dbg !7
  252. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !7
  253. // CHECK:STDOUT: %.loc16_37.2.v = getelementptr inbounds nuw { i1, i32 }, ptr %c.var, i32 0, i32 0, !dbg !8
  254. // CHECK:STDOUT: %.loc16_37.5.w = getelementptr inbounds nuw { i1, i32 }, ptr %c.var, i32 0, i32 1, !dbg !8
  255. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %c.var, ptr align 4 @C.val.9ee.loc16_3, i64 8, i1 false), !dbg !7
  256. // CHECK:STDOUT: %C.GetBool.call = call i1 @_CGetBool.C.Main.5450dc8e8b8e0899(ptr %c.var), !dbg !9
  257. // CHECK:STDOUT: ret i1 %C.GetBool.call, !dbg !10
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: ; Function Attrs: nounwind
  261. // CHECK:STDOUT: define i32 @_CAccessInt.Main() #0 !dbg !11 {
  262. // CHECK:STDOUT: entry:
  263. // CHECK:STDOUT: %c.var = alloca { i1, i32 }, align 8, !dbg !12
  264. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !12
  265. // CHECK:STDOUT: %.loc21_37.2.v = getelementptr inbounds nuw { i1, i32 }, ptr %c.var, i32 0, i32 0, !dbg !13
  266. // CHECK:STDOUT: %.loc21_37.5.w = getelementptr inbounds nuw { i1, i32 }, ptr %c.var, i32 0, i32 1, !dbg !13
  267. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %c.var, ptr align 4 @C.val.9ee.loc16_3, i64 8, i1 false), !dbg !12
  268. // CHECK:STDOUT: %C.GetT.call = call i32 @_CGetT.C.Main.5450dc8e8b8e0899(ptr %c.var), !dbg !14
  269. // CHECK:STDOUT: ret i32 %C.GetT.call, !dbg !15
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: ; Function Attrs: nounwind
  273. // CHECK:STDOUT: define void @_CAccessEmpty.Main() #0 !dbg !16 {
  274. // CHECK:STDOUT: entry:
  275. // CHECK:STDOUT: %c.var = alloca { i1, {} }, align 8, !dbg !17
  276. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !17
  277. // CHECK:STDOUT: %.loc26_37.2.v = getelementptr inbounds nuw { i1, {} }, ptr %c.var, i32 0, i32 0, !dbg !18
  278. // CHECK:STDOUT: %.loc26_37.4.w = getelementptr inbounds nuw { i1, {} }, ptr %c.var, i32 0, i32 1, !dbg !18
  279. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %c.var, ptr align 1 @C.val.f52.loc26_3, i64 1, i1 false), !dbg !17
  280. // CHECK:STDOUT: call void @_CGetT.C.Main.cf13cead63317d44(ptr %c.var), !dbg !19
  281. // CHECK:STDOUT: ret void, !dbg !20
  282. // CHECK:STDOUT: }
  283. // CHECK:STDOUT:
  284. // CHECK:STDOUT: ; Function Attrs: nounwind
  285. // CHECK:STDOUT: define void @_CAccessTuple.Main(ptr sret({ i32, i32, i32 }) %return) #0 !dbg !21 {
  286. // CHECK:STDOUT: entry:
  287. // CHECK:STDOUT: %c.var = alloca { i1, { i32, i32, i32 } }, align 8, !dbg !22
  288. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !22
  289. // CHECK:STDOUT: %.loc31_57.2.v = getelementptr inbounds nuw { i1, { i32, i32, i32 } }, ptr %c.var, i32 0, i32 0, !dbg !23
  290. // CHECK:STDOUT: %.loc31_57.4.w = getelementptr inbounds nuw { i1, { i32, i32, i32 } }, ptr %c.var, i32 0, i32 1, !dbg !23
  291. // CHECK:STDOUT: %tuple.elem0.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %.loc31_57.4.w, i32 0, i32 0, !dbg !24
  292. // CHECK:STDOUT: %tuple.elem1.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %.loc31_57.4.w, i32 0, i32 1, !dbg !24
  293. // CHECK:STDOUT: %tuple.elem2.tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %.loc31_57.4.w, i32 0, i32 2, !dbg !24
  294. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %c.var, ptr align 4 @C.val.029.loc31_3, i64 16, i1 false), !dbg !22
  295. // CHECK:STDOUT: call void @_CGetT.C.Main.623a49e5eda7ec3b(ptr %return, ptr %c.var), !dbg !25
  296. // CHECK:STDOUT: ret void, !dbg !26
  297. // CHECK:STDOUT: }
  298. // CHECK:STDOUT:
  299. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  300. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  301. // CHECK:STDOUT:
  302. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  303. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: ; Function Attrs: nounwind
  306. // CHECK:STDOUT: define linkonce_odr i1 @_CGetBool.C.Main.5450dc8e8b8e0899(ptr %self) #0 !dbg !27 {
  307. // CHECK:STDOUT: entry:
  308. // CHECK:STDOUT: %.loc6_16.1.v = getelementptr inbounds nuw { i1, i32 }, ptr %self, i32 0, i32 0, !dbg !28
  309. // CHECK:STDOUT: %.loc6_16.2 = load i8, ptr %.loc6_16.1.v, align 1, !dbg !28
  310. // CHECK:STDOUT: %.loc6_16.21 = trunc i8 %.loc6_16.2 to i1, !dbg !28
  311. // CHECK:STDOUT: ret i1 %.loc6_16.21, !dbg !29
  312. // CHECK:STDOUT: }
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: ; Function Attrs: nounwind
  315. // CHECK:STDOUT: define linkonce_odr i32 @_CGetT.C.Main.5450dc8e8b8e0899(ptr %self) #0 !dbg !30 {
  316. // CHECK:STDOUT: entry:
  317. // CHECK:STDOUT: %.loc9_16.1.w = getelementptr inbounds nuw { i1, i32 }, ptr %self, i32 0, i32 1, !dbg !31
  318. // CHECK:STDOUT: %.loc9_16.2 = load i32, ptr %.loc9_16.1.w, align 4, !dbg !31
  319. // CHECK:STDOUT: ret i32 %.loc9_16.2, !dbg !32
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: ; Function Attrs: nounwind
  323. // CHECK:STDOUT: define linkonce_odr void @_CGetT.C.Main.cf13cead63317d44(ptr %self) #0 !dbg !33 {
  324. // CHECK:STDOUT: entry:
  325. // CHECK:STDOUT: %.loc9_16.1.w = getelementptr inbounds nuw { i1, {} }, ptr %self, i32 0, i32 1, !dbg !34
  326. // CHECK:STDOUT: ret void, !dbg !35
  327. // CHECK:STDOUT: }
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: ; Function Attrs: nounwind
  330. // CHECK:STDOUT: define linkonce_odr void @_CGetT.C.Main.623a49e5eda7ec3b(ptr sret({ i32, i32, i32 }) %return, ptr %self) #0 !dbg !36 {
  331. // CHECK:STDOUT: entry:
  332. // CHECK:STDOUT: %.loc9_16.1.w = getelementptr inbounds nuw { i1, { i32, i32, i32 } }, ptr %self, i32 0, i32 1, !dbg !37
  333. // CHECK:STDOUT: call void @"_COp.6d582b60b7397ec5:Copy.Core.8e95c89adba3b450"(ptr %return, ptr %.loc9_16.1.w), !dbg !37
  334. // CHECK:STDOUT: ret void, !dbg !38
  335. // CHECK:STDOUT: }
  336. // CHECK:STDOUT:
  337. // CHECK:STDOUT: ; Function Attrs: nounwind
  338. // CHECK:STDOUT: define linkonce_odr void @"_COp.6d582b60b7397ec5:Copy.Core.8e95c89adba3b450"(ptr sret({ i32, i32, i32 }) %return, ptr %self) #0 !dbg !39 {
  339. // CHECK:STDOUT: %tuple.elem = getelementptr inbounds nuw { i32, i32, i32 }, ptr %self, i32 0, i32 0, !dbg !41
  340. // CHECK:STDOUT: %tuple.elem.load = load i32, ptr %tuple.elem, align 4, !dbg !41
  341. // CHECK:STDOUT: %tuple.elem1 = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 0, !dbg !42
  342. // CHECK:STDOUT: %tuple.elem2 = getelementptr inbounds nuw { i32, i32, i32 }, ptr %self, i32 0, i32 1, !dbg !43
  343. // CHECK:STDOUT: %tuple.elem.load3 = load i32, ptr %tuple.elem2, align 4, !dbg !43
  344. // CHECK:STDOUT: %tuple.elem4 = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 1, !dbg !42
  345. // CHECK:STDOUT: %tuple.elem5 = getelementptr inbounds nuw { i32, i32, i32 }, ptr %self, i32 0, i32 2, !dbg !44
  346. // CHECK:STDOUT: %tuple.elem.load6 = load i32, ptr %tuple.elem5, align 4, !dbg !44
  347. // CHECK:STDOUT: %tuple.elem7 = getelementptr inbounds nuw { i32, i32, i32 }, ptr %return, i32 0, i32 2, !dbg !42
  348. // CHECK:STDOUT: store i32 %tuple.elem.load, ptr %tuple.elem1, align 4, !dbg !42
  349. // CHECK:STDOUT: store i32 %tuple.elem.load3, ptr %tuple.elem4, align 4, !dbg !42
  350. // CHECK:STDOUT: store i32 %tuple.elem.load6, ptr %tuple.elem7, align 4, !dbg !42
  351. // CHECK:STDOUT: ret void, !dbg !45
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: ; uselistorder directives
  355. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 3, 2, 1, 0 }
  356. // CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 3, 2, 1, 0 }
  357. // CHECK:STDOUT:
  358. // CHECK:STDOUT: attributes #0 = { nounwind }
  359. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  360. // CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  361. // CHECK:STDOUT:
  362. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  363. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  364. // CHECK:STDOUT:
  365. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  366. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  367. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  368. // CHECK:STDOUT: !3 = !DIFile(filename: "access.carbon", directory: "")
  369. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "AccessBool", linkageName: "_CAccessBool.Main", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  370. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  371. // CHECK:STDOUT: !6 = !{}
  372. // CHECK:STDOUT: !7 = !DILocation(line: 16, column: 3, scope: !4)
  373. // CHECK:STDOUT: !8 = !DILocation(line: 16, column: 19, scope: !4)
  374. // CHECK:STDOUT: !9 = !DILocation(line: 17, column: 10, scope: !4)
  375. // CHECK:STDOUT: !10 = !DILocation(line: 17, column: 3, scope: !4)
  376. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "AccessInt", linkageName: "_CAccessInt.Main", scope: null, file: !3, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  377. // CHECK:STDOUT: !12 = !DILocation(line: 21, column: 3, scope: !11)
  378. // CHECK:STDOUT: !13 = !DILocation(line: 21, column: 19, scope: !11)
  379. // CHECK:STDOUT: !14 = !DILocation(line: 22, column: 10, scope: !11)
  380. // CHECK:STDOUT: !15 = !DILocation(line: 22, column: 3, scope: !11)
  381. // CHECK:STDOUT: !16 = distinct !DISubprogram(name: "AccessEmpty", linkageName: "_CAccessEmpty.Main", scope: null, file: !3, line: 25, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  382. // CHECK:STDOUT: !17 = !DILocation(line: 26, column: 3, scope: !16)
  383. // CHECK:STDOUT: !18 = !DILocation(line: 26, column: 18, scope: !16)
  384. // CHECK:STDOUT: !19 = !DILocation(line: 27, column: 10, scope: !16)
  385. // CHECK:STDOUT: !20 = !DILocation(line: 27, column: 3, scope: !16)
  386. // CHECK:STDOUT: !21 = distinct !DISubprogram(name: "AccessTuple", linkageName: "_CAccessTuple.Main", scope: null, file: !3, line: 30, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  387. // CHECK:STDOUT: !22 = !DILocation(line: 31, column: 3, scope: !21)
  388. // CHECK:STDOUT: !23 = !DILocation(line: 31, column: 31, scope: !21)
  389. // CHECK:STDOUT: !24 = !DILocation(line: 31, column: 48, scope: !21)
  390. // CHECK:STDOUT: !25 = !DILocation(line: 32, column: 10, scope: !21)
  391. // CHECK:STDOUT: !26 = !DILocation(line: 32, column: 3, scope: !21)
  392. // CHECK:STDOUT: !27 = distinct !DISubprogram(name: "GetBool", linkageName: "_CGetBool.C.Main.5450dc8e8b8e0899", scope: null, file: !3, line: 5, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  393. // CHECK:STDOUT: !28 = !DILocation(line: 6, column: 12, scope: !27)
  394. // CHECK:STDOUT: !29 = !DILocation(line: 6, column: 5, scope: !27)
  395. // CHECK:STDOUT: !30 = distinct !DISubprogram(name: "GetT", linkageName: "_CGetT.C.Main.5450dc8e8b8e0899", scope: null, file: !3, line: 8, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  396. // CHECK:STDOUT: !31 = !DILocation(line: 9, column: 12, scope: !30)
  397. // CHECK:STDOUT: !32 = !DILocation(line: 9, column: 5, scope: !30)
  398. // CHECK:STDOUT: !33 = distinct !DISubprogram(name: "GetT", linkageName: "_CGetT.C.Main.cf13cead63317d44", scope: null, file: !3, line: 8, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  399. // CHECK:STDOUT: !34 = !DILocation(line: 9, column: 12, scope: !33)
  400. // CHECK:STDOUT: !35 = !DILocation(line: 9, column: 5, scope: !33)
  401. // CHECK:STDOUT: !36 = distinct !DISubprogram(name: "GetT", linkageName: "_CGetT.C.Main.623a49e5eda7ec3b", scope: null, file: !3, line: 8, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  402. // CHECK:STDOUT: !37 = !DILocation(line: 9, column: 12, scope: !36)
  403. // CHECK:STDOUT: !38 = !DILocation(line: 9, column: 5, scope: !36)
  404. // CHECK:STDOUT: !39 = distinct !DISubprogram(name: "Op", linkageName: "_COp.6d582b60b7397ec5:Copy.Core.8e95c89adba3b450", scope: null, file: !40, line: 54, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  405. // CHECK:STDOUT: !40 = !DIFile(filename: "min_prelude/parts/copy.carbon", directory: "")
  406. // CHECK:STDOUT: !41 = !DILocation(line: 55, column: 13, scope: !39)
  407. // CHECK:STDOUT: !42 = !DILocation(line: 55, column: 12, scope: !39)
  408. // CHECK:STDOUT: !43 = !DILocation(line: 55, column: 26, scope: !39)
  409. // CHECK:STDOUT: !44 = !DILocation(line: 55, column: 39, scope: !39)
  410. // CHECK:STDOUT: !45 = !DILocation(line: 55, column: 5, scope: !39)