mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 00:18:16 +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`.
128 lines
7.2 KiB
Plaintext
128 lines
7.2 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/primitives.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/function/generic/call_dedup_ptr.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/call_dedup_ptr.carbon
|
|
|
|
fn F[T: Core.Copy](x: T) -> T {
|
|
return x;
|
|
}
|
|
|
|
fn M() {
|
|
var ptr_i32 : i32*;
|
|
F(ptr_i32);
|
|
var ptr_f64 : f64*;
|
|
F(ptr_f64);
|
|
var ptr_i8 : i8*;
|
|
F(ptr_i8);
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ---
|
|
// CHECK:STDOUT: ; ModuleID = 'call_dedup_ptr.carbon'
|
|
// CHECK:STDOUT: source_filename = "call_dedup_ptr.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define void @_CM.Main() #0 !dbg !38 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %ptr_i32.var = alloca ptr, align 8, !dbg !39
|
|
// CHECK:STDOUT: %ptr_f64.var = alloca ptr, align 8, !dbg !46
|
|
// CHECK:STDOUT: %ptr_i8.var = alloca ptr, align 8, !dbg !50
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %ptr_i32.var), !dbg !39
|
|
// CHECK:STDOUT: store ptr poison, ptr %ptr_i32.var, align 8, !dbg !39
|
|
// CHECK:STDOUT: %.loc19_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !41
|
|
// CHECK:STDOUT: %F.call.loc19 = call ptr @_CF.Main.417c9c4a651ab31b(ptr %.loc19_5), !dbg !42
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %ptr_f64.var), !dbg !46
|
|
// CHECK:STDOUT: store ptr poison, ptr %ptr_f64.var, align 8, !dbg !46
|
|
// CHECK:STDOUT: %.loc21_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !48
|
|
// CHECK:STDOUT: %F.call.loc21 = call ptr @_CF.Main.417c9c4a651ab31b(ptr %.loc21_5), !dbg !49
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %ptr_i8.var), !dbg !50
|
|
// CHECK:STDOUT: store ptr poison, ptr %ptr_i8.var, align 8, !dbg !50
|
|
// CHECK:STDOUT: %.loc23_5 = load ptr, ptr %ptr_i8.var, align 8, !dbg !52
|
|
// CHECK:STDOUT: %F.call.loc23 = call ptr @_CF.Main.417c9c4a651ab31b(ptr %.loc23_5), !dbg !53
|
|
// CHECK:STDOUT: call void @_CSelfDestruct.Core.eadf459918fc387c(ptr %ptr_i8.var), !dbg !50
|
|
// CHECK:STDOUT: call void @_CSelfDestruct.Core.b18855c76072615b(ptr %ptr_f64.var), !dbg !46
|
|
// CHECK:STDOUT: call void @_CSelfDestruct.Core.4f29d15a20894e9b(ptr %ptr_i32.var), !dbg !39
|
|
// CHECK:STDOUT: ret void, !dbg !56
|
|
// 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 ptr @_CF.Main.417c9c4a651ab31b(ptr %x) #0 !dbg !57 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret ptr %x, !dbg !63
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define linkonce_odr void @_CSelfDestruct.Core.eadf459918fc387c(ptr %t) #0 !dbg !81 {
|
|
// CHECK:STDOUT: ret void, !dbg !86
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define linkonce_odr void @_CSelfDestruct.Core.b18855c76072615b(ptr %t) #0 !dbg !88 {
|
|
// CHECK:STDOUT: ret void, !dbg !93
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nounwind
|
|
// CHECK:STDOUT: define linkonce_odr void @_CSelfDestruct.Core.4f29d15a20894e9b(ptr %t) #0 !dbg !95 {
|
|
// CHECK:STDOUT: ret void, !dbg !100
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; uselistorder directives
|
|
// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 2, 1, 0 }
|
|
// CHECK:STDOUT: uselistorder ptr @_CF.Main.417c9c4a651ab31b, { 2, 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 = !{!35}
|
|
// 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: !26 = !DIFile(filename: "min_prelude/parts/destroy.carbon", directory: "")
|
|
// CHECK:STDOUT: !34 = !DIFile(filename: "call_dedup_ptr.carbon", directory: "")
|
|
// CHECK:STDOUT: !35 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !34, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !36 = !{null}
|
|
// CHECK:STDOUT: !37 = !DISubroutineType(types: !36)
|
|
// CHECK:STDOUT: !38 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !34, line: 17, type: !37, spFlags: DISPFlagDefinition, unit: !35)
|
|
// CHECK:STDOUT: !39 = !DILocation(line: 18, column: 3, scope: !38)
|
|
// CHECK:STDOUT: !41 = !DILocation(line: 19, column: 5, scope: !38)
|
|
// CHECK:STDOUT: !42 = !DILocation(line: 19, column: 3, scope: !38)
|
|
// CHECK:STDOUT: !43 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
|
|
// CHECK:STDOUT: !44 = !{!43, !43}
|
|
// CHECK:STDOUT: !45 = !DISubroutineType(types: !44)
|
|
// CHECK:STDOUT: !46 = !DILocation(line: 20, column: 3, scope: !38)
|
|
// CHECK:STDOUT: !48 = !DILocation(line: 21, column: 5, scope: !38)
|
|
// CHECK:STDOUT: !49 = !DILocation(line: 21, column: 3, scope: !38)
|
|
// CHECK:STDOUT: !50 = !DILocation(line: 22, column: 3, scope: !38)
|
|
// CHECK:STDOUT: !52 = !DILocation(line: 23, column: 5, scope: !38)
|
|
// CHECK:STDOUT: !53 = !DILocation(line: 23, column: 3, scope: !38)
|
|
// CHECK:STDOUT: !54 = !{null, !43}
|
|
// CHECK:STDOUT: !55 = !DISubroutineType(types: !54)
|
|
// CHECK:STDOUT: !56 = !DILocation(line: 17, column: 1, scope: !38)
|
|
// CHECK:STDOUT: !57 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.417c9c4a651ab31b", scope: null, file: !34, line: 13, type: !45, spFlags: DISPFlagDefinition, unit: !35, retainedNodes: !64)
|
|
// CHECK:STDOUT: !58 = !DILocalVariable(arg: 1, scope: !57, type: !43)
|
|
// CHECK:STDOUT: !63 = !DILocation(line: 14, column: 3, scope: !57)
|
|
// CHECK:STDOUT: !64 = !{!58}
|
|
// CHECK:STDOUT: !81 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.Core.eadf459918fc387c", scope: null, file: !26, line: 32, type: !55, spFlags: DISPFlagDefinition, unit: !35, retainedNodes: !87)
|
|
// CHECK:STDOUT: !82 = !DILocalVariable(arg: 1, scope: !81, type: !43)
|
|
// CHECK:STDOUT: !86 = !DILocation(line: 32, column: 1, scope: !81)
|
|
// CHECK:STDOUT: !87 = !{!82}
|
|
// CHECK:STDOUT: !88 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.Core.b18855c76072615b", scope: null, file: !26, line: 32, type: !55, spFlags: DISPFlagDefinition, unit: !35, retainedNodes: !94)
|
|
// CHECK:STDOUT: !89 = !DILocalVariable(arg: 1, scope: !88, type: !43)
|
|
// CHECK:STDOUT: !93 = !DILocation(line: 32, column: 1, scope: !88)
|
|
// CHECK:STDOUT: !94 = !{!89}
|
|
// CHECK:STDOUT: !95 = distinct !DISubprogram(name: "SelfDestruct", linkageName: "_CSelfDestruct.Core.4f29d15a20894e9b", scope: null, file: !26, line: 32, type: !55, spFlags: DISPFlagDefinition, unit: !35, retainedNodes: !101)
|
|
// CHECK:STDOUT: !96 = !DILocalVariable(arg: 1, scope: !95, type: !43)
|
|
// CHECK:STDOUT: !100 = !DILocation(line: 32, column: 1, scope: !95)
|
|
// CHECK:STDOUT: !101 = !{!96}
|
|
// CHECK:STDOUT:
|