basic.carbon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/pointer/basic.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/basic.carbon
  10. fn F() -> i32 {
  11. var n: i32 = 0;
  12. var p: i32* = &n;
  13. return *p;
  14. }
  15. // CHECK:STDOUT: --- basic.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  19. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  20. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  21. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  22. // CHECK:STDOUT: %int_0.1: Core.IntLiteral = int_value 0 [template]
  23. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  24. // CHECK:STDOUT: %impl_witness.19: <witness> = impl_witness (imports.%import_ref.14), @impl.1(%int_32) [template]
  25. // CHECK:STDOUT: %Convert.type.10: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  26. // CHECK:STDOUT: %Convert.10: %Convert.type.10 = struct_value () [template]
  27. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.1, %Convert.10 [template]
  28. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  29. // CHECK:STDOUT: %int_0.2: %i32 = int_value 0 [template]
  30. // CHECK:STDOUT: %ptr: type = ptr_type %i32 [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  35. // CHECK:STDOUT: .Int = %import_ref.1
  36. // CHECK:STDOUT: .ImplicitAs = %import_ref.5
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .F = %F.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  49. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  50. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  51. // CHECK:STDOUT: } {
  52. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  53. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  54. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  55. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @F() -> %i32 {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: %n.var: ref %i32 = var n
  62. // CHECK:STDOUT: %n: ref %i32 = bind_name n, %n.var
  63. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0.1]
  64. // CHECK:STDOUT: %impl.elem0: %Convert.type.2 = impl_witness_access constants.%impl_witness.19, element0 [template = constants.%Convert.10]
  65. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound]
  66. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  67. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_0) [template = constants.%int_0.2]
  68. // CHECK:STDOUT: %.loc12: init %i32 = converted %int_0, %int.convert_checked [template = constants.%int_0.2]
  69. // CHECK:STDOUT: assign %n.var, %.loc12
  70. // CHECK:STDOUT: %p.var: ref %ptr = var p
  71. // CHECK:STDOUT: %p: ref %ptr = bind_name p, %p.var
  72. // CHECK:STDOUT: %n.ref: ref %i32 = name_ref n, %n
  73. // CHECK:STDOUT: %addr: %ptr = addr_of %n.ref
  74. // CHECK:STDOUT: assign %p.var, %addr
  75. // CHECK:STDOUT: %p.ref: ref %ptr = name_ref p, %p
  76. // CHECK:STDOUT: %.loc15_11: %ptr = bind_value %p.ref
  77. // CHECK:STDOUT: %.loc15_10.1: ref %i32 = deref %.loc15_11
  78. // CHECK:STDOUT: %.loc15_10.2: %i32 = bind_value %.loc15_10.1
  79. // CHECK:STDOUT: return %.loc15_10.2
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: