mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 20:10:28 +00:00
Determining that a type has trivial destruction requires checking whether all of its subobjects have trivial destruction and whether its type has a custom witness for `Destroy.Op`. This isn't possible when `Destroy` is the custodian for `Destroy.Op` and `SubobjectDestroy.Op`, so we need to make `SubobjectDestroy` its own interface. `Destroy.SelfDestruct` becomes a standalone function because it depends on `SubobjectDestroy` and `Destroy` being implemented, and is also responsible for generating any custom witnesses for both interfaces. Making `SelfDestruct` an interface was experimented with, but this required a blanket impl that caused issues for facet types. `Destroy` depends on `SubobjectDestroy` to be implemented. We'd ideally use `require impls SubobjectDestroy`, but it isn't complete yet, and it also causes problems when `Destroy` is implemented inside the class definition. We work around this by temporarily renaming the `Destroy` interface to `DestroyImpl`, and introducing a constraint called `Destroy` so that user code doesn't need to write `Core.SubobjectDestroy & Core.Destroy`.
298 lines
14 KiB
Plaintext
298 lines
14 KiB
Plaintext
// 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
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/function/definition/destroy.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/definition/destroy.carbon
|
|
|
|
// --- let_param.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {}
|
|
|
|
fn F(_: C) {
|
|
}
|
|
|
|
fn G();
|
|
|
|
fn CallF() {
|
|
F({});
|
|
G();
|
|
}
|
|
|
|
// --- var_param.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {}
|
|
|
|
fn F(var _: C) {
|
|
}
|
|
|
|
fn G();
|
|
|
|
fn CallF() {
|
|
F({});
|
|
G();
|
|
}
|
|
|
|
// --- return_slot.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {}
|
|
|
|
fn F() -> C {
|
|
return {};
|
|
}
|
|
|
|
fn G();
|
|
|
|
fn Forward() -> C {
|
|
return F();
|
|
}
|
|
|
|
fn InitVar() {
|
|
var _: C = F();
|
|
G();
|
|
}
|
|
|
|
fn InitLet() {
|
|
let _: C = F();
|
|
G();
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ---
|
|
// CHECK:STDOUT: ; ModuleID = 'let_param.carbon'
|
|
// CHECK:STDOUT: source_filename = "let_param.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: @C.val = internal constant {} zeroinitializer
|
|
// CHECK:STDOUT: @C.val.loc12_6.6 = internal constant {} zeroinitializer
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CF.Main(ptr %_) #0 !dbg !21 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret void, !dbg !24
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: declare void @_CG.Main()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CCallF.Main() #0 !dbg !26 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %.loc12_6.2.temp = alloca {}, align 1, !dbg !27
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc12_6.2.temp), !dbg !27
|
|
// CHECK:STDOUT: call void @_CF.Main(ptr @C.val.loc12_6.6), !dbg !28
|
|
// CHECK:STDOUT: call void @_CSelfDestruct.Core.356af3b6aef18564(ptr @C.val), !dbg !27
|
|
// CHECK:STDOUT: call void @_CG.Main(), !dbg !29
|
|
// CHECK:STDOUT: ret void, !dbg !30
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
|
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define linkonce_odr void @_CSelfDestruct.Core.356af3b6aef18564(ptr %t) #0 !dbg !31 {
|
|
// CHECK:STDOUT: ret void, !dbg !36
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: attributes #0 = { nounwind }
|
|
// CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !llvm.dbg.cu = !{!15}
|
|
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
|
|
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
|
|
// CHECK:STDOUT: !6 = !DIFile(filename: "min_prelude/parts/destroy.carbon", directory: "")
|
|
// CHECK:STDOUT: !14 = !DIFile(filename: "let_param.carbon", directory: "")
|
|
// CHECK:STDOUT: !15 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !14, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
|
|
// CHECK:STDOUT: !17 = !{null, !16}
|
|
// CHECK:STDOUT: !18 = !DISubroutineType(types: !17)
|
|
// CHECK:STDOUT: !19 = !{null}
|
|
// CHECK:STDOUT: !20 = !DISubroutineType(types: !19)
|
|
// CHECK:STDOUT: !21 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !14, line: 6, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !25)
|
|
// CHECK:STDOUT: !22 = !DILocalVariable(arg: 1, scope: !21, type: !16)
|
|
// CHECK:STDOUT: !24 = !DILocation(line: 6, column: 1, scope: !21)
|
|
// CHECK:STDOUT: !25 = !{!22}
|
|
// CHECK:STDOUT: !26 = distinct !DISubprogram(name: "CallF", linkageName: "_CCallF.Main", scope: null, file: !14, line: 11, type: !20, spFlags: DISPFlagDefinition, unit: !15)
|
|
// CHECK:STDOUT: !27 = !DILocation(line: 12, column: 5, scope: !26)
|
|
// CHECK:STDOUT: !28 = !DILocation(line: 12, column: 3, scope: !26)
|
|
// CHECK:STDOUT: !29 = !DILocation(line: 13, column: 3, scope: !26)
|
|
// CHECK:STDOUT: !30 = !DILocation(line: 11, column: 1, scope: !26)
|
|
// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.Core.356af3b6aef18564", scope: null, file: !6, line: 32, type: !18, spFlags: DISPFlagDefinition, unit: !15, retainedNodes: !37)
|
|
// CHECK:STDOUT: !32 = !DILocalVariable(arg: 1, scope: !31, type: !16)
|
|
// CHECK:STDOUT: !36 = !DILocation(line: 32, column: 1, scope: !31)
|
|
// CHECK:STDOUT: !37 = !{!32}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; ---
|
|
// CHECK:STDOUT: ; ModuleID = 'var_param.carbon'
|
|
// CHECK:STDOUT: source_filename = "var_param.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: @C.val.loc6_6.1 = internal constant {} zeroinitializer
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CF.Main(ptr %_) #0 !dbg !40 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret void, !dbg !44
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: declare void @_CG.Main()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CCallF.Main() #0 !dbg !46 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %_.var = alloca {}, align 1, !dbg !47
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !47
|
|
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %_.var, ptr align 1 @C.val.loc6_6.1, i64 0, i1 false), !dbg !47
|
|
// CHECK:STDOUT: call void @_CF.Main(ptr %_.var), !dbg !48
|
|
// CHECK:STDOUT: call void @_CSelfDestruct.Core.356af3b6aef18564(ptr %_.var), !dbg !47
|
|
// CHECK:STDOUT: call void @_CG.Main(), !dbg !49
|
|
// CHECK:STDOUT: ret void, !dbg !50
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
|
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
|
// CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #1
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define linkonce_odr void @_CSelfDestruct.Core.356af3b6aef18564(ptr %t) #0 !dbg !51 {
|
|
// CHECK:STDOUT: ret void, !dbg !56
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: attributes #0 = { nounwind }
|
|
// CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !llvm.dbg.cu = !{!39}
|
|
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
|
|
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
|
|
// CHECK:STDOUT: !6 = !DIFile(filename: "min_prelude/parts/destroy.carbon", directory: "")
|
|
// CHECK:STDOUT: !16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
|
|
// CHECK:STDOUT: !17 = !{null, !16}
|
|
// CHECK:STDOUT: !18 = !DISubroutineType(types: !17)
|
|
// CHECK:STDOUT: !19 = !{null}
|
|
// CHECK:STDOUT: !20 = !DISubroutineType(types: !19)
|
|
// CHECK:STDOUT: !38 = !DIFile(filename: "var_param.carbon", directory: "")
|
|
// CHECK:STDOUT: !39 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !38, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !40 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !38, line: 6, type: !18, spFlags: DISPFlagDefinition, unit: !39, retainedNodes: !45)
|
|
// CHECK:STDOUT: !41 = !DILocalVariable(arg: 1, scope: !40, type: !16)
|
|
// CHECK:STDOUT: !44 = !DILocation(line: 6, column: 1, scope: !40)
|
|
// CHECK:STDOUT: !45 = !{!41}
|
|
// CHECK:STDOUT: !46 = distinct !DISubprogram(name: "CallF", linkageName: "_CCallF.Main", scope: null, file: !38, line: 11, type: !20, spFlags: DISPFlagDefinition, unit: !39)
|
|
// CHECK:STDOUT: !47 = !DILocation(line: 6, column: 6, scope: !46)
|
|
// CHECK:STDOUT: !48 = !DILocation(line: 12, column: 3, scope: !46)
|
|
// CHECK:STDOUT: !49 = !DILocation(line: 13, column: 3, scope: !46)
|
|
// CHECK:STDOUT: !50 = !DILocation(line: 11, column: 1, scope: !46)
|
|
// CHECK:STDOUT: !51 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.Core.356af3b6aef18564", scope: null, file: !6, line: 32, type: !18, spFlags: DISPFlagDefinition, unit: !39, retainedNodes: !57)
|
|
// CHECK:STDOUT: !52 = !DILocalVariable(arg: 1, scope: !51, type: !16)
|
|
// CHECK:STDOUT: !56 = !DILocation(line: 32, column: 1, scope: !51)
|
|
// CHECK:STDOUT: !57 = !{!52}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; ---
|
|
// CHECK:STDOUT: ; ModuleID = 'return_slot.carbon'
|
|
// CHECK:STDOUT: source_filename = "return_slot.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: @C.val.loc7_12 = internal constant {} zeroinitializer
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CF.Main(ptr sret({}) %return) #0 !dbg !62 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %return, ptr align 1 @C.val.loc7_12, i64 0, i1 false), !dbg !65
|
|
// CHECK:STDOUT: ret void, !dbg !65
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: declare void @_CG.Main()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CForward.Main(ptr sret({}) %return) #0 !dbg !66 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: call void @_CF.Main(ptr %return), !dbg !69
|
|
// CHECK:STDOUT: ret void, !dbg !70
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CInitVar.Main() #0 !dbg !71 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %_.var = alloca {}, align 1, !dbg !72
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !72
|
|
// CHECK:STDOUT: call void @_CF.Main(ptr %_.var), !dbg !73
|
|
// CHECK:STDOUT: call void @_CG.Main(), !dbg !75
|
|
// CHECK:STDOUT: call void @_CSelfDestruct.Core.356af3b6aef18564(ptr %_.var), !dbg !72
|
|
// CHECK:STDOUT: ret void, !dbg !76
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CInitLet.Main() #0 !dbg !77 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %.loc22_16.1.temp = alloca {}, align 1, !dbg !78
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc22_16.1.temp), !dbg !78
|
|
// CHECK:STDOUT: call void @_CF.Main(ptr %.loc22_16.1.temp), !dbg !78
|
|
// CHECK:STDOUT: call void @_CG.Main(), !dbg !81
|
|
// CHECK:STDOUT: call void @_CSelfDestruct.Core.356af3b6aef18564(ptr %.loc22_16.1.temp), !dbg !78
|
|
// CHECK:STDOUT: ret void, !dbg !82
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
|
// CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #1
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
|
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define linkonce_odr void @_CSelfDestruct.Core.356af3b6aef18564(ptr %t) #0 !dbg !83 {
|
|
// CHECK:STDOUT: ret void, !dbg !88
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; uselistorder directives
|
|
// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 1, 0 }
|
|
// CHECK:STDOUT: uselistorder ptr @_CSelfDestruct.Core.356af3b6aef18564, { 1, 0 }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: attributes #0 = { nounwind }
|
|
// CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !llvm.dbg.cu = !{!59}
|
|
// CHECK:STDOUT: !llvm.module.flags = !{!2, !3}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !2 = !{i32 7, !"Dwarf Version", i32 5}
|
|
// CHECK:STDOUT: !3 = !{i32 2, !"Debug Info Version", i32 3}
|
|
// CHECK:STDOUT: !6 = !DIFile(filename: "min_prelude/parts/destroy.carbon", directory: "")
|
|
// CHECK:STDOUT: !16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
|
|
// CHECK:STDOUT: !17 = !{null, !16}
|
|
// CHECK:STDOUT: !18 = !DISubroutineType(types: !17)
|
|
// CHECK:STDOUT: !19 = !{null}
|
|
// CHECK:STDOUT: !20 = !DISubroutineType(types: !19)
|
|
// CHECK:STDOUT: !58 = !DIFile(filename: "return_slot.carbon", directory: "")
|
|
// CHECK:STDOUT: !59 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !58, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !60 = !{!16}
|
|
// CHECK:STDOUT: !61 = !DISubroutineType(types: !60)
|
|
// CHECK:STDOUT: !62 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !58, line: 6, type: !61, spFlags: DISPFlagDefinition, unit: !59)
|
|
// CHECK:STDOUT: !65 = !DILocation(line: 7, column: 3, scope: !62)
|
|
// CHECK:STDOUT: !66 = distinct !DISubprogram(name: "Forward", linkageName: "_CForward.Main", scope: null, file: !58, line: 12, type: !61, spFlags: DISPFlagDefinition, unit: !59)
|
|
// CHECK:STDOUT: !69 = !DILocation(line: 13, column: 10, scope: !66)
|
|
// CHECK:STDOUT: !70 = !DILocation(line: 13, column: 3, scope: !66)
|
|
// CHECK:STDOUT: !71 = distinct !DISubprogram(name: "InitVar", linkageName: "_CInitVar.Main", scope: null, file: !58, line: 16, type: !20, spFlags: DISPFlagDefinition, unit: !59)
|
|
// CHECK:STDOUT: !72 = !DILocation(line: 17, column: 3, scope: !71)
|
|
// CHECK:STDOUT: !73 = !DILocation(line: 17, column: 14, scope: !71)
|
|
// CHECK:STDOUT: !75 = !DILocation(line: 18, column: 3, scope: !71)
|
|
// CHECK:STDOUT: !76 = !DILocation(line: 16, column: 1, scope: !71)
|
|
// CHECK:STDOUT: !77 = distinct !DISubprogram(name: "InitLet", linkageName: "_CInitLet.Main", scope: null, file: !58, line: 21, type: !20, spFlags: DISPFlagDefinition, unit: !59)
|
|
// CHECK:STDOUT: !78 = !DILocation(line: 22, column: 14, scope: !77)
|
|
// CHECK:STDOUT: !81 = !DILocation(line: 23, column: 3, scope: !77)
|
|
// CHECK:STDOUT: !82 = !DILocation(line: 21, column: 1, scope: !77)
|
|
// CHECK:STDOUT: !83 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.Core.356af3b6aef18564", scope: null, file: !6, line: 32, type: !18, spFlags: DISPFlagDefinition, unit: !59, retainedNodes: !89)
|
|
// CHECK:STDOUT: !84 = !DILocalVariable(arg: 1, scope: !83, type: !16)
|
|
// CHECK:STDOUT: !88 = !DILocation(line: 32, column: 1, scope: !83)
|
|
// CHECK:STDOUT: !89 = !{!84}
|
|
// CHECK:STDOUT:
|