mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 13:45:01 +01:00
Per the design, field access into a class value expression is a value expression, even though we could produce an ephemeral reference expression instead and avoid performing a value binding. This slightly pessimizes class member access in some cases, but we should be able to restore the old generated code by deferring actually performing the value binding until a value expression is needed.
40 lines
1.9 KiB
Plaintext
40 lines
1.9 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
|
|
//
|
|
// AUTOUPDATE
|
|
|
|
class C {
|
|
var a: (i32, i32, i32);
|
|
}
|
|
|
|
fn F(c: C) -> i32 {
|
|
// TODO: `c.a` is a value expression here, which forces a value binding as
|
|
// part of the member access, creating a tuple value temporary. We could
|
|
// defer performing the value binding to avoid creating this temporary.
|
|
return c.a[1];
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'value_access.carbon'
|
|
// CHECK:STDOUT: source_filename = "value_access.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @F(ptr %c) {
|
|
// CHECK:STDOUT: %a = getelementptr inbounds { { i32, i32, i32 } }, ptr %c, i32 0, i32 0
|
|
// CHECK:STDOUT: %tuple.elem = getelementptr inbounds { i32, i32, i32 }, ptr %a, i32 0, i32 0
|
|
// CHECK:STDOUT: %1 = load i32, ptr %tuple.elem, align 4
|
|
// CHECK:STDOUT: %tuple.elem1 = getelementptr inbounds { i32, i32, i32 }, ptr %a, i32 0, i32 1
|
|
// CHECK:STDOUT: %2 = load i32, ptr %tuple.elem1, align 4
|
|
// CHECK:STDOUT: %tuple.elem2 = getelementptr inbounds { i32, i32, i32 }, ptr %a, i32 0, i32 2
|
|
// CHECK:STDOUT: %3 = load i32, ptr %tuple.elem2, align 4
|
|
// CHECK:STDOUT: %tuple = alloca { i32, i32, i32 }, align 8
|
|
// CHECK:STDOUT: %4 = getelementptr inbounds { i32, i32, i32 }, ptr %tuple, i32 0, i32 0
|
|
// CHECK:STDOUT: store i32 %1, ptr %4, align 4
|
|
// CHECK:STDOUT: %5 = getelementptr inbounds { i32, i32, i32 }, ptr %tuple, i32 0, i32 1
|
|
// CHECK:STDOUT: store i32 %2, ptr %5, align 4
|
|
// CHECK:STDOUT: %6 = getelementptr inbounds { i32, i32, i32 }, ptr %tuple, i32 0, i32 2
|
|
// CHECK:STDOUT: store i32 %3, ptr %6, align 4
|
|
// CHECK:STDOUT: %tuple.index = getelementptr inbounds { i32, i32, i32 }, ptr %tuple, i32 0, i32 1
|
|
// CHECK:STDOUT: %tuple.index.load = load i32, ptr %tuple.index, align 4
|
|
// CHECK:STDOUT: ret i32 %tuple.index.load
|
|
// CHECK:STDOUT: }
|