base_field.carbon 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. base class Base {
  7. var a: i32;
  8. var b: i32;
  9. var c: i32;
  10. }
  11. class Derived {
  12. extend base: Base;
  13. var d: i32;
  14. var e: i32;
  15. }
  16. fn Access(p: Derived*) -> i32* {
  17. return &(*p).c;
  18. }
  19. // CHECK:STDOUT: --- base_field.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  23. // CHECK:STDOUT: %.1: type = unbound_element_type Base, i32 [template]
  24. // CHECK:STDOUT: %.2: type = struct_type {.a: i32, .b: i32, .c: i32} [template]
  25. // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
  26. // CHECK:STDOUT: %.3: type = ptr_type {.a: i32, .b: i32, .c: i32} [template]
  27. // CHECK:STDOUT: %.4: type = unbound_element_type Derived, Base [template]
  28. // CHECK:STDOUT: %.5: type = unbound_element_type Derived, i32 [template]
  29. // CHECK:STDOUT: %.6: type = struct_type {.base: Base, .d: i32, .e: i32} [template]
  30. // CHECK:STDOUT: %.7: type = ptr_type Derived [template]
  31. // CHECK:STDOUT: %.8: type = ptr_type i32 [template]
  32. // CHECK:STDOUT: %.9: type = struct_type {.base: {.a: i32, .b: i32, .c: i32}*, .d: i32, .e: i32} [template]
  33. // CHECK:STDOUT: %.10: type = ptr_type {.base: {.a: i32, .b: i32, .c: i32}*, .d: i32, .e: i32} [template]
  34. // CHECK:STDOUT: %.11: type = ptr_type {.base: Base, .d: i32, .e: i32} [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .Base = %Base.decl
  40. // CHECK:STDOUT: .Derived = %Derived.decl
  41. // CHECK:STDOUT: .Access = %Access
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {}
  44. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {}
  45. // CHECK:STDOUT: %Access: <function> = fn_decl @Access [template] {
  46. // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, %Derived.decl [template = constants.%Derived]
  47. // CHECK:STDOUT: %.loc20_21: type = ptr_type Derived [template = constants.%.7]
  48. // CHECK:STDOUT: %p.loc20_11.1: Derived* = param p
  49. // CHECK:STDOUT: @Access.%p: Derived* = bind_name p, %p.loc20_11.1
  50. // CHECK:STDOUT: %.loc20_30: type = ptr_type i32 [template = constants.%.8]
  51. // CHECK:STDOUT: %return.var: ref i32* = var <return slot>
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: class @Base {
  56. // CHECK:STDOUT: %.loc8: <unbound element of class Base> = field_decl a, element0 [template]
  57. // CHECK:STDOUT: %.loc9: <unbound element of class Base> = field_decl b, element1 [template]
  58. // CHECK:STDOUT: %.loc10: <unbound element of class Base> = field_decl c, element2 [template]
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: !members:
  61. // CHECK:STDOUT: .Self = constants.%Base
  62. // CHECK:STDOUT: .a = %.loc8
  63. // CHECK:STDOUT: .b = %.loc9
  64. // CHECK:STDOUT: .c = %.loc10
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: class @Derived {
  68. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  69. // CHECK:STDOUT: %.loc14: <unbound element of class Derived> = base_decl Base, element0 [template]
  70. // CHECK:STDOUT: %.loc16: <unbound element of class Derived> = field_decl d, element1 [template]
  71. // CHECK:STDOUT: %.loc17: <unbound element of class Derived> = field_decl e, element2 [template]
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: !members:
  74. // CHECK:STDOUT: .Self = constants.%Derived
  75. // CHECK:STDOUT: .base = %.loc14
  76. // CHECK:STDOUT: .d = %.loc16
  77. // CHECK:STDOUT: .e = %.loc17
  78. // CHECK:STDOUT: extend name_scope1
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @Access(%p: Derived*) -> i32* {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: %p.ref: Derived* = name_ref p, %p
  84. // CHECK:STDOUT: %.loc21_12.1: ref Derived = deref %p.ref
  85. // CHECK:STDOUT: %c.ref: <unbound element of class Base> = name_ref c, @Base.%.loc10 [template = @Base.%.loc10]
  86. // CHECK:STDOUT: %.loc21_15.1: ref Base = class_element_access %.loc21_12.1, element0
  87. // CHECK:STDOUT: %.loc21_12.2: ref Base = converted %.loc21_12.1, %.loc21_15.1
  88. // CHECK:STDOUT: %.loc21_15.2: ref i32 = class_element_access %.loc21_12.2, element2
  89. // CHECK:STDOUT: %.loc21_10: i32* = addr_of %.loc21_15.2
  90. // CHECK:STDOUT: return %.loc21_10
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: