convert.carbon 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/class/convert.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/class/convert.carbon
  12. class IntWrapper {
  13. var n: i32;
  14. }
  15. impl IntWrapper as Core.ImplicitAs(i32) {
  16. fn Convert[self: Self]() -> i32 { return self.n; }
  17. }
  18. fn Consume(n: i32) {}
  19. fn DoIt() {
  20. var w: IntWrapper = {.n = 42};
  21. Consume(w);
  22. }
  23. // CHECK:STDOUT: ; ModuleID = 'convert.carbon'
  24. // CHECK:STDOUT: source_filename = "convert.carbon"
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: @IntWrapper.val.loc24_3 = internal constant { i32 } { i32 42 }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: ; Function Attrs: nounwind
  29. // CHECK:STDOUT: define i32 @"_CConvert.IntWrapper.Main:ImplicitAs.Core"(ptr %self) #0 !dbg !4 {
  30. // CHECK:STDOUT: entry:
  31. // CHECK:STDOUT: %.loc18_48.1.n = getelementptr inbounds nuw { i32 }, ptr %self, i32 0, i32 0, !dbg !7
  32. // CHECK:STDOUT: %.loc18_48.2 = load i32, ptr %.loc18_48.1.n, align 4, !dbg !7
  33. // CHECK:STDOUT: ret i32 %.loc18_48.2, !dbg !8
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: ; Function Attrs: nounwind
  37. // CHECK:STDOUT: define void @_CConsume.Main(i32 %n) #0 !dbg !9 {
  38. // CHECK:STDOUT: entry:
  39. // CHECK:STDOUT: ret void, !dbg !10
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: ; Function Attrs: nounwind
  43. // CHECK:STDOUT: define void @_CDoIt.Main() #0 !dbg !11 {
  44. // CHECK:STDOUT: entry:
  45. // CHECK:STDOUT: %w.var = alloca { i32 }, align 8, !dbg !12
  46. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %w.var), !dbg !12
  47. // CHECK:STDOUT: %.loc24_31.3.n = getelementptr inbounds nuw { i32 }, ptr %w.var, i32 0, i32 0, !dbg !13
  48. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %w.var, ptr align 4 @IntWrapper.val.loc24_3, i64 4, i1 false), !dbg !12
  49. // CHECK:STDOUT: %IntWrapper.as.ImplicitAs.impl.Convert.call = call i32 @"_CConvert.IntWrapper.Main:ImplicitAs.Core"(ptr %w.var), !dbg !14
  50. // CHECK:STDOUT: call void @_CConsume.Main(i32 %IntWrapper.as.ImplicitAs.impl.Convert.call), !dbg !15
  51. // CHECK:STDOUT: ret void, !dbg !16
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  55. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  58. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  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: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  65. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  68. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  69. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  70. // CHECK:STDOUT: !3 = !DIFile(filename: "convert.carbon", directory: "")
  71. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.IntWrapper.Main:ImplicitAs.Core", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  72. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  73. // CHECK:STDOUT: !6 = !{}
  74. // CHECK:STDOUT: !7 = !DILocation(line: 18, column: 44, scope: !4)
  75. // CHECK:STDOUT: !8 = !DILocation(line: 18, column: 37, scope: !4)
  76. // CHECK:STDOUT: !9 = distinct !DISubprogram(name: "Consume", linkageName: "_CConsume.Main", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  77. // CHECK:STDOUT: !10 = !DILocation(line: 21, column: 1, scope: !9)
  78. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "DoIt", linkageName: "_CDoIt.Main", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  79. // CHECK:STDOUT: !12 = !DILocation(line: 24, column: 3, scope: !11)
  80. // CHECK:STDOUT: !13 = !DILocation(line: 24, column: 23, scope: !11)
  81. // CHECK:STDOUT: !14 = !DILocation(line: 25, column: 11, scope: !11)
  82. // CHECK:STDOUT: !15 = !DILocation(line: 25, column: 3, scope: !11)
  83. // CHECK:STDOUT: !16 = !DILocation(line: 23, column: 1, scope: !11)