mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Remove special case for returning value expressions by copy (#6052)
When returning a value from a function whose return type has a by-copy initializing representation, perform initialization like we do when the return type has an in-place initializing representation. This makes our SemIR representation more uniform, as the return expression will now always be an initializing expression rather than a value expression, but more importantly it means that attempts to return a non-copyable type by value now fail, even if the type has a by-copy initializing representation. This catches a bunch of places where we were returning a value of an unconstrained template parameter `T:! type`, which we were incorrectly allowing because we didn't notice it was not copyable. Unfortunately this then requires quite a few test updates. Like #6034, this exposes a lowering issue where lowering crashes when attempting to lower a specific copy operation for certain types; a couple more tests are temporarily disabled here. An upcoming PR dependent on this one will fix the issue and re-enable those tests.
This commit is contained in:
@@ -16,12 +16,12 @@
|
||||
fn F[T:! type](x: T) {
|
||||
}
|
||||
|
||||
fn H[T:! type](x: T) -> T {
|
||||
fn H[T:! Core.Copy](x: T) -> T {
|
||||
F(x);
|
||||
return x;
|
||||
}
|
||||
|
||||
fn G[T:! type](x: T) -> T {
|
||||
fn G[T:! Core.Copy](x: T) -> T {
|
||||
H(x);
|
||||
F(x);
|
||||
return x;
|
||||
@@ -47,8 +47,8 @@ fn M() {
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %m.var), !dbg !8
|
||||
// CHECK:STDOUT: %.loc34 = load i32, ptr %n.var, align 4, !dbg !9
|
||||
// CHECK:STDOUT: call void @_CF.Main.b88d1103f417c6d4(i32 %.loc34), !dbg !10
|
||||
// CHECK:STDOUT: %.loc35 = load i32, ptr %n.var, align 4, !dbg !11
|
||||
// CHECK:STDOUT: %G.call = call i32 @_CG.Main.b88d1103f417c6d4(i32 %.loc35), !dbg !12
|
||||
// CHECK:STDOUT: %.loc35_9 = load i32, ptr %n.var, align 4, !dbg !11
|
||||
// CHECK:STDOUT: %G.call = call i32 @_CG.Main.b7c8e4dff2adcdaa(i32 %.loc35_9), !dbg !12
|
||||
// CHECK:STDOUT: store i32 %G.call, ptr %m.var, align 4, !dbg !13
|
||||
// CHECK:STDOUT: ret void, !dbg !14
|
||||
// CHECK:STDOUT: }
|
||||
@@ -61,14 +61,14 @@ fn M() {
|
||||
// CHECK:STDOUT: ret void, !dbg !16
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.b88d1103f417c6d4(i32 %x) !dbg !17 {
|
||||
// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.b7c8e4dff2adcdaa(i32 %x) !dbg !17 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %H.call = call i32 @_CH.Main.b88d1103f417c6d4(i32 %x), !dbg !18
|
||||
// CHECK:STDOUT: %H.call = call i32 @_CH.Main.b7c8e4dff2adcdaa(i32 %x), !dbg !18
|
||||
// CHECK:STDOUT: call void @_CF.Main.b88d1103f417c6d4(i32 %x), !dbg !19
|
||||
// CHECK:STDOUT: ret i32 %x, !dbg !20
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: define linkonce_odr i32 @_CH.Main.b88d1103f417c6d4(i32 %x) !dbg !21 {
|
||||
// CHECK:STDOUT: define linkonce_odr i32 @_CH.Main.b7c8e4dff2adcdaa(i32 %x) !dbg !21 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: call void @_CF.Main.b88d1103f417c6d4(i32 %x), !dbg !22
|
||||
// CHECK:STDOUT: ret i32 %x, !dbg !23
|
||||
@@ -99,10 +99,10 @@ fn M() {
|
||||
// CHECK:STDOUT: !14 = !DILocation(line: 30, column: 1, scope: !4)
|
||||
// CHECK:STDOUT: !15 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
||||
// CHECK:STDOUT: !16 = !DILocation(line: 16, column: 1, scope: !15)
|
||||
// CHECK:STDOUT: !17 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 24, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
||||
// CHECK:STDOUT: !17 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b7c8e4dff2adcdaa", scope: null, file: !3, line: 24, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
||||
// CHECK:STDOUT: !18 = !DILocation(line: 25, column: 3, scope: !17)
|
||||
// CHECK:STDOUT: !19 = !DILocation(line: 26, column: 3, scope: !17)
|
||||
// CHECK:STDOUT: !20 = !DILocation(line: 27, column: 3, scope: !17)
|
||||
// CHECK:STDOUT: !21 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main.b88d1103f417c6d4", scope: null, file: !3, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
||||
// CHECK:STDOUT: !21 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main.b7c8e4dff2adcdaa", scope: null, file: !3, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
||||
// CHECK:STDOUT: !22 = !DILocation(line: 20, column: 3, scope: !21)
|
||||
// CHECK:STDOUT: !23 = !DILocation(line: 21, column: 3, scope: !21)
|
||||
|
||||
Reference in New Issue
Block a user