function_param.carbon 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/array/function_param.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/array/function_param.carbon
  12. fn F(arr: array(i32, 3), i: i32) -> i32 {
  13. return arr[i];
  14. }
  15. fn G() -> i32 {
  16. return F((1, 2, 3), 1);
  17. }
  18. // CHECK:STDOUT: ; ModuleID = 'function_param.carbon'
  19. // CHECK:STDOUT: source_filename = "function_param.carbon"
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: @array = internal constant [3 x i32] [i32 1, i32 2, i32 3]
  22. // CHECK:STDOUT: @array.loc18_20.15 = internal constant [3 x i32] [i32 1, i32 2, i32 3]
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: ; Function Attrs: nounwind
  25. // CHECK:STDOUT: define i32 @_CF.Main(ptr %arr, i32 %i) #0 !dbg !4 {
  26. // CHECK:STDOUT: entry:
  27. // CHECK:STDOUT: %.loc14_15.2.array.index = getelementptr inbounds [3 x i32], ptr %arr, i32 0, i32 %i, !dbg !12
  28. // CHECK:STDOUT: %.loc14_15.3 = load i32, ptr %.loc14_15.2.array.index, align 4, !dbg !12
  29. // CHECK:STDOUT: ret i32 %.loc14_15.3, !dbg !13
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: ; Function Attrs: nounwind
  33. // CHECK:STDOUT: define i32 @_CG.Main() #0 !dbg !14 {
  34. // CHECK:STDOUT: entry:
  35. // CHECK:STDOUT: %.loc18_20.3.temp = alloca [3 x i32], align 4, !dbg !17
  36. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_20.3.temp), !dbg !17
  37. // CHECK:STDOUT: %.loc18_20.4.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_20.3.temp, i32 0, i64 0, !dbg !17
  38. // CHECK:STDOUT: %.loc18_20.7.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_20.3.temp, i32 0, i64 1, !dbg !17
  39. // CHECK:STDOUT: %.loc18_20.10.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_20.3.temp, i32 0, i64 2, !dbg !17
  40. // CHECK:STDOUT: %F.call = call i32 @_CF.Main(ptr @array.loc18_20.15, i32 1), !dbg !18
  41. // CHECK:STDOUT: call void @"_COp.bfd302cd235977c4:core.Destroy.Core"(ptr @array), !dbg !17
  42. // CHECK:STDOUT: ret i32 %F.call, !dbg !19
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: ; Function Attrs: nounwind
  46. // CHECK:STDOUT: define weak_odr void @"_COp.7e389eab4a7e5487:core.Destroy.Core"(ptr %self) #0 !dbg !20 {
  47. // CHECK:STDOUT: entry:
  48. // CHECK:STDOUT: ret void, !dbg !25
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: ; Function Attrs: nounwind
  52. // CHECK:STDOUT: define weak_odr void @"_COp.bfd302cd235977c4:core.Destroy.Core"(ptr %self) #0 !dbg !26 {
  53. // CHECK:STDOUT: entry:
  54. // CHECK:STDOUT: ret void, !dbg !31
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  58. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: attributes #0 = { nounwind }
  61. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  64. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  67. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  68. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  69. // CHECK:STDOUT: !3 = !DIFile(filename: "function_param.carbon", directory: "")
  70. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !9)
  71. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  72. // CHECK:STDOUT: !6 = !{!7, !8, !7}
  73. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  74. // CHECK:STDOUT: !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
  75. // CHECK:STDOUT: !9 = !{!10, !11}
  76. // CHECK:STDOUT: !10 = !DILocalVariable(arg: 1, scope: !4, type: !8)
  77. // CHECK:STDOUT: !11 = !DILocalVariable(arg: 2, scope: !4, type: !7)
  78. // CHECK:STDOUT: !12 = !DILocation(line: 14, column: 10, scope: !4)
  79. // CHECK:STDOUT: !13 = !DILocation(line: 14, column: 3, scope: !4)
  80. // CHECK:STDOUT: !14 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main", scope: null, file: !3, line: 17, type: !15, spFlags: DISPFlagDefinition, unit: !2)
  81. // CHECK:STDOUT: !15 = !DISubroutineType(types: !16)
  82. // CHECK:STDOUT: !16 = !{!7}
  83. // CHECK:STDOUT: !17 = !DILocation(line: 18, column: 12, scope: !14)
  84. // CHECK:STDOUT: !18 = !DILocation(line: 18, column: 10, scope: !14)
  85. // CHECK:STDOUT: !19 = !DILocation(line: 18, column: 3, scope: !14)
  86. // CHECK:STDOUT: !20 = distinct !DISubprogram(name: "Op", linkageName: "_COp.7e389eab4a7e5487:core.Destroy.Core", scope: null, file: !3, line: 18, type: !21, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !23)
  87. // CHECK:STDOUT: !21 = !DISubroutineType(types: !22)
  88. // CHECK:STDOUT: !22 = !{null, !7}
  89. // CHECK:STDOUT: !23 = !{!24}
  90. // CHECK:STDOUT: !24 = !DILocalVariable(arg: 1, scope: !20, type: !7)
  91. // CHECK:STDOUT: !25 = !DILocation(line: 18, column: 12, scope: !20)
  92. // CHECK:STDOUT: !26 = distinct !DISubprogram(name: "Op", linkageName: "_COp.bfd302cd235977c4:core.Destroy.Core", scope: null, file: !3, line: 18, type: !27, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !29)
  93. // CHECK:STDOUT: !27 = !DISubroutineType(types: !28)
  94. // CHECK:STDOUT: !28 = !{null, !8}
  95. // CHECK:STDOUT: !29 = !{!30}
  96. // CHECK:STDOUT: !30 = !DILocalVariable(arg: 1, scope: !26, type: !8)
  97. // CHECK:STDOUT: !31 = !DILocation(line: 18, column: 12, scope: !26)