maybe_unformed.carbon 5.0 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/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/builtins/maybe_unformed.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/builtins/maybe_unformed.carbon
  12. fn MaybeUnformedBuiltin(t: type) -> type = "maybe_unformed.make_type";
  13. fn TakeBuiltin(x: MaybeUnformedBuiltin(i32)) {}
  14. fn MakeBuiltin() -> MaybeUnformedBuiltin(i32);
  15. fn PassBuiltin() {
  16. // This is passed by pointer even though `i32` would generally be passed in
  17. // registers.
  18. TakeBuiltin(MakeBuiltin());
  19. }
  20. // Also test that an adapter wrapped around the builtin behaves the same.
  21. class MaybeUnformedAdapter(T:! type) {
  22. adapt MaybeUnformedBuiltin(T);
  23. }
  24. fn TakeAdapter(x: MaybeUnformedAdapter(i32)) {}
  25. fn MakeAdapter() -> MaybeUnformedAdapter(i32);
  26. fn PassAdapter() {
  27. TakeAdapter(MakeAdapter());
  28. }
  29. // CHECK:STDOUT: ; ModuleID = 'maybe_unformed.carbon'
  30. // CHECK:STDOUT: source_filename = "maybe_unformed.carbon"
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: define void @_CTakeBuiltin.Main(ptr %x) !dbg !4 {
  33. // CHECK:STDOUT: entry:
  34. // CHECK:STDOUT: ret void, !dbg !7
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: declare void @_CMakeBuiltin.Main(ptr sret(i32))
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: define void @_CPassBuiltin.Main() !dbg !8 {
  40. // CHECK:STDOUT: entry:
  41. // CHECK:STDOUT: %.loc21_27.1.temp = alloca i32, align 4, !dbg !9
  42. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc21_27.1.temp), !dbg !9
  43. // CHECK:STDOUT: call void @_CMakeBuiltin.Main(ptr %.loc21_27.1.temp), !dbg !9
  44. // CHECK:STDOUT: call void @_CTakeBuiltin.Main(ptr %.loc21_27.1.temp), !dbg !10
  45. // CHECK:STDOUT: ret void, !dbg !11
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: define void @_CTakeAdapter.Main(ptr %x) !dbg !12 {
  49. // CHECK:STDOUT: entry:
  50. // CHECK:STDOUT: ret void, !dbg !13
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: declare void @_CMakeAdapter.Main(ptr sret(i32))
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: define void @_CPassAdapter.Main() !dbg !14 {
  56. // CHECK:STDOUT: entry:
  57. // CHECK:STDOUT: %.loc34_27.1.temp = alloca i32, align 4, !dbg !15
  58. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc34_27.1.temp), !dbg !15
  59. // CHECK:STDOUT: call void @_CMakeAdapter.Main(ptr %.loc34_27.1.temp), !dbg !15
  60. // CHECK:STDOUT: call void @_CTakeAdapter.Main(ptr %.loc34_27.1.temp), !dbg !16
  61. // CHECK:STDOUT: ret void, !dbg !17
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  65. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #0
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: ; uselistorder directives
  68. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 1, 0 }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  73. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  76. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  77. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  78. // CHECK:STDOUT: !3 = !DIFile(filename: "maybe_unformed.carbon", directory: "")
  79. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "TakeBuiltin", linkageName: "_CTakeBuiltin.Main", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  80. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  81. // CHECK:STDOUT: !6 = !{}
  82. // CHECK:STDOUT: !7 = !DILocation(line: 15, column: 1, scope: !4)
  83. // CHECK:STDOUT: !8 = distinct !DISubprogram(name: "PassBuiltin", linkageName: "_CPassBuiltin.Main", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  84. // CHECK:STDOUT: !9 = !DILocation(line: 21, column: 15, scope: !8)
  85. // CHECK:STDOUT: !10 = !DILocation(line: 21, column: 3, scope: !8)
  86. // CHECK:STDOUT: !11 = !DILocation(line: 18, column: 1, scope: !8)
  87. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "TakeAdapter", linkageName: "_CTakeAdapter.Main", scope: null, file: !3, line: 30, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  88. // CHECK:STDOUT: !13 = !DILocation(line: 30, column: 1, scope: !12)
  89. // CHECK:STDOUT: !14 = distinct !DISubprogram(name: "PassAdapter", linkageName: "_CPassAdapter.Main", scope: null, file: !3, line: 33, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  90. // CHECK:STDOUT: !15 = !DILocation(line: 34, column: 15, scope: !14)
  91. // CHECK:STDOUT: !16 = !DILocation(line: 34, column: 3, scope: !14)
  92. // CHECK:STDOUT: !17 = !DILocation(line: 33, column: 1, scope: !14)