nested_const.carbon 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/nested_const.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/nested_const.carbon
  14. // TODO: The `const` in the return type should not be necessary.
  15. fn F(p: const (const (const i32*)*)) -> const i32 {
  16. return **p;
  17. }
  18. // CHECK:STDOUT: --- nested_const.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  22. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  23. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  24. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  25. // CHECK:STDOUT: %const.20a: type = const_type %i32 [concrete]
  26. // CHECK:STDOUT: %ptr.36b: type = ptr_type %const.20a [concrete]
  27. // CHECK:STDOUT: %const.58f: type = const_type %ptr.36b [concrete]
  28. // CHECK:STDOUT: %ptr.6e8: type = ptr_type %const.58f [concrete]
  29. // CHECK:STDOUT: %const.fa2: type = const_type %ptr.6e8 [concrete]
  30. // CHECK:STDOUT: %pattern_type.800: type = pattern_type %const.fa2 [concrete]
  31. // CHECK:STDOUT: %pattern_type.a65: type = pattern_type %const.20a [concrete]
  32. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  33. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: imports {
  37. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  38. // CHECK:STDOUT: .Int = %Core.Int
  39. // CHECK:STDOUT: import Core//prelude
  40. // CHECK:STDOUT: import Core//prelude/...
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  47. // CHECK:STDOUT: .Core = imports.%Core
  48. // CHECK:STDOUT: .F = %F.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  52. // CHECK:STDOUT: %p.patt: %pattern_type.800 = binding_pattern p [concrete]
  53. // CHECK:STDOUT: %p.param_patt: %pattern_type.800 = value_param_pattern %p.patt, call_param0 [concrete]
  54. // CHECK:STDOUT: %return.patt: %pattern_type.a65 = return_slot_pattern [concrete]
  55. // CHECK:STDOUT: %return.param_patt: %pattern_type.a65 = out_param_pattern %return.patt, call_param1 [concrete]
  56. // CHECK:STDOUT: } {
  57. // CHECK:STDOUT: %int_32.loc16_47: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  58. // CHECK:STDOUT: %i32.loc16_47: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  59. // CHECK:STDOUT: %const.loc16_41: type = const_type %i32.loc16_47 [concrete = constants.%const.20a]
  60. // CHECK:STDOUT: %p.param: %const.fa2 = value_param call_param0
  61. // CHECK:STDOUT: %.loc16: type = splice_block %const.loc16_9 [concrete = constants.%const.fa2] {
  62. // CHECK:STDOUT: %int_32.loc16_29: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  63. // CHECK:STDOUT: %i32.loc16_29: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  64. // CHECK:STDOUT: %const.loc16_23: type = const_type %i32.loc16_29 [concrete = constants.%const.20a]
  65. // CHECK:STDOUT: %ptr.loc16_32: type = ptr_type %const.loc16_23 [concrete = constants.%ptr.36b]
  66. // CHECK:STDOUT: %const.loc16_16: type = const_type %ptr.loc16_32 [concrete = constants.%const.58f]
  67. // CHECK:STDOUT: %ptr.loc16_34: type = ptr_type %const.loc16_16 [concrete = constants.%ptr.6e8]
  68. // CHECK:STDOUT: %const.loc16_9: type = const_type %ptr.loc16_34 [concrete = constants.%const.fa2]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %p: %const.fa2 = bind_name p, %p.param
  71. // CHECK:STDOUT: %return.param: ref %const.20a = out_param call_param1
  72. // CHECK:STDOUT: %return: ref %const.20a = return_slot %return.param
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @F(%p.param: %const.fa2) -> %const.20a {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: %p.ref: %const.fa2 = name_ref p, %p
  79. // CHECK:STDOUT: %.loc17_11.1: ref %const.58f = deref %p.ref
  80. // CHECK:STDOUT: %.loc17_11.2: %const.58f = bind_value %.loc17_11.1
  81. // CHECK:STDOUT: %.loc17_10.1: ref %const.20a = deref %.loc17_11.2
  82. // CHECK:STDOUT: %.loc17_10.2: %const.20a = bind_value %.loc17_10.1
  83. // CHECK:STDOUT: return %.loc17_10.2
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: