var_param.carbon 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 n: i32) {}
  14. fn OneVar_X(var x: X) {}
  15. fn TwoVars(var a: i32, var b: X) {}
  16. fn VarThenLet(var a: i32, b: X) {}
  17. fn LetThenVar(a: i32, var b: 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.loc16_13.2 = internal constant {} zeroinitializer
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: ; Function Attrs: nounwind
  31. // CHECK:STDOUT: define void @_COneVar_i32.Main(ptr %n) #0 !dbg !4 {
  32. // CHECK:STDOUT: entry:
  33. // CHECK:STDOUT: ret void, !dbg !7
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: ; Function Attrs: nounwind
  37. // CHECK:STDOUT: define void @_COneVar_X.Main(ptr %x) #0 !dbg !8 {
  38. // CHECK:STDOUT: entry:
  39. // CHECK:STDOUT: ret void, !dbg !9
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: ; Function Attrs: nounwind
  43. // CHECK:STDOUT: define void @_CTwoVars.Main(ptr %a, ptr %b) #0 !dbg !10 {
  44. // CHECK:STDOUT: entry:
  45. // CHECK:STDOUT: ret void, !dbg !11
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: ; Function Attrs: nounwind
  49. // CHECK:STDOUT: define void @_CVarThenLet.Main(ptr %a, ptr %b) #0 !dbg !12 {
  50. // CHECK:STDOUT: entry:
  51. // CHECK:STDOUT: ret void, !dbg !13
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: ; Function Attrs: nounwind
  55. // CHECK:STDOUT: define void @_CLetThenVar.Main(i32 %a, ptr %b) #0 !dbg !14 {
  56. // CHECK:STDOUT: entry:
  57. // CHECK:STDOUT: ret void, !dbg !15
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: ; Function Attrs: nounwind
  61. // CHECK:STDOUT: define void @_CCall.Main() #0 !dbg !16 {
  62. // CHECK:STDOUT: entry:
  63. // CHECK:STDOUT: %.loc15_15.1.temp = alloca i32, align 4, !dbg !17
  64. // CHECK:STDOUT: %.loc16_13.1.temp = alloca {}, align 8, !dbg !18
  65. // CHECK:STDOUT: %.loc18_12.1.temp = alloca i32, align 4, !dbg !19
  66. // CHECK:STDOUT: %.loc18_24.1.temp = alloca {}, align 8, !dbg !20
  67. // CHECK:STDOUT: %.loc20_15.1.temp = alloca i32, align 4, !dbg !21
  68. // CHECK:STDOUT: %.loc27_18.2.temp = alloca {}, align 8, !dbg !22
  69. // CHECK:STDOUT: %.loc21_23.1.temp = alloca {}, align 8, !dbg !23
  70. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc15_15.1.temp), !dbg !17
  71. // CHECK:STDOUT: store i32 1, ptr %.loc15_15.1.temp, align 4, !dbg !17
  72. // CHECK:STDOUT: call void @_COneVar_i32.Main(ptr %.loc15_15.1.temp), !dbg !24
  73. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc16_13.1.temp), !dbg !18
  74. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.loc16_13.1.temp, ptr align 1 @X.val.loc16_13.2, i64 0, i1 false), !dbg !18
  75. // CHECK:STDOUT: call void @_COneVar_X.Main(ptr %.loc16_13.1.temp), !dbg !25
  76. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_12.1.temp), !dbg !19
  77. // CHECK:STDOUT: store i32 1, ptr %.loc18_12.1.temp, align 4, !dbg !19
  78. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_24.1.temp), !dbg !20
  79. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.loc18_24.1.temp, ptr align 1 @X.val.loc16_13.2, i64 0, i1 false), !dbg !20
  80. // CHECK:STDOUT: call void @_CTwoVars.Main(ptr %.loc18_12.1.temp, ptr %.loc18_24.1.temp), !dbg !26
  81. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc20_15.1.temp), !dbg !21
  82. // CHECK:STDOUT: store i32 1, ptr %.loc20_15.1.temp, align 4, !dbg !21
  83. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc27_18.2.temp), !dbg !22
  84. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.loc27_18.2.temp, ptr align 1 @X.val.loc16_13.2, i64 0, i1 false), !dbg !22
  85. // CHECK:STDOUT: call void @_CVarThenLet.Main(ptr %.loc20_15.1.temp, ptr %.loc27_18.2.temp), !dbg !27
  86. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc21_23.1.temp), !dbg !23
  87. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.loc21_23.1.temp, ptr align 1 @X.val.loc16_13.2, i64 0, i1 false), !dbg !23
  88. // CHECK:STDOUT: call void @_CLetThenVar.Main(i32 1, ptr %.loc21_23.1.temp), !dbg !28
  89. // CHECK:STDOUT: ret void, !dbg !29
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  93. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  96. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: ; uselistorder directives
  99. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 6, 5, 4, 3, 2, 1, 0 }
  100. // CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 3, 2, 1, 0 }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: attributes #0 = { nounwind }
  103. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  104. // CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  107. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  110. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  111. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  112. // CHECK:STDOUT: !3 = !DIFile(filename: "var_param.carbon", directory: "")
  113. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "OneVar_i32", linkageName: "_COneVar_i32.Main", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  114. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  115. // CHECK:STDOUT: !6 = !{}
  116. // CHECK:STDOUT: !7 = !DILocation(line: 15, column: 1, scope: !4)
  117. // CHECK:STDOUT: !8 = distinct !DISubprogram(name: "OneVar_X", linkageName: "_COneVar_X.Main", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  118. // CHECK:STDOUT: !9 = !DILocation(line: 16, column: 1, scope: !8)
  119. // CHECK:STDOUT: !10 = distinct !DISubprogram(name: "TwoVars", linkageName: "_CTwoVars.Main", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  120. // CHECK:STDOUT: !11 = !DILocation(line: 18, column: 1, scope: !10)
  121. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "VarThenLet", linkageName: "_CVarThenLet.Main", scope: null, file: !3, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  122. // CHECK:STDOUT: !13 = !DILocation(line: 20, column: 1, scope: !12)
  123. // CHECK:STDOUT: !14 = distinct !DISubprogram(name: "LetThenVar", linkageName: "_CLetThenVar.Main", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  124. // CHECK:STDOUT: !15 = !DILocation(line: 21, column: 1, scope: !14)
  125. // CHECK:STDOUT: !16 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  126. // CHECK:STDOUT: !17 = !DILocation(line: 15, column: 15, scope: !16)
  127. // CHECK:STDOUT: !18 = !DILocation(line: 16, column: 13, scope: !16)
  128. // CHECK:STDOUT: !19 = !DILocation(line: 18, column: 12, scope: !16)
  129. // CHECK:STDOUT: !20 = !DILocation(line: 18, column: 24, scope: !16)
  130. // CHECK:STDOUT: !21 = !DILocation(line: 20, column: 15, scope: !16)
  131. // CHECK:STDOUT: !22 = !DILocation(line: 27, column: 17, scope: !16)
  132. // CHECK:STDOUT: !23 = !DILocation(line: 21, column: 23, scope: !16)
  133. // CHECK:STDOUT: !24 = !DILocation(line: 24, column: 3, scope: !16)
  134. // CHECK:STDOUT: !25 = !DILocation(line: 25, column: 3, scope: !16)
  135. // CHECK:STDOUT: !26 = !DILocation(line: 26, column: 3, scope: !16)
  136. // CHECK:STDOUT: !27 = !DILocation(line: 27, column: 3, scope: !16)
  137. // CHECK:STDOUT: !28 = !DILocation(line: 28, column: 3, scope: !16)
  138. // CHECK:STDOUT: !29 = !DILocation(line: 23, column: 1, scope: !16)