basic.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/pointer/basic.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/basic.carbon
  14. fn F() -> i32 {
  15. var n: i32 = 0;
  16. var p: i32* = &n;
  17. return *p;
  18. }
  19. // CHECK:STDOUT: --- basic.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  23. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  24. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  25. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  26. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  27. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  28. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  29. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  30. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  31. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  32. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  33. // CHECK:STDOUT: %ImplicitAs.type.e8c: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  34. // CHECK:STDOUT: %ImplicitAs.Convert.type.1b6: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
  35. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  36. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.49e: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  37. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.f01: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.49e = struct_value () [symbolic]
  38. // CHECK:STDOUT: %ImplicitAs.impl_witness.acc: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.b6b, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  39. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.9ec: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  40. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.592: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.9ec = struct_value () [concrete]
  41. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.e8c = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.acc) [concrete]
  42. // CHECK:STDOUT: %.7ea: type = fn_type_with_self_type %ImplicitAs.Convert.type.1b6, %ImplicitAs.facet [concrete]
  43. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %int_0.5c6, %Core.IntLiteral.as.ImplicitAs.impl.Convert.592 [concrete]
  44. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.592, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  45. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  46. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  47. // CHECK:STDOUT: %ptr.235: type = ptr_type %i32 [concrete]
  48. // CHECK:STDOUT: %pattern_type.fe8: type = pattern_type %ptr.235 [concrete]
  49. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  50. // CHECK:STDOUT: %T.as.Destroy.impl.Op.type.f2e: type = fn_type @T.as.Destroy.impl.Op, @T.as.Destroy.impl(%ptr.235) [concrete]
  51. // CHECK:STDOUT: %T.as.Destroy.impl.Op.fad: %T.as.Destroy.impl.Op.type.f2e = struct_value () [concrete]
  52. // CHECK:STDOUT: %ptr.5d5: type = ptr_type %ptr.235 [concrete]
  53. // CHECK:STDOUT: %T.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %T.as.Destroy.impl.Op.fad, @T.as.Destroy.impl.Op(%ptr.235) [concrete]
  54. // CHECK:STDOUT: %Int.as.Destroy.impl.Op.type.11b: type = fn_type @Int.as.Destroy.impl.Op, @Int.as.Destroy.impl(%int_32) [concrete]
  55. // CHECK:STDOUT: %Int.as.Destroy.impl.Op.054: %Int.as.Destroy.impl.Op.type.11b = struct_value () [concrete]
  56. // CHECK:STDOUT: %Int.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Destroy.impl.Op.054, @Int.as.Destroy.impl.Op(%int_32) [concrete]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: imports {
  60. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  61. // CHECK:STDOUT: .Int = %Core.Int
  62. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  63. // CHECK:STDOUT: .Destroy = %Core.Destroy
  64. // CHECK:STDOUT: import Core//prelude
  65. // CHECK:STDOUT: import Core//prelude/...
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  68. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  69. // CHECK:STDOUT: %Core.import_ref.428: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.49e) = import_ref Core//prelude/parts/int, loc16_39, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.f01)]
  70. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.b6b = impl_witness_table (%Core.import_ref.428), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  71. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  76. // CHECK:STDOUT: .Core = imports.%Core
  77. // CHECK:STDOUT: .F = %F.decl
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %Core.import = import Core
  80. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  81. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  82. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  83. // CHECK:STDOUT: } {
  84. // CHECK:STDOUT: %int_32.loc15: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  85. // CHECK:STDOUT: %i32.loc15: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  86. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  87. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @F() -> %i32 {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: name_binding_decl {
  94. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = binding_pattern n [concrete]
  95. // CHECK:STDOUT: %n.var_patt: %pattern_type.7ce = var_pattern %n.patt [concrete]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %n.var: ref %i32 = var %n.var_patt
  98. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  99. // CHECK:STDOUT: %impl.elem0: %.7ea = impl_witness_access constants.%ImplicitAs.impl_witness.acc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.592]
  100. // CHECK:STDOUT: %bound_method.loc16_3.1: <bound method> = bound_method %int_0, %impl.elem0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  101. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  102. // CHECK:STDOUT: %bound_method.loc16_3.2: <bound method> = bound_method %int_0, %specific_fn [concrete = constants.%bound_method]
  103. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %i32 = call %bound_method.loc16_3.2(%int_0) [concrete = constants.%int_0.6a9]
  104. // CHECK:STDOUT: %.loc16_3: init %i32 = converted %int_0, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_0.6a9]
  105. // CHECK:STDOUT: assign %n.var, %.loc16_3
  106. // CHECK:STDOUT: %.loc16_10: type = splice_block %i32.loc16 [concrete = constants.%i32] {
  107. // CHECK:STDOUT: %int_32.loc16: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  108. // CHECK:STDOUT: %i32.loc16: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %n: ref %i32 = bind_name n, %n.var
  111. // CHECK:STDOUT: name_binding_decl {
  112. // CHECK:STDOUT: %p.patt: %pattern_type.fe8 = binding_pattern p [concrete]
  113. // CHECK:STDOUT: %p.var_patt: %pattern_type.fe8 = var_pattern %p.patt [concrete]
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %p.var: ref %ptr.235 = var %p.var_patt
  116. // CHECK:STDOUT: %n.ref: ref %i32 = name_ref n, %n
  117. // CHECK:STDOUT: %addr.loc17_17: %ptr.235 = addr_of %n.ref
  118. // CHECK:STDOUT: assign %p.var, %addr.loc17_17
  119. // CHECK:STDOUT: %.loc17: type = splice_block %ptr [concrete = constants.%ptr.235] {
  120. // CHECK:STDOUT: %int_32.loc17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  121. // CHECK:STDOUT: %i32.loc17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  122. // CHECK:STDOUT: %ptr: type = ptr_type %i32.loc17 [concrete = constants.%ptr.235]
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %p: ref %ptr.235 = bind_name p, %p.var
  125. // CHECK:STDOUT: %p.ref: ref %ptr.235 = name_ref p, %p
  126. // CHECK:STDOUT: %.loc19_11: %ptr.235 = bind_value %p.ref
  127. // CHECK:STDOUT: %.loc19_10.1: ref %i32 = deref %.loc19_11
  128. // CHECK:STDOUT: %.loc19_10.2: %i32 = bind_value %.loc19_10.1
  129. // CHECK:STDOUT: %T.as.Destroy.impl.Op.bound: <bound method> = bound_method %p.var, constants.%T.as.Destroy.impl.Op.fad
  130. // CHECK:STDOUT: %T.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function constants.%T.as.Destroy.impl.Op.fad, @T.as.Destroy.impl.Op(constants.%ptr.235) [concrete = constants.%T.as.Destroy.impl.Op.specific_fn]
  131. // CHECK:STDOUT: %bound_method.loc17: <bound method> = bound_method %p.var, %T.as.Destroy.impl.Op.specific_fn
  132. // CHECK:STDOUT: %addr.loc17_3: %ptr.5d5 = addr_of %p.var
  133. // CHECK:STDOUT: %T.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc17(%addr.loc17_3)
  134. // CHECK:STDOUT: %Int.as.Destroy.impl.Op.bound: <bound method> = bound_method %n.var, constants.%Int.as.Destroy.impl.Op.054
  135. // CHECK:STDOUT: %Int.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function constants.%Int.as.Destroy.impl.Op.054, @Int.as.Destroy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Destroy.impl.Op.specific_fn]
  136. // CHECK:STDOUT: %bound_method.loc16_3.3: <bound method> = bound_method %n.var, %Int.as.Destroy.impl.Op.specific_fn
  137. // CHECK:STDOUT: %addr.loc16: %ptr.235 = addr_of %n.var
  138. // CHECK:STDOUT: %Int.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc16_3.3(%addr.loc16)
  139. // CHECK:STDOUT: return %.loc19_10.2
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: