var_param.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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/function/definition/var_param.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/definition/var_param.carbon
  12. class X {}
  13. fn OneVar_i32(var _: i32) {}
  14. fn OneVar_X(var _: X) {}
  15. fn TwoVars(var _: i32, var _: X) {}
  16. fn VarThenLet(var _: i32, _: X) {}
  17. fn LetThenVar(_: i32, var _: X) {}
  18. fn Call() {
  19. OneVar_i32(1);
  20. OneVar_X({});
  21. TwoVars(1, {});
  22. VarThenLet(1, {});
  23. LetThenVar(1, {});
  24. }
  25. // CHECK:STDOUT: ; ModuleID = 'var_param.carbon'
  26. // CHECK:STDOUT: source_filename = "var_param.carbon"
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: @X.val = internal constant {} zeroinitializer
  29. // CHECK:STDOUT: @X.val.loc16 = internal constant {} zeroinitializer
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: ; Function Attrs: nounwind
  32. // CHECK:STDOUT: define void @_COneVar_i32.Main(ptr %_) #0 !dbg !4 {
  33. // CHECK:STDOUT: entry:
  34. // CHECK:STDOUT: ret void, !dbg !10
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: ; Function Attrs: nounwind
  38. // CHECK:STDOUT: define void @_COneVar_X.Main(ptr %_) #0 !dbg !11 {
  39. // CHECK:STDOUT: entry:
  40. // CHECK:STDOUT: ret void, !dbg !17
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: ; Function Attrs: nounwind
  44. // CHECK:STDOUT: define void @_CTwoVars.Main(ptr %_, ptr %_1) #0 !dbg !18 {
  45. // CHECK:STDOUT: entry:
  46. // CHECK:STDOUT: ret void, !dbg !24
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: ; Function Attrs: nounwind
  50. // CHECK:STDOUT: define void @_CVarThenLet.Main(ptr %_, ptr %_1) #0 !dbg !25 {
  51. // CHECK:STDOUT: entry:
  52. // CHECK:STDOUT: ret void, !dbg !29
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: ; Function Attrs: nounwind
  56. // CHECK:STDOUT: define void @_CLetThenVar.Main(i32 %_, ptr %_1) #0 !dbg !30 {
  57. // CHECK:STDOUT: entry:
  58. // CHECK:STDOUT: ret void, !dbg !34
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: ; Function Attrs: nounwind
  62. // CHECK:STDOUT: define void @_CCall.Main() #0 !dbg !35 {
  63. // CHECK:STDOUT: entry:
  64. // CHECK:STDOUT: %_.var.loc15 = alloca i32, align 4, !dbg !38
  65. // CHECK:STDOUT: %_.var.loc16 = alloca {}, align 8, !dbg !39
  66. // CHECK:STDOUT: %_.var.loc18_12 = alloca i32, align 4, !dbg !40
  67. // CHECK:STDOUT: %_.var.loc18_24 = alloca {}, align 8, !dbg !41
  68. // CHECK:STDOUT: %_.var.loc20 = alloca i32, align 4, !dbg !42
  69. // CHECK:STDOUT: %.loc27_18.2.temp = alloca {}, align 8, !dbg !43
  70. // CHECK:STDOUT: %_.var.loc21 = alloca {}, align 8, !dbg !44
  71. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var.loc15), !dbg !38
  72. // CHECK:STDOUT: store i32 1, ptr %_.var.loc15, align 4, !dbg !38
  73. // CHECK:STDOUT: call void @_COneVar_i32.Main(ptr %_.var.loc15), !dbg !45
  74. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var.loc16), !dbg !39
  75. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %_.var.loc16, ptr align 1 @X.val.loc16, i64 0, i1 false), !dbg !39
  76. // CHECK:STDOUT: call void @_COneVar_X.Main(ptr %_.var.loc16), !dbg !46
  77. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var.loc18_12), !dbg !40
  78. // CHECK:STDOUT: store i32 1, ptr %_.var.loc18_12, align 4, !dbg !40
  79. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var.loc18_24), !dbg !41
  80. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %_.var.loc18_24, ptr align 1 @X.val.loc16, i64 0, i1 false), !dbg !41
  81. // CHECK:STDOUT: call void @_CTwoVars.Main(ptr %_.var.loc18_12, ptr %_.var.loc18_24), !dbg !47
  82. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var.loc20), !dbg !42
  83. // CHECK:STDOUT: store i32 1, ptr %_.var.loc20, align 4, !dbg !42
  84. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc27_18.2.temp), !dbg !43
  85. // CHECK:STDOUT: call void @_CVarThenLet.Main(ptr %_.var.loc20, ptr @X.val.loc16), !dbg !48
  86. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var.loc21), !dbg !44
  87. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %_.var.loc21, ptr align 1 @X.val.loc16, i64 0, i1 false), !dbg !44
  88. // CHECK:STDOUT: call void @_CLetThenVar.Main(i32 1, ptr %_.var.loc21), !dbg !49
  89. // CHECK:STDOUT: call void @"_COp.607f187990247af9:core.Destroy.Core"(ptr %_.var.loc21), !dbg !44
  90. // CHECK:STDOUT: call void @"_COp.607f187990247af9:core.Destroy.Core"(ptr @X.val), !dbg !43
  91. // CHECK:STDOUT: call void @"_COp.7e389eab4a7e5487:core.Destroy.Core"(ptr %_.var.loc20), !dbg !42
  92. // CHECK:STDOUT: call void @"_COp.607f187990247af9:core.Destroy.Core"(ptr %_.var.loc18_24), !dbg !41
  93. // CHECK:STDOUT: call void @"_COp.7e389eab4a7e5487:core.Destroy.Core"(ptr %_.var.loc18_12), !dbg !40
  94. // CHECK:STDOUT: call void @"_COp.607f187990247af9:core.Destroy.Core"(ptr %_.var.loc16), !dbg !39
  95. // CHECK:STDOUT: call void @"_COp.7e389eab4a7e5487:core.Destroy.Core"(ptr %_.var.loc15), !dbg !38
  96. // CHECK:STDOUT: ret void, !dbg !50
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: ; Function Attrs: nounwind
  100. // CHECK:STDOUT: define weak_odr void @"_COp.607f187990247af9:core.Destroy.Core"(ptr %self) #0 !dbg !51 {
  101. // CHECK:STDOUT: entry:
  102. // CHECK:STDOUT: ret void, !dbg !54
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: ; Function Attrs: nounwind
  106. // CHECK:STDOUT: define weak_odr void @"_COp.7e389eab4a7e5487:core.Destroy.Core"(ptr %self) #0 !dbg !55 {
  107. // CHECK:STDOUT: entry:
  108. // CHECK:STDOUT: ret void, !dbg !58
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  112. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  115. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: ; uselistorder directives
  118. // CHECK:STDOUT: uselistorder ptr @"_COp.607f187990247af9:core.Destroy.Core", { 3, 2, 1, 0 }
  119. // CHECK:STDOUT: uselistorder ptr @"_COp.7e389eab4a7e5487:core.Destroy.Core", { 2, 1, 0 }
  120. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 6, 5, 4, 3, 2, 1, 0 }
  121. // CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 2, 1, 0 }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: attributes #0 = { nounwind }
  124. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  125. // CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  128. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  131. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  132. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  133. // CHECK:STDOUT: !3 = !DIFile(filename: "var_param.carbon", directory: "")
  134. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "OneVar_i32", linkageName: "_COneVar_i32.Main", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
  135. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  136. // CHECK:STDOUT: !6 = !{null, !7}
  137. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  138. // CHECK:STDOUT: !8 = !{!9}
  139. // CHECK:STDOUT: !9 = !DILocalVariable(arg: 1, scope: !4, type: !7)
  140. // CHECK:STDOUT: !10 = !DILocation(line: 15, column: 1, scope: !4)
  141. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "OneVar_X", linkageName: "_COneVar_X.Main", scope: null, file: !3, line: 16, type: !12, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !15)
  142. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  143. // CHECK:STDOUT: !13 = !{null, !14}
  144. // CHECK:STDOUT: !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
  145. // CHECK:STDOUT: !15 = !{!16}
  146. // CHECK:STDOUT: !16 = !DILocalVariable(arg: 1, scope: !11, type: !14)
  147. // CHECK:STDOUT: !17 = !DILocation(line: 16, column: 1, scope: !11)
  148. // CHECK:STDOUT: !18 = distinct !DISubprogram(name: "TwoVars", linkageName: "_CTwoVars.Main", scope: null, file: !3, line: 18, type: !19, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !21)
  149. // CHECK:STDOUT: !19 = !DISubroutineType(types: !20)
  150. // CHECK:STDOUT: !20 = !{null, !7, !14}
  151. // CHECK:STDOUT: !21 = !{!22, !23}
  152. // CHECK:STDOUT: !22 = !DILocalVariable(arg: 1, scope: !18, type: !7)
  153. // CHECK:STDOUT: !23 = !DILocalVariable(arg: 2, scope: !18, type: !14)
  154. // CHECK:STDOUT: !24 = !DILocation(line: 18, column: 1, scope: !18)
  155. // CHECK:STDOUT: !25 = distinct !DISubprogram(name: "VarThenLet", linkageName: "_CVarThenLet.Main", scope: null, file: !3, line: 20, type: !19, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !26)
  156. // CHECK:STDOUT: !26 = !{!27, !28}
  157. // CHECK:STDOUT: !27 = !DILocalVariable(arg: 1, scope: !25, type: !7)
  158. // CHECK:STDOUT: !28 = !DILocalVariable(arg: 2, scope: !25, type: !14)
  159. // CHECK:STDOUT: !29 = !DILocation(line: 20, column: 1, scope: !25)
  160. // CHECK:STDOUT: !30 = distinct !DISubprogram(name: "LetThenVar", linkageName: "_CLetThenVar.Main", scope: null, file: !3, line: 21, type: !19, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !31)
  161. // CHECK:STDOUT: !31 = !{!32, !33}
  162. // CHECK:STDOUT: !32 = !DILocalVariable(arg: 1, scope: !30, type: !7)
  163. // CHECK:STDOUT: !33 = !DILocalVariable(arg: 2, scope: !30, type: !14)
  164. // CHECK:STDOUT: !34 = !DILocation(line: 21, column: 1, scope: !30)
  165. // CHECK:STDOUT: !35 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !3, line: 23, type: !36, spFlags: DISPFlagDefinition, unit: !2)
  166. // CHECK:STDOUT: !36 = !DISubroutineType(types: !37)
  167. // CHECK:STDOUT: !37 = !{null}
  168. // CHECK:STDOUT: !38 = !DILocation(line: 15, column: 15, scope: !35)
  169. // CHECK:STDOUT: !39 = !DILocation(line: 16, column: 13, scope: !35)
  170. // CHECK:STDOUT: !40 = !DILocation(line: 18, column: 12, scope: !35)
  171. // CHECK:STDOUT: !41 = !DILocation(line: 18, column: 24, scope: !35)
  172. // CHECK:STDOUT: !42 = !DILocation(line: 20, column: 15, scope: !35)
  173. // CHECK:STDOUT: !43 = !DILocation(line: 27, column: 17, scope: !35)
  174. // CHECK:STDOUT: !44 = !DILocation(line: 21, column: 23, scope: !35)
  175. // CHECK:STDOUT: !45 = !DILocation(line: 24, column: 3, scope: !35)
  176. // CHECK:STDOUT: !46 = !DILocation(line: 25, column: 3, scope: !35)
  177. // CHECK:STDOUT: !47 = !DILocation(line: 26, column: 3, scope: !35)
  178. // CHECK:STDOUT: !48 = !DILocation(line: 27, column: 3, scope: !35)
  179. // CHECK:STDOUT: !49 = !DILocation(line: 28, column: 3, scope: !35)
  180. // CHECK:STDOUT: !50 = !DILocation(line: 23, column: 1, scope: !35)
  181. // CHECK:STDOUT: !51 = distinct !DISubprogram(name: "Op", linkageName: "_COp.607f187990247af9:core.Destroy.Core", scope: null, file: !3, line: 21, type: !12, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !52)
  182. // CHECK:STDOUT: !52 = !{!53}
  183. // CHECK:STDOUT: !53 = !DILocalVariable(arg: 1, scope: !51, type: !14)
  184. // CHECK:STDOUT: !54 = !DILocation(line: 21, column: 23, scope: !51)
  185. // CHECK:STDOUT: !55 = distinct !DISubprogram(name: "Op", linkageName: "_COp.7e389eab4a7e5487:core.Destroy.Core", scope: null, file: !3, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !56)
  186. // CHECK:STDOUT: !56 = !{!57}
  187. // CHECK:STDOUT: !57 = !DILocalVariable(arg: 1, scope: !55, type: !7)
  188. // CHECK:STDOUT: !58 = !DILocation(line: 20, column: 15, scope: !55)