nested_const.carbon 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/nested_const.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/nested_const.carbon
  10. // TODO: The `const` in the return type should not be necessary.
  11. fn F(p: const (const (const i32*)*)) -> const i32 {
  12. return **p;
  13. }
  14. // CHECK:STDOUT: --- nested_const.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  18. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  19. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  20. // CHECK:STDOUT: %.2: type = const_type i32 [template]
  21. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  22. // CHECK:STDOUT: %.4: type = const_type %.3 [template]
  23. // CHECK:STDOUT: %.5: type = ptr_type %.4 [template]
  24. // CHECK:STDOUT: %.6: type = const_type %.5 [template]
  25. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  26. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: imports {
  30. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  31. // CHECK:STDOUT: .Int32 = %import_ref
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/operators
  34. // CHECK:STDOUT: import Core//prelude/types
  35. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  36. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  37. // CHECK:STDOUT: import Core//prelude/operators/comparison
  38. // CHECK:STDOUT: import Core//prelude/types/bool
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .Core = imports.%Core
  46. // CHECK:STDOUT: .F = %F.decl
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  50. // CHECK:STDOUT: %int.make_type_32.loc12_29: init type = call constants.%Int32() [template = i32]
  51. // CHECK:STDOUT: %.loc12_23.1: type = value_of_initializer %int.make_type_32.loc12_29 [template = i32]
  52. // CHECK:STDOUT: %.loc12_23.2: type = converted %int.make_type_32.loc12_29, %.loc12_23.1 [template = i32]
  53. // CHECK:STDOUT: %.loc12_23.3: type = const_type i32 [template = constants.%.2]
  54. // CHECK:STDOUT: %.loc12_32: type = ptr_type %.2 [template = constants.%.3]
  55. // CHECK:STDOUT: %.loc12_16: type = const_type %.3 [template = constants.%.4]
  56. // CHECK:STDOUT: %.loc12_34: type = ptr_type %.4 [template = constants.%.5]
  57. // CHECK:STDOUT: %.loc12_9: type = const_type %.5 [template = constants.%.6]
  58. // CHECK:STDOUT: %p.loc12_6.1: %.6 = param p
  59. // CHECK:STDOUT: @F.%p: %.6 = bind_name p, %p.loc12_6.1
  60. // CHECK:STDOUT: %int.make_type_32.loc12_47: init type = call constants.%Int32() [template = i32]
  61. // CHECK:STDOUT: %.loc12_41.1: type = value_of_initializer %int.make_type_32.loc12_47 [template = i32]
  62. // CHECK:STDOUT: %.loc12_41.2: type = converted %int.make_type_32.loc12_47, %.loc12_41.1 [template = i32]
  63. // CHECK:STDOUT: %.loc12_41.3: type = const_type i32 [template = constants.%.2]
  64. // CHECK:STDOUT: @F.%return: ref %.2 = var <return slot>
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: fn @F(%p: %.6) -> %.2 {
  71. // CHECK:STDOUT: !entry:
  72. // CHECK:STDOUT: %p.ref: %.6 = name_ref p, %p
  73. // CHECK:STDOUT: %.loc13_11.1: ref %.4 = deref %p.ref
  74. // CHECK:STDOUT: %.loc13_11.2: %.4 = bind_value %.loc13_11.1
  75. // CHECK:STDOUT: %.loc13_10.1: ref %.2 = deref %.loc13_11.2
  76. // CHECK:STDOUT: %.loc13_10.2: %.2 = bind_value %.loc13_10.1
  77. // CHECK:STDOUT: return %.loc13_10.2
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: