field_access_in_value.carbon 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/check/testdata/class/field_access_in_value.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/field_access_in_value.carbon
  10. class Class {
  11. var j: i32;
  12. var k: i32;
  13. }
  14. fn Test() {
  15. var cv: Class;
  16. cv.j = 1;
  17. cv.k = 2;
  18. let c: Class = cv;
  19. var cj: i32 = c.j;
  20. var ck: i32 = c.k;
  21. }
  22. // CHECK:STDOUT: --- field_access_in_value.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  26. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  27. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  28. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  29. // CHECK:STDOUT: %.2: type = unbound_element_type %Class, i32 [template]
  30. // CHECK:STDOUT: %.3: type = struct_type {.j: i32, .k: i32} [template]
  31. // CHECK:STDOUT: %Test.type: type = fn_type @Test [template]
  32. // CHECK:STDOUT: %Test: %Test.type = struct_value () [template]
  33. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  34. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  35. // CHECK:STDOUT: %.6: i32 = int_literal 2 [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = %Core
  41. // CHECK:STDOUT: .Class = %Class.decl
  42. // CHECK:STDOUT: .Test = %Test.decl
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  45. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  46. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  47. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  48. // CHECK:STDOUT: %Test.decl: %Test.type = fn_decl @Test [template = constants.%Test] {}
  49. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  50. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: class @Class {
  54. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  55. // CHECK:STDOUT: %.loc12_10.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  56. // CHECK:STDOUT: %.loc12_10.2: type = converted %int.make_type_32.loc12, %.loc12_10.1 [template = i32]
  57. // CHECK:STDOUT: %.loc12_8: %.2 = field_decl j, element0 [template]
  58. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %.loc13_10.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  60. // CHECK:STDOUT: %.loc13_10.2: type = converted %int.make_type_32.loc13, %.loc13_10.1 [template = i32]
  61. // CHECK:STDOUT: %.loc13_8: %.2 = field_decl k, element1 [template]
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: !members:
  64. // CHECK:STDOUT: .Self = constants.%Class
  65. // CHECK:STDOUT: .j = %.loc12_8
  66. // CHECK:STDOUT: .k = %.loc13_8
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @Test() {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: %Class.ref.loc17: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  74. // CHECK:STDOUT: %cv.var: ref %Class = var cv
  75. // CHECK:STDOUT: %cv: ref %Class = bind_name cv, %cv.var
  76. // CHECK:STDOUT: %cv.ref.loc18: ref %Class = name_ref cv, %cv
  77. // CHECK:STDOUT: %j.ref.loc18: %.2 = name_ref j, @Class.%.loc12_8 [template = @Class.%.loc12_8]
  78. // CHECK:STDOUT: %.loc18_5: ref i32 = class_element_access %cv.ref.loc18, element0
  79. // CHECK:STDOUT: %.loc18_10: i32 = int_literal 1 [template = constants.%.5]
  80. // CHECK:STDOUT: assign %.loc18_5, %.loc18_10
  81. // CHECK:STDOUT: %cv.ref.loc19: ref %Class = name_ref cv, %cv
  82. // CHECK:STDOUT: %k.ref.loc19: %.2 = name_ref k, @Class.%.loc13_8 [template = @Class.%.loc13_8]
  83. // CHECK:STDOUT: %.loc19_5: ref i32 = class_element_access %cv.ref.loc19, element1
  84. // CHECK:STDOUT: %.loc19_10: i32 = int_literal 2 [template = constants.%.6]
  85. // CHECK:STDOUT: assign %.loc19_5, %.loc19_10
  86. // CHECK:STDOUT: %Class.ref.loc20: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  87. // CHECK:STDOUT: %cv.ref.loc20: ref %Class = name_ref cv, %cv
  88. // CHECK:STDOUT: %.loc20: %Class = bind_value %cv.ref.loc20
  89. // CHECK:STDOUT: %c: %Class = bind_name c, %.loc20
  90. // CHECK:STDOUT: %int.make_type_32.loc21: init type = call constants.%Int32() [template = i32]
  91. // CHECK:STDOUT: %.loc21_11.1: type = value_of_initializer %int.make_type_32.loc21 [template = i32]
  92. // CHECK:STDOUT: %.loc21_11.2: type = converted %int.make_type_32.loc21, %.loc21_11.1 [template = i32]
  93. // CHECK:STDOUT: %cj.var: ref i32 = var cj
  94. // CHECK:STDOUT: %cj: ref i32 = bind_name cj, %cj.var
  95. // CHECK:STDOUT: %c.ref.loc21: %Class = name_ref c, %c
  96. // CHECK:STDOUT: %j.ref.loc21: %.2 = name_ref j, @Class.%.loc12_8 [template = @Class.%.loc12_8]
  97. // CHECK:STDOUT: %.loc21_18.1: ref i32 = class_element_access %c.ref.loc21, element0
  98. // CHECK:STDOUT: %.loc21_18.2: i32 = bind_value %.loc21_18.1
  99. // CHECK:STDOUT: assign %cj.var, %.loc21_18.2
  100. // CHECK:STDOUT: %int.make_type_32.loc22: init type = call constants.%Int32() [template = i32]
  101. // CHECK:STDOUT: %.loc22_11.1: type = value_of_initializer %int.make_type_32.loc22 [template = i32]
  102. // CHECK:STDOUT: %.loc22_11.2: type = converted %int.make_type_32.loc22, %.loc22_11.1 [template = i32]
  103. // CHECK:STDOUT: %ck.var: ref i32 = var ck
  104. // CHECK:STDOUT: %ck: ref i32 = bind_name ck, %ck.var
  105. // CHECK:STDOUT: %c.ref.loc22: %Class = name_ref c, %c
  106. // CHECK:STDOUT: %k.ref.loc22: %.2 = name_ref k, @Class.%.loc13_8 [template = @Class.%.loc13_8]
  107. // CHECK:STDOUT: %.loc22_18.1: ref i32 = class_element_access %c.ref.loc22, element1
  108. // CHECK:STDOUT: %.loc22_18.2: i32 = bind_value %.loc22_18.1
  109. // CHECK:STDOUT: assign %ck.var, %.loc22_18.2
  110. // CHECK:STDOUT: return
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: