Destroy temporaries at the end of expression statements. (#7513)

Instead of tracking the cleanup scope depth on entry to each scope,
track an "ambient" cleanup scope depth that's *after* the destructors of
local variables in that scope. This gets increased to include the
destructors of local variables when we create a name-binding
declaration. Then, when we reach a point where temporaries should be
destroyed, run cleanups that are after the ambient cleanup scope depth
on the stack. This happens:

* At the `;` of a statement expression.
* At the `)` of an `if` or `while` statement.
* After performing the implied `HasValue()` call in a `for` statement.

Per informal agreement with leads, this means we lifetime-extend all
temporaries created in the initializer of a name-binding declaration to
the full scope of that declaration, but that temporaries created in an
expression statement are destroyed at the `;`.
This commit is contained in:
Richard Smith
2026-07-16 15:12:39 +00:00
committed by GitHub
parent 81e495ee53
commit 703529fc55
37 changed files with 844 additions and 384 deletions
@@ -334,10 +334,10 @@ fn F(ref r: Cpp.A) {
// CHECK:STDOUT: %.loc8_14.3.temp = alloca i8, align 1, !dbg !19
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc7_14.3.temp), !dbg !18
// CHECK:STDOUT: call void @_ZNK9NeedThunk8ImplicitEa.carbon_thunk.__(ptr %n, ptr @int_1.f1e), !dbg !20
// CHECK:STDOUT: call void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr @int_1.f1e), !dbg !18
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc8_14.3.temp), !dbg !19
// CHECK:STDOUT: call void @_ZNH9NeedThunk8ExplicitES_a.carbon_thunk.__(ptr %n, ptr @int_1.f1e), !dbg !21
// CHECK:STDOUT: call void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr @int_1.f1e), !dbg !19
// CHECK:STDOUT: call void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr @int_1.f1e), !dbg !18
// CHECK:STDOUT: ret void, !dbg !22
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -355,6 +355,12 @@ fn F(ref r: Cpp.A) {
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr %self) #0 !dbg !30 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !36
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
// CHECK:STDOUT: define internal void @_ZNH9NeedThunk8ExplicitES_a.carbon_thunk.__(ptr noundef %0, ptr noundef %c) #1 {
// CHECK:STDOUT: entry:
@@ -370,12 +376,6 @@ fn F(ref r: Cpp.A) {
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr %self) #0 !dbg !30 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !36
// 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)) #2
// CHECK:STDOUT:
@@ -426,13 +426,13 @@ fn F(ref r: Cpp.A) {
// CHECK:STDOUT: !27 = !{!"p1 omnipotent char", !25, i64 0}
// CHECK:STDOUT: !28 = !{}
// CHECK:STDOUT: !29 = !{!10, !10, i64 0}
// CHECK:STDOUT: !30 = distinct !DISubprogram(name: "Op", linkageName: "_COp.578b3934f85dbca6:core.Destroy.Core", scope: null, file: !1, line: 8, type: !31, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !34)
// CHECK:STDOUT: !30 = distinct !DISubprogram(name: "Op", linkageName: "_COp.578b3934f85dbca6:core.Destroy.Core", scope: null, file: !1, line: 7, type: !31, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !34)
// CHECK:STDOUT: !31 = !DISubroutineType(types: !32)
// CHECK:STDOUT: !32 = !{null, !33}
// CHECK:STDOUT: !33 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_signed)
// CHECK:STDOUT: !34 = !{!35}
// CHECK:STDOUT: !35 = !DILocalVariable(arg: 1, scope: !30, type: !33)
// CHECK:STDOUT: !36 = !DILocation(line: 8, column: 14, scope: !30)
// CHECK:STDOUT: !36 = !DILocation(line: 7, column: 14, scope: !30)
// CHECK:STDOUT:
// CHECK:STDOUT: ; ---
// CHECK:STDOUT: ; ModuleID = 'call_with_ref_self.carbon'
@@ -131,13 +131,13 @@ fn PassValueExpr(y: Cpp.Y) {
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc7_19.3.temp), !dbg !15
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc7_22.3.temp), !dbg !16
// CHECK:STDOUT: call void @_Z11pass_signedasil.carbon_thunk.____(ptr @int_1.f1e, ptr @int_2.5c2, i32 3, i64 4), !dbg !19
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr @int_2.5c2), !dbg !16
// CHECK:STDOUT: call void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr @int_1.f1e), !dbg !15
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc9_21.3.temp), !dbg !17
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc9_24.3.temp), !dbg !18
// CHECK:STDOUT: call void @_Z13pass_unsignedhtjm.carbon_thunk.____(ptr @int_1.067, ptr @int_2.ec3, i32 3, i64 4), !dbg !20
// CHECK:STDOUT: call void @"_COp.6fd0ed7da7a22bb4:core.Destroy.Core"(ptr @int_2.ec3), !dbg !18
// CHECK:STDOUT: call void @"_COp.c3b9dc9c7e0d5d3d:core.Destroy.Core"(ptr @int_1.067), !dbg !17
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr @int_2.5c2), !dbg !16
// CHECK:STDOUT: call void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr @int_1.f1e), !dbg !15
// CHECK:STDOUT: ret void, !dbg !21
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -162,6 +162,18 @@ fn PassValueExpr(y: Cpp.Y) {
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %self) #0 !dbg !33 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !39
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr %self) #0 !dbg !40 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !46
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
// CHECK:STDOUT: define internal void @_Z13pass_unsignedhtjm.carbon_thunk.____(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 noundef %3) #1 {
// CHECK:STDOUT: entry:
@@ -184,25 +196,13 @@ fn PassValueExpr(y: Cpp.Y) {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.6fd0ed7da7a22bb4:core.Destroy.Core"(ptr %self) #0 !dbg !33 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !39
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.c3b9dc9c7e0d5d3d:core.Destroy.Core"(ptr %self) #0 !dbg !40 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !46
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %self) #0 !dbg !47 {
// CHECK:STDOUT: define weak_odr void @"_COp.6fd0ed7da7a22bb4:core.Destroy.Core"(ptr %self) #0 !dbg !47 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !53
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.578b3934f85dbca6:core.Destroy.Core"(ptr %self) #0 !dbg !54 {
// CHECK:STDOUT: define weak_odr void @"_COp.c3b9dc9c7e0d5d3d:core.Destroy.Core"(ptr %self) #0 !dbg !54 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !60
// CHECK:STDOUT: }
@@ -219,22 +219,22 @@ fn PassValueExpr(y: Cpp.Y) {
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc17_18.1.temp), !dbg !68
// CHECK:STDOUT: store i16 %a, ptr %.loc17_18.1.temp, align 2, !dbg !68
// CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk._(ptr %.loc17_18.1.temp), !dbg !72
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %.loc17_18.1.temp), !dbg !68
// CHECK:STDOUT: %.loc18_18.2 = load i16, ptr %b, align 2, !dbg !69
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_18.3.temp), !dbg !69
// CHECK:STDOUT: store i16 %.loc18_18.2, ptr %.loc18_18.3.temp, align 2, !dbg !69
// CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk._(ptr %.loc18_18.3.temp), !dbg !73
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %.loc18_18.3.temp), !dbg !69
// CHECK:STDOUT: %.loc19_18.1 = load i16, ptr @_Cc.Main, align 2, !dbg !70
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc19_18.2.temp), !dbg !70
// CHECK:STDOUT: store i16 %.loc19_18.1, ptr %.loc19_18.2.temp, align 2, !dbg !70
// CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk._(ptr %.loc19_18.2.temp), !dbg !74
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %.loc19_18.2.temp), !dbg !70
// CHECK:STDOUT: %MakeShort.call = call i16 @_CMakeShort.Main(), !dbg !71
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc20_28.3.temp), !dbg !71
// CHECK:STDOUT: store i16 %MakeShort.call, ptr %.loc20_28.3.temp, align 2, !dbg !71
// CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk._(ptr %.loc20_28.3.temp), !dbg !75
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %.loc20_28.3.temp), !dbg !71
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %.loc19_18.2.temp), !dbg !70
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %.loc18_18.3.temp), !dbg !69
// CHECK:STDOUT: call void @"_COp.eb6702152d47e49f:core.Destroy.Core"(ptr %.loc17_18.1.temp), !dbg !68
// CHECK:STDOUT: ret void, !dbg !76
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -311,40 +311,40 @@ fn PassValueExpr(y: Cpp.Y) {
// CHECK:STDOUT: !30 = !{!10, !10, i64 0}
// CHECK:STDOUT: !31 = !{!32, !32, i64 0}
// CHECK:STDOUT: !32 = !{!"short", !10, i64 0}
// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.6fd0ed7da7a22bb4:core.Destroy.Core", scope: null, file: !1, line: 9, type: !34, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !37)
// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.eb6702152d47e49f:core.Destroy.Core", scope: null, file: !1, line: 7, type: !34, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !37)
// CHECK:STDOUT: !34 = !DISubroutineType(types: !35)
// CHECK:STDOUT: !35 = !{null, !36}
// CHECK:STDOUT: !36 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_unsigned)
// CHECK:STDOUT: !36 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
// CHECK:STDOUT: !37 = !{!38}
// CHECK:STDOUT: !38 = !DILocalVariable(arg: 1, scope: !33, type: !36)
// CHECK:STDOUT: !39 = !DILocation(line: 9, column: 24, scope: !33)
// CHECK:STDOUT: !40 = distinct !DISubprogram(name: "Op", linkageName: "_COp.c3b9dc9c7e0d5d3d:core.Destroy.Core", scope: null, file: !1, line: 9, type: !41, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !44)
// CHECK:STDOUT: !39 = !DILocation(line: 7, column: 22, scope: !33)
// CHECK:STDOUT: !40 = distinct !DISubprogram(name: "Op", linkageName: "_COp.578b3934f85dbca6:core.Destroy.Core", scope: null, file: !1, line: 7, type: !41, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !44)
// CHECK:STDOUT: !41 = !DISubroutineType(types: !42)
// CHECK:STDOUT: !42 = !{null, !43}
// CHECK:STDOUT: !43 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_unsigned)
// CHECK:STDOUT: !43 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_signed)
// CHECK:STDOUT: !44 = !{!45}
// CHECK:STDOUT: !45 = !DILocalVariable(arg: 1, scope: !40, type: !43)
// CHECK:STDOUT: !46 = !DILocation(line: 9, column: 21, scope: !40)
// CHECK:STDOUT: !47 = distinct !DISubprogram(name: "Op", linkageName: "_COp.eb6702152d47e49f:core.Destroy.Core", scope: null, file: !1, line: 7, type: !48, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !51)
// CHECK:STDOUT: !46 = !DILocation(line: 7, column: 19, scope: !40)
// CHECK:STDOUT: !47 = distinct !DISubprogram(name: "Op", linkageName: "_COp.6fd0ed7da7a22bb4:core.Destroy.Core", scope: null, file: !1, line: 9, type: !48, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !51)
// CHECK:STDOUT: !48 = !DISubroutineType(types: !49)
// CHECK:STDOUT: !49 = !{null, !50}
// CHECK:STDOUT: !50 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
// CHECK:STDOUT: !50 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_unsigned)
// CHECK:STDOUT: !51 = !{!52}
// CHECK:STDOUT: !52 = !DILocalVariable(arg: 1, scope: !47, type: !50)
// CHECK:STDOUT: !53 = !DILocation(line: 7, column: 22, scope: !47)
// CHECK:STDOUT: !54 = distinct !DISubprogram(name: "Op", linkageName: "_COp.578b3934f85dbca6:core.Destroy.Core", scope: null, file: !1, line: 7, type: !55, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !58)
// CHECK:STDOUT: !53 = !DILocation(line: 9, column: 24, scope: !47)
// CHECK:STDOUT: !54 = distinct !DISubprogram(name: "Op", linkageName: "_COp.c3b9dc9c7e0d5d3d:core.Destroy.Core", scope: null, file: !1, line: 9, type: !55, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !58)
// CHECK:STDOUT: !55 = !DISubroutineType(types: !56)
// CHECK:STDOUT: !56 = !{null, !57}
// CHECK:STDOUT: !57 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_signed)
// CHECK:STDOUT: !57 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_unsigned)
// CHECK:STDOUT: !58 = !{!59}
// CHECK:STDOUT: !59 = !DILocalVariable(arg: 1, scope: !54, type: !57)
// CHECK:STDOUT: !60 = !DILocation(line: 7, column: 19, scope: !54)
// CHECK:STDOUT: !60 = !DILocation(line: 9, column: 21, scope: !54)
// CHECK:STDOUT: !61 = distinct !DISubprogram(name: "PassShort", linkageName: "_CPassShort.Main", scope: null, file: !1, line: 16, type: !62, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !65)
// CHECK:STDOUT: !62 = !DISubroutineType(types: !63)
// CHECK:STDOUT: !63 = !{null, !50, !64}
// CHECK:STDOUT: !63 = !{null, !36, !64}
// CHECK:STDOUT: !64 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
// CHECK:STDOUT: !65 = !{!66, !67}
// CHECK:STDOUT: !66 = !DILocalVariable(arg: 1, scope: !61, type: !50)
// CHECK:STDOUT: !66 = !DILocalVariable(arg: 1, scope: !61, type: !36)
// CHECK:STDOUT: !67 = !DILocalVariable(arg: 2, scope: !61, type: !64)
// CHECK:STDOUT: !68 = !DILocation(line: 17, column: 18, scope: !61)
// CHECK:STDOUT: !69 = !DILocation(line: 18, column: 18, scope: !61)
+56 -56
View File
@@ -65,23 +65,41 @@ fn ConvertNullptrConstant() -> Core.Optional(i32*) {
// CHECK:STDOUT: store ptr %Cpp.nullptr_t.as.ImplicitAs.impl.Convert.call, ptr %.loc12_18.2.temp, align 8, !dbg !15
// CHECK:STDOUT: %.loc12_18.4 = load ptr, ptr %.loc12_18.2.temp, align 8, !dbg !15
// CHECK:STDOUT: call void @_Z7TakePtrPi(ptr %.loc12_18.4), !dbg !17
// CHECK:STDOUT: call void @"_COp.9a41840f34ccc47a:core.Destroy.Core"(ptr %.loc12_18.2.temp), !dbg !15
// CHECK:STDOUT: %Cpp.nullptr_t.as.Copy.impl.Op.call = call ptr @"_COp.NullptrT.CppCompat.Core:Copy.Core"(ptr poison), !dbg !16
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc14_22.1.temp), !dbg !16
// CHECK:STDOUT: store ptr %Cpp.nullptr_t.as.Copy.impl.Op.call, ptr %.loc14_22.1.temp, align 8, !dbg !16
// CHECK:STDOUT: call void @_Z11TakeNullptrDn.carbon_thunk._(ptr %.loc14_22.1.temp), !dbg !18
// CHECK:STDOUT: call void @"_COp.37a0be3fec6961f4:core.Destroy.Core"(ptr %.loc14_22.1.temp), !dbg !16
// CHECK:STDOUT: call void @"_COp.9a41840f34ccc47a:core.Destroy.Core"(ptr %.loc12_18.2.temp), !dbg !15
// CHECK:STDOUT: ret void, !dbg !19
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: declare void @_Z7TakePtrPi(ptr noundef) #1
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.32a070744df634d9:core.Destroy.Core"(ptr %self) #0 !dbg !20 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !26
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.958634845f762cfe:core.Destroy.Core"(ptr %self) #0 !dbg !27 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !30
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.9a41840f34ccc47a:core.Destroy.Core"(ptr %self) #0 !dbg !31 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !34
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
// CHECK:STDOUT: define internal void @_Z11TakeNullptrDn.carbon_thunk._(ptr noundef %n) #2 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %n.addr = alloca ptr, align 8
// CHECK:STDOUT: store ptr %n, ptr %n.addr, align 8, !tbaa !20
// CHECK:STDOUT: %0 = load ptr, ptr %n.addr, align 8, !tbaa !20
// CHECK:STDOUT: store ptr %n, ptr %n.addr, align 8, !tbaa !35
// CHECK:STDOUT: %0 = load ptr, ptr %n.addr, align 8, !tbaa !35
// CHECK:STDOUT: call void @_Z11TakeNullptrDn(ptr null)
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
@@ -89,37 +107,19 @@ fn ConvertNullptrConstant() -> Core.Optional(i32*) {
// CHECK:STDOUT: declare ptr @"_COp.NullptrT.CppCompat.Core:Copy.Core"(ptr)
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.fd39a15e7d61228d:core.Destroy.Core"(ptr %self) #0 !dbg !23 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !29
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.125695b29f2cf97c:core.Destroy.Core"(ptr %self) #0 !dbg !30 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !33
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.37a0be3fec6961f4:core.Destroy.Core"(ptr %self) #0 !dbg !34 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !37
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.32a070744df634d9:core.Destroy.Core"(ptr %self) #0 !dbg !38 {
// CHECK:STDOUT: define weak_odr void @"_COp.fd39a15e7d61228d:core.Destroy.Core"(ptr %self) #0 !dbg !38 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !41
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.958634845f762cfe:core.Destroy.Core"(ptr %self) #0 !dbg !42 {
// CHECK:STDOUT: define weak_odr void @"_COp.125695b29f2cf97c:core.Destroy.Core"(ptr %self) #0 !dbg !42 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !45
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.9a41840f34ccc47a:core.Destroy.Core"(ptr %self) #0 !dbg !46 {
// CHECK:STDOUT: define weak_odr void @"_COp.37a0be3fec6961f4:core.Destroy.Core"(ptr %self) #0 !dbg !46 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !49
// CHECK:STDOUT: }
@@ -160,8 +160,8 @@ fn ConvertNullptrConstant() -> Core.Optional(i32*) {
// CHECK:STDOUT: define internal void @_Z13ReturnNullptrv.carbon_thunk.(ptr noundef %return) #2 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !20
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !20
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !35
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !35
// CHECK:STDOUT: %call = call ptr @_Z13ReturnNullptrv()
// CHECK:STDOUT: store ptr %call, ptr %0, align 8, !tbaa !65
// CHECK:STDOUT: ret void
@@ -239,39 +239,39 @@ fn ConvertNullptrConstant() -> Core.Optional(i32*) {
// CHECK:STDOUT: !17 = !DILocation(line: 12, column: 3, scope: !12)
// CHECK:STDOUT: !18 = !DILocation(line: 14, column: 3, scope: !12)
// CHECK:STDOUT: !19 = !DILocation(line: 11, column: 1, scope: !12)
// CHECK:STDOUT: !20 = !{!21, !21, i64 0}
// CHECK:STDOUT: !21 = !{!"p1 std::nullptr_t", !22, i64 0}
// CHECK:STDOUT: !22 = !{!"any pointer", !10, i64 0}
// CHECK:STDOUT: !23 = distinct !DISubprogram(name: "Op", linkageName: "_COp.fd39a15e7d61228d:core.Destroy.Core", scope: null, file: !1, line: 14, type: !24, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !27)
// CHECK:STDOUT: !24 = !DISubroutineType(types: !25)
// CHECK:STDOUT: !25 = !{null, !26}
// CHECK:STDOUT: !26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
// CHECK:STDOUT: !27 = !{!28}
// CHECK:STDOUT: !28 = !DILocalVariable(arg: 1, scope: !23, type: !26)
// CHECK:STDOUT: !29 = !DILocation(line: 14, column: 19, scope: !23)
// CHECK:STDOUT: !30 = distinct !DISubprogram(name: "Op", linkageName: "_COp.125695b29f2cf97c:core.Destroy.Core", scope: null, file: !1, line: 14, type: !24, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !31)
// CHECK:STDOUT: !31 = !{!32}
// CHECK:STDOUT: !32 = !DILocalVariable(arg: 1, scope: !30, type: !26)
// CHECK:STDOUT: !33 = !DILocation(line: 14, column: 19, scope: !30)
// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "Op", linkageName: "_COp.37a0be3fec6961f4:core.Destroy.Core", scope: null, file: !1, line: 14, type: !24, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !35)
// CHECK:STDOUT: !35 = !{!36}
// CHECK:STDOUT: !36 = !DILocalVariable(arg: 1, scope: !34, type: !26)
// CHECK:STDOUT: !37 = !DILocation(line: 14, column: 19, scope: !34)
// CHECK:STDOUT: !38 = distinct !DISubprogram(name: "Op", linkageName: "_COp.32a070744df634d9:core.Destroy.Core", scope: null, file: !1, line: 12, type: !24, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !39)
// CHECK:STDOUT: !20 = distinct !DISubprogram(name: "Op", linkageName: "_COp.32a070744df634d9:core.Destroy.Core", scope: null, file: !1, line: 12, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !24)
// CHECK:STDOUT: !21 = !DISubroutineType(types: !22)
// CHECK:STDOUT: !22 = !{null, !23}
// CHECK:STDOUT: !23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
// CHECK:STDOUT: !24 = !{!25}
// CHECK:STDOUT: !25 = !DILocalVariable(arg: 1, scope: !20, type: !23)
// CHECK:STDOUT: !26 = !DILocation(line: 12, column: 15, scope: !20)
// CHECK:STDOUT: !27 = distinct !DISubprogram(name: "Op", linkageName: "_COp.958634845f762cfe:core.Destroy.Core", scope: null, file: !1, line: 12, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !28)
// CHECK:STDOUT: !28 = !{!29}
// CHECK:STDOUT: !29 = !DILocalVariable(arg: 1, scope: !27, type: !23)
// CHECK:STDOUT: !30 = !DILocation(line: 12, column: 15, scope: !27)
// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "Op", linkageName: "_COp.9a41840f34ccc47a:core.Destroy.Core", scope: null, file: !1, line: 12, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !32)
// CHECK:STDOUT: !32 = !{!33}
// CHECK:STDOUT: !33 = !DILocalVariable(arg: 1, scope: !31, type: !23)
// CHECK:STDOUT: !34 = !DILocation(line: 12, column: 15, scope: !31)
// CHECK:STDOUT: !35 = !{!36, !36, i64 0}
// CHECK:STDOUT: !36 = !{!"p1 std::nullptr_t", !37, i64 0}
// CHECK:STDOUT: !37 = !{!"any pointer", !10, i64 0}
// CHECK:STDOUT: !38 = distinct !DISubprogram(name: "Op", linkageName: "_COp.fd39a15e7d61228d:core.Destroy.Core", scope: null, file: !1, line: 14, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !39)
// CHECK:STDOUT: !39 = !{!40}
// CHECK:STDOUT: !40 = !DILocalVariable(arg: 1, scope: !38, type: !26)
// CHECK:STDOUT: !41 = !DILocation(line: 12, column: 15, scope: !38)
// CHECK:STDOUT: !42 = distinct !DISubprogram(name: "Op", linkageName: "_COp.958634845f762cfe:core.Destroy.Core", scope: null, file: !1, line: 12, type: !24, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !43)
// CHECK:STDOUT: !40 = !DILocalVariable(arg: 1, scope: !38, type: !23)
// CHECK:STDOUT: !41 = !DILocation(line: 14, column: 19, scope: !38)
// CHECK:STDOUT: !42 = distinct !DISubprogram(name: "Op", linkageName: "_COp.125695b29f2cf97c:core.Destroy.Core", scope: null, file: !1, line: 14, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !43)
// CHECK:STDOUT: !43 = !{!44}
// CHECK:STDOUT: !44 = !DILocalVariable(arg: 1, scope: !42, type: !26)
// CHECK:STDOUT: !45 = !DILocation(line: 12, column: 15, scope: !42)
// CHECK:STDOUT: !46 = distinct !DISubprogram(name: "Op", linkageName: "_COp.9a41840f34ccc47a:core.Destroy.Core", scope: null, file: !1, line: 12, type: !24, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !47)
// CHECK:STDOUT: !44 = !DILocalVariable(arg: 1, scope: !42, type: !23)
// CHECK:STDOUT: !45 = !DILocation(line: 14, column: 19, scope: !42)
// CHECK:STDOUT: !46 = distinct !DISubprogram(name: "Op", linkageName: "_COp.37a0be3fec6961f4:core.Destroy.Core", scope: null, file: !1, line: 14, type: !21, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !47)
// CHECK:STDOUT: !47 = !{!48}
// CHECK:STDOUT: !48 = !DILocalVariable(arg: 1, scope: !46, type: !26)
// CHECK:STDOUT: !49 = !DILocation(line: 12, column: 15, scope: !46)
// CHECK:STDOUT: !48 = !DILocalVariable(arg: 1, scope: !46, type: !23)
// CHECK:STDOUT: !49 = !DILocation(line: 14, column: 19, scope: !46)
// CHECK:STDOUT: !50 = distinct !DISubprogram(name: "ReturnNullptr", linkageName: "_CReturnNullptr.Main", scope: null, file: !1, line: 17, type: !51, spFlags: DISPFlagDefinition, unit: !0)
// CHECK:STDOUT: !51 = !DISubroutineType(types: !52)
// CHECK:STDOUT: !52 = !{!26}
// CHECK:STDOUT: !52 = !{!23}
// CHECK:STDOUT: !53 = !DILocation(line: 18, column: 10, scope: !50)
// CHECK:STDOUT: !54 = !DILocation(line: 18, column: 3, scope: !50)
// CHECK:STDOUT: !55 = distinct !DISubprogram(name: "ReturnNullptrCopy", linkageName: "_CReturnNullptrCopy.Main", scope: null, file: !1, line: 21, type: !51, spFlags: DISPFlagDefinition, unit: !0)
@@ -294,9 +294,9 @@ fn ConvertNullptrConstant() -> Core.Optional(i32*) {
// CHECK:STDOUT: !72 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.NullptrT.CppCompat.Core:ImplicitAs.f8357062f5b0e57c.Core.84588f41d61dafba", scope: null, file: !73, line: 51, type: !74, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !76)
// CHECK:STDOUT: !73 = !DIFile(filename: "{{.*}}/prelude/types/cpp/nullptr.carbon", directory: "")
// CHECK:STDOUT: !74 = !DISubroutineType(types: !75)
// CHECK:STDOUT: !75 = !{!26, !26}
// CHECK:STDOUT: !75 = !{!23, !23}
// CHECK:STDOUT: !76 = !{!77}
// CHECK:STDOUT: !77 = !DILocalVariable(arg: 1, scope: !72, type: !26)
// CHECK:STDOUT: !77 = !DILocalVariable(arg: 1, scope: !72, type: !23)
// CHECK:STDOUT: !78 = !DILocation(line: 52, column: 14, scope: !72)
// CHECK:STDOUT: !79 = !DILocation(line: 52, column: 7, scope: !72)
// CHECK:STDOUT: !80 = distinct !DISubprogram(name: "None", linkageName: "_CNone.Optional.Core.0a6122c87ac9ba0f", scope: null, file: !81, line: 30, type: !51, spFlags: DISPFlagDefinition, unit: !0)
+18 -18
View File
@@ -157,12 +157,12 @@ fn GetRefs() {
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var.2), !dbg !18
// CHECK:STDOUT: store i32 42, ptr %_.var.2, align 4, !dbg !18
// CHECK:STDOUT: call void @_Z11TakeIntRRefOi.carbon_thunk.v(ptr %_.var.2), !dbg !24
// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %_.var.2), !dbg !18
// CHECK:STDOUT: %.loc25_23.1 = load i32, ptr %n.var, align 4, !dbg !19
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc25_23.2.temp), !dbg !19
// CHECK:STDOUT: store i32 %.loc25_23.1, ptr %.loc25_23.2.temp, align 4, !dbg !19
// CHECK:STDOUT: call void @_Z15TakeConstIntRefRKi.carbon_thunk._(ptr %.loc25_23.2.temp), !dbg !25
// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %.loc25_23.2.temp), !dbg !19
// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %_.var.2), !dbg !18
// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %n.var), !dbg !17
// CHECK:STDOUT: ret void, !dbg !26
// CHECK:STDOUT: }
@@ -217,6 +217,12 @@ fn GetRefs() {
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %self) #0 !dbg !37 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !43
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
// CHECK:STDOUT: define internal void @_Z15TakeConstIntRefRKi.carbon_thunk._(ptr noundef %0) #4 {
// CHECK:STDOUT: entry:
@@ -227,12 +233,6 @@ fn GetRefs() {
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %self) #0 !dbg !37 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !43
// 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)) #5
// CHECK:STDOUT:
@@ -305,13 +305,13 @@ fn GetRefs() {
// CHECK:STDOUT: !34 = !DILocation(line: 5, column: 7, scope: !30)
// CHECK:STDOUT: !35 = !{!36, !36, i64 0}
// CHECK:STDOUT: !36 = !{!"p1 int", !29, i64 0}
// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 25, type: !38, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)
// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 12, type: !38, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)
// CHECK:STDOUT: !38 = !DISubroutineType(types: !39)
// CHECK:STDOUT: !39 = !{null, !40}
// CHECK:STDOUT: !40 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !41 = !{!42}
// CHECK:STDOUT: !42 = !DILocalVariable(arg: 1, scope: !37, type: !40)
// CHECK:STDOUT: !43 = !DILocation(line: 25, column: 23, scope: !37)
// CHECK:STDOUT: !43 = !DILocation(line: 12, column: 23, scope: !37)
// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Op", linkageName: "_COp.51f3fb62cb986374:DefaultOrUnformed.Core.67b28f83c7cfd60c", scope: null, file: !45, line: 9, type: !31, spFlags: DISPFlagDefinition, unit: !0)
// CHECK:STDOUT: !45 = !DIFile(filename: "min_prelude/parts/default.carbon", directory: "")
// CHECK:STDOUT: !46 = !DILocation(line: 9, column: 28, scope: !44)
@@ -348,12 +348,12 @@ fn GetRefs() {
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !18
// CHECK:STDOUT: store i32 42, ptr %_.var, align 4, !dbg !18
// CHECK:STDOUT: call void @_Z11TakeIntRRefOi10ForceThunk.carbon_thunk.v(ptr %_.var), !dbg !24
// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %_.var), !dbg !18
// CHECK:STDOUT: %.loc26_23.1 = load i32, ptr %n.var, align 4, !dbg !19
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc26_23.2.temp), !dbg !19
// CHECK:STDOUT: store i32 %.loc26_23.1, ptr %.loc26_23.2.temp, align 4, !dbg !19
// CHECK:STDOUT: call void @_Z15TakeConstIntRefRKi10ForceThunk.carbon_thunk._(ptr %.loc26_23.2.temp), !dbg !25
// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %.loc26_23.2.temp), !dbg !19
// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %_.var), !dbg !18
// CHECK:STDOUT: call void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %n.var), !dbg !17
// CHECK:STDOUT: ret void, !dbg !26
// CHECK:STDOUT: }
@@ -429,6 +429,12 @@ fn GetRefs() {
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %self) #0 !dbg !39 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !45
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
// CHECK:STDOUT: define internal void @_Z15TakeConstIntRefRKi10ForceThunk.carbon_thunk._(ptr noundef %0) #3 {
// CHECK:STDOUT: entry:
@@ -440,12 +446,6 @@ fn GetRefs() {
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: nounwind
// CHECK:STDOUT: define weak_odr void @"_COp.5e27612b9dd31a14:core.Destroy.Core"(ptr %self) #0 !dbg !39 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: ret void, !dbg !45
// 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)) #4
// CHECK:STDOUT:
@@ -521,13 +521,13 @@ fn GetRefs() {
// CHECK:STDOUT: !36 = !{!37, !37, i64 0}
// CHECK:STDOUT: !37 = !{!"p1 int", !29, i64 0}
// CHECK:STDOUT: !38 = !{i64 4}
// CHECK:STDOUT: !39 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 26, type: !40, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !43)
// CHECK:STDOUT: !39 = distinct !DISubprogram(name: "Op", linkageName: "_COp.5e27612b9dd31a14:core.Destroy.Core", scope: null, file: !1, line: 13, type: !40, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !43)
// CHECK:STDOUT: !40 = !DISubroutineType(types: !41)
// CHECK:STDOUT: !41 = !{null, !42}
// CHECK:STDOUT: !42 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
// CHECK:STDOUT: !43 = !{!44}
// CHECK:STDOUT: !44 = !DILocalVariable(arg: 1, scope: !39, type: !42)
// CHECK:STDOUT: !45 = !DILocation(line: 26, column: 23, scope: !39)
// CHECK:STDOUT: !45 = !DILocation(line: 13, column: 23, scope: !39)
// CHECK:STDOUT: !46 = distinct !DISubprogram(name: "Op", linkageName: "_COp.51f3fb62cb986374:DefaultOrUnformed.Core.67b28f83c7cfd60c", scope: null, file: !47, line: 9, type: !31, spFlags: DISPFlagDefinition, unit: !0)
// CHECK:STDOUT: !47 = !DIFile(filename: "min_prelude/parts/default.carbon", directory: "")
// CHECK:STDOUT: !48 = !DILocation(line: 9, column: 28, scope: !46)