basic.carbon 4.1 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: %Int32.type: type = fn_type @Int32 [template]
  19. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  20. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  21. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  22. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  23. // CHECK:STDOUT: %.2: i32 = int_literal 0 [template]
  24. // CHECK:STDOUT: %.3: type = ptr_type i32 [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  29. // CHECK:STDOUT: .Int32 = %import_ref
  30. // CHECK:STDOUT: import Core//prelude
  31. // CHECK:STDOUT: import Core//prelude/operators
  32. // CHECK:STDOUT: import Core//prelude/types
  33. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  34. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  35. // CHECK:STDOUT: import Core//prelude/operators/comparison
  36. // CHECK:STDOUT: import Core//prelude/types/bool
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .Core = imports.%Core
  44. // CHECK:STDOUT: .F = %F.decl
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Core.import = import Core
  47. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  48. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  49. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
  50. // CHECK:STDOUT: %.loc11_11.2: type = converted %int.make_type_32, %.loc11_11.1 [template = i32]
  51. // CHECK:STDOUT: @F.%return: ref i32 = var <return slot>
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: fn @F() -> i32 {
  58. // CHECK:STDOUT: !entry:
  59. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  60. // CHECK:STDOUT: %.loc12_10.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  61. // CHECK:STDOUT: %.loc12_10.2: type = converted %int.make_type_32.loc12, %.loc12_10.1 [template = i32]
  62. // CHECK:STDOUT: %n.var: ref i32 = var n
  63. // CHECK:STDOUT: %n: ref i32 = bind_name n, %n.var
  64. // CHECK:STDOUT: %.loc12_16: i32 = int_literal 0 [template = constants.%.2]
  65. // CHECK:STDOUT: assign %n.var, %.loc12_16
  66. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc13_13.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  68. // CHECK:STDOUT: %.loc13_13.2: type = converted %int.make_type_32.loc13, %.loc13_13.1 [template = i32]
  69. // CHECK:STDOUT: %.loc13_13.3: type = ptr_type i32 [template = constants.%.3]
  70. // CHECK:STDOUT: %p.var: ref %.3 = var p
  71. // CHECK:STDOUT: %p: ref %.3 = bind_name p, %p.var
  72. // CHECK:STDOUT: %n.ref: ref i32 = name_ref n, %n
  73. // CHECK:STDOUT: %.loc13_17: %.3 = addr_of %n.ref
  74. // CHECK:STDOUT: assign %p.var, %.loc13_17
  75. // CHECK:STDOUT: %p.ref: ref %.3 = name_ref p, %p
  76. // CHECK:STDOUT: %.loc15_11: %.3 = 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: