|
|
@@ -0,0 +1,81 @@
|
|
|
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
|
+// Exceptions. See /LICENSE for license information.
|
|
|
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
+//
|
|
|
+// AUTOUPDATE
|
|
|
+// TIP: To test this file alone, run:
|
|
|
+// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/class/convert.carbon
|
|
|
+// TIP: To dump output, run:
|
|
|
+// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/class/convert.carbon
|
|
|
+
|
|
|
+class IntWrapper {
|
|
|
+ var n: i32;
|
|
|
+}
|
|
|
+
|
|
|
+impl IntWrapper as Core.ImplicitAs(i32) {
|
|
|
+ fn Convert[self: Self]() -> i32 { return self.n; }
|
|
|
+}
|
|
|
+
|
|
|
+fn Consume(n: i32) {}
|
|
|
+
|
|
|
+fn DoIt() {
|
|
|
+ var w: IntWrapper = {.n = 42};
|
|
|
+ Consume(w);
|
|
|
+}
|
|
|
+
|
|
|
+// CHECK:STDOUT: ; ModuleID = 'convert.carbon'
|
|
|
+// CHECK:STDOUT: source_filename = "convert.carbon"
|
|
|
+// CHECK:STDOUT:
|
|
|
+// CHECK:STDOUT: @struct.loc22_32 = internal constant { i32 } { i32 42 }
|
|
|
+// CHECK:STDOUT:
|
|
|
+// CHECK:STDOUT: define i32 @"_CConvert.IntWrapper.Main:ImplicitAs.Core"(ptr %self) !dbg !4 {
|
|
|
+// CHECK:STDOUT: entry:
|
|
|
+// CHECK:STDOUT: %.loc16_48.1.n = getelementptr inbounds nuw { i32 }, ptr %self, i32 0, i32 0, !dbg !7
|
|
|
+// CHECK:STDOUT: %.loc16_48.2 = load i32, ptr %.loc16_48.1.n, align 4, !dbg !7
|
|
|
+// CHECK:STDOUT: ret i32 %.loc16_48.2, !dbg !8
|
|
|
+// CHECK:STDOUT: }
|
|
|
+// CHECK:STDOUT:
|
|
|
+// CHECK:STDOUT: define void @_CConsume.Main(i32 %n) !dbg !9 {
|
|
|
+// CHECK:STDOUT: entry:
|
|
|
+// CHECK:STDOUT: ret void, !dbg !10
|
|
|
+// CHECK:STDOUT: }
|
|
|
+// CHECK:STDOUT:
|
|
|
+// CHECK:STDOUT: define void @_CDoIt.Main() !dbg !11 {
|
|
|
+// CHECK:STDOUT: entry:
|
|
|
+// CHECK:STDOUT: %w.var = alloca { i32 }, align 8, !dbg !12
|
|
|
+// CHECK:STDOUT: %.loc22_31.2.n = getelementptr inbounds nuw { i32 }, ptr %w.var, i32 0, i32 0, !dbg !13
|
|
|
+// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %w.var, ptr align 4 @struct.loc22_32, i64 4, i1 false), !dbg !14
|
|
|
+// CHECK:STDOUT: %Convert.call = call i32 @"_CConvert.IntWrapper.Main:ImplicitAs.Core"(ptr %w.var), !dbg !15
|
|
|
+// CHECK:STDOUT: %.loc23_11.6.temp = alloca i32, align 4, !dbg !15
|
|
|
+// CHECK:STDOUT: store i32 %Convert.call, ptr %.loc23_11.6.temp, align 4, !dbg !15
|
|
|
+// CHECK:STDOUT: %.loc23_11.8 = load i32, ptr %.loc23_11.6.temp, align 4, !dbg !15
|
|
|
+// CHECK:STDOUT: call void @_CConsume.Main(i32 %.loc23_11.8), !dbg !16
|
|
|
+// CHECK:STDOUT: ret void, !dbg !17
|
|
|
+// CHECK:STDOUT: }
|
|
|
+// CHECK:STDOUT:
|
|
|
+// CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
|
|
|
+// CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0
|
|
|
+// CHECK:STDOUT:
|
|
|
+// CHECK:STDOUT: attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
|
|
|
+// CHECK:STDOUT:
|
|
|
+// CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
|
|
|
+// CHECK:STDOUT: !llvm.dbg.cu = !{!2}
|
|
|
+// CHECK:STDOUT:
|
|
|
+// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
|
|
|
+// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
|
|
|
+// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
|
+// CHECK:STDOUT: !3 = !DIFile(filename: "convert.carbon", directory: "")
|
|
|
+// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.IntWrapper.Main:ImplicitAs.Core", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
|
+// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
|
|
|
+// CHECK:STDOUT: !6 = !{}
|
|
|
+// CHECK:STDOUT: !7 = !DILocation(line: 16, column: 44, scope: !4)
|
|
|
+// CHECK:STDOUT: !8 = !DILocation(line: 16, column: 37, scope: !4)
|
|
|
+// CHECK:STDOUT: !9 = distinct !DISubprogram(name: "Consume", linkageName: "_CConsume.Main", scope: null, file: !3, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
|
+// CHECK:STDOUT: !10 = !DILocation(line: 19, column: 1, scope: !9)
|
|
|
+// CHECK:STDOUT: !11 = distinct !DISubprogram(name: "DoIt", linkageName: "_CDoIt.Main", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
|
+// CHECK:STDOUT: !12 = !DILocation(line: 22, column: 7, scope: !11)
|
|
|
+// CHECK:STDOUT: !13 = !DILocation(line: 22, column: 23, scope: !11)
|
|
|
+// CHECK:STDOUT: !14 = !DILocation(line: 22, column: 3, scope: !11)
|
|
|
+// CHECK:STDOUT: !15 = !DILocation(line: 23, column: 11, scope: !11)
|
|
|
+// CHECK:STDOUT: !16 = !DILocation(line: 23, column: 3, scope: !11)
|
|
|
+// CHECK:STDOUT: !17 = !DILocation(line: 21, column: 1, scope: !11)
|