value_access.carbon 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. class C {
  7. var a: (i32, i32, i32);
  8. }
  9. fn F(c: C) -> i32 {
  10. // TODO: `c.a` is a value expression here, which forces a value binding as
  11. // part of the member access, creating a tuple value temporary. We could
  12. // defer performing the value binding to avoid creating this temporary.
  13. return c.a[1];
  14. }
  15. // CHECK:STDOUT: ; ModuleID = 'value_access.carbon'
  16. // CHECK:STDOUT: source_filename = "value_access.carbon"
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: define i32 @F(ptr %c) {
  19. // CHECK:STDOUT: %a = getelementptr inbounds { { i32, i32, i32 } }, ptr %c, i32 0, i32 0
  20. // CHECK:STDOUT: %tuple.elem = getelementptr inbounds { i32, i32, i32 }, ptr %a, i32 0, i32 0
  21. // CHECK:STDOUT: %1 = load i32, ptr %tuple.elem, align 4
  22. // CHECK:STDOUT: %tuple.elem1 = getelementptr inbounds { i32, i32, i32 }, ptr %a, i32 0, i32 1
  23. // CHECK:STDOUT: %2 = load i32, ptr %tuple.elem1, align 4
  24. // CHECK:STDOUT: %tuple.elem2 = getelementptr inbounds { i32, i32, i32 }, ptr %a, i32 0, i32 2
  25. // CHECK:STDOUT: %3 = load i32, ptr %tuple.elem2, align 4
  26. // CHECK:STDOUT: %tuple = alloca { i32, i32, i32 }, align 8
  27. // CHECK:STDOUT: %4 = getelementptr inbounds { i32, i32, i32 }, ptr %tuple, i32 0, i32 0
  28. // CHECK:STDOUT: store i32 %1, ptr %4, align 4
  29. // CHECK:STDOUT: %5 = getelementptr inbounds { i32, i32, i32 }, ptr %tuple, i32 0, i32 1
  30. // CHECK:STDOUT: store i32 %2, ptr %5, align 4
  31. // CHECK:STDOUT: %6 = getelementptr inbounds { i32, i32, i32 }, ptr %tuple, i32 0, i32 2
  32. // CHECK:STDOUT: store i32 %3, ptr %6, align 4
  33. // CHECK:STDOUT: %tuple.index = getelementptr inbounds { i32, i32, i32 }, ptr %tuple, i32 0, i32 1
  34. // CHECK:STDOUT: %tuple.index.load = load i32, ptr %tuple.index, align 4
  35. // CHECK:STDOUT: ret i32 %tuple.index.load
  36. // CHECK:STDOUT: }