identity.carbon 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // `expr as T` should behave the same as `expr` if `T` is the type of `expr`.
  7. class X {
  8. // ...
  9. }
  10. fn Value(n: X) {
  11. let m: X = n as X;
  12. }
  13. fn Reference(p: X*) {
  14. let q: X* = &(*p as X);
  15. }
  16. fn Make() -> X;
  17. fn Initializing() {
  18. var x: X = (Make() as X);
  19. }
  20. // CHECK:STDOUT: --- identity.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %X: type = class_type @X [template]
  24. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  25. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  26. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  27. // CHECK:STDOUT: %.4: type = ptr_type X [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: file {
  31. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  32. // CHECK:STDOUT: .X = %X.decl
  33. // CHECK:STDOUT: .Value = %Value
  34. // CHECK:STDOUT: .Reference = %Reference
  35. // CHECK:STDOUT: .Make = %Make
  36. // CHECK:STDOUT: .Initializing = %Initializing
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {}
  39. // CHECK:STDOUT: %Value: <function> = fn_decl @Value [template] {
  40. // CHECK:STDOUT: %X.ref.loc13: type = name_ref X, %X.decl [template = constants.%X]
  41. // CHECK:STDOUT: %n.loc13_10.1: X = param n
  42. // CHECK:STDOUT: @Value.%n: X = bind_name n, %n.loc13_10.1
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %Reference: <function> = fn_decl @Reference [template] {
  45. // CHECK:STDOUT: %X.ref.loc17: type = name_ref X, %X.decl [template = constants.%X]
  46. // CHECK:STDOUT: %.loc17: type = ptr_type X [template = constants.%.4]
  47. // CHECK:STDOUT: %p.loc17_14.1: X* = param p
  48. // CHECK:STDOUT: @Reference.%p: X* = bind_name p, %p.loc17_14.1
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Make: <function> = fn_decl @Make [template] {
  51. // CHECK:STDOUT: %X.ref.loc21: type = name_ref X, %X.decl [template = constants.%X]
  52. // CHECK:STDOUT: @Make.%return: ref X = var <return slot>
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Initializing: <function> = fn_decl @Initializing [template] {}
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: class @X {
  58. // CHECK:STDOUT: !members:
  59. // CHECK:STDOUT: .Self = constants.%X
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: fn @Value(%n: X) {
  63. // CHECK:STDOUT: !entry:
  64. // CHECK:STDOUT: %X.ref.loc14_10: type = name_ref X, file.%X.decl [template = constants.%X]
  65. // CHECK:STDOUT: %n.ref: X = name_ref n, %n
  66. // CHECK:STDOUT: %X.ref.loc14_19: type = name_ref X, file.%X.decl [template = constants.%X]
  67. // CHECK:STDOUT: %m: X = bind_name m, %n.ref
  68. // CHECK:STDOUT: return
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @Reference(%p: X*) {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: %X.ref.loc18_10: type = name_ref X, file.%X.decl [template = constants.%X]
  74. // CHECK:STDOUT: %.loc18_11: type = ptr_type X [template = constants.%.4]
  75. // CHECK:STDOUT: %p.ref: X* = name_ref p, %p
  76. // CHECK:STDOUT: %.loc18_17: ref X = deref %p.ref
  77. // CHECK:STDOUT: %X.ref.loc18_23: type = name_ref X, file.%X.decl [template = constants.%X]
  78. // CHECK:STDOUT: %.loc18_15: X* = addr_of %.loc18_17
  79. // CHECK:STDOUT: %q: X* = bind_name q, %.loc18_15
  80. // CHECK:STDOUT: return
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @Make() -> %return: X;
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @Initializing() {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: %X.ref.loc24_10: type = name_ref X, file.%X.decl [template = constants.%X]
  88. // CHECK:STDOUT: %x.var: ref X = var x
  89. // CHECK:STDOUT: %x: ref X = bind_name x, %x.var
  90. // CHECK:STDOUT: %Make.ref: <function> = name_ref Make, file.%Make [template = file.%Make]
  91. // CHECK:STDOUT: %.loc24_7: ref X = splice_block %x.var {}
  92. // CHECK:STDOUT: %.loc24_19: init X = call %Make.ref() to %.loc24_7
  93. // CHECK:STDOUT: %X.ref.loc24_25: type = name_ref X, file.%X.decl [template = constants.%X]
  94. // CHECK:STDOUT: assign %x.var, %.loc24_19
  95. // CHECK:STDOUT: return
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: