member_access.carbon 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/struct/member_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/struct/member_access.carbon
  10. fn Run() -> i32 {
  11. var x: {.a: f64, .b: i32} = {.a = 0.0, .b = 1};
  12. var y: i32 = x.b;
  13. var z: i32 = y;
  14. return 0;
  15. }
  16. // CHECK:STDOUT: ; ModuleID = 'member_access.carbon'
  17. // CHECK:STDOUT: source_filename = "member_access.carbon"
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: @struct.loc12_49 = internal constant { double, i32 } { double 0.000000e+00, i32 1 }
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: define i32 @main() {
  22. // CHECK:STDOUT: entry:
  23. // CHECK:STDOUT: %x.var = alloca { double, i32 }, align 8
  24. // CHECK:STDOUT: %.loc12_48.2.a = getelementptr inbounds nuw { double, i32 }, ptr %x.var, i32 0, i32 0
  25. // CHECK:STDOUT: %.loc12_48.4.b = getelementptr inbounds nuw { double, i32 }, ptr %x.var, i32 0, i32 1
  26. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %x.var, ptr align 8 @struct.loc12_49, i64 16, i1 false)
  27. // CHECK:STDOUT: %y.var = alloca i32, align 4
  28. // CHECK:STDOUT: %.loc13_17.1.b = getelementptr inbounds nuw { double, i32 }, ptr %x.var, i32 0, i32 1
  29. // CHECK:STDOUT: %.loc13_17.2 = load i32, ptr %.loc13_17.1.b, align 4
  30. // CHECK:STDOUT: store i32 %.loc13_17.2, ptr %y.var, align 4
  31. // CHECK:STDOUT: %z.var = alloca i32, align 4
  32. // CHECK:STDOUT: %.loc14_16 = load i32, ptr %y.var, align 4
  33. // CHECK:STDOUT: store i32 %.loc14_16, ptr %z.var, align 4
  34. // CHECK:STDOUT: ret i32 0
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  38. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }