ref.carbon 3.5 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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=only
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/declaration/ref.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/declaration/ref.carbon
  13. // --- ref_return.carbon
  14. //@include-in-dumps
  15. fn F() -> ref i32;
  16. fn G() {
  17. let unused ref x: i32 = F();
  18. }
  19. // CHECK:STDOUT: --- ref_return.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: %Int.generic: %Int.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  26. // CHECK:STDOUT: %.1da: Core.Form = ref_form %i32 [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: %G.type: type = fn_type @G [concrete]
  31. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  36. // CHECK:STDOUT: .Int = %Core.Int
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  45. // CHECK:STDOUT: .Core = imports.%Core
  46. // CHECK:STDOUT: .F = %F.decl
  47. // CHECK:STDOUT: .G = %G.decl
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core.import = import Core
  50. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  51. // CHECK:STDOUT: %.loc4_11.1: %pattern_type.7ce = ref_return_pattern [concrete]
  52. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern %.loc4_11.1, %i32 [concrete]
  53. // CHECK:STDOUT: } {
  54. // CHECK:STDOUT: %i32: type = type_literal constants.%i32 [concrete = constants.%i32]
  55. // CHECK:STDOUT: %.loc4_11.2: type = ref_tag %i32
  56. // CHECK:STDOUT: %.loc4_11.3: Core.Form = ref_form %i32 [concrete = constants.%.1da]
  57. // CHECK:STDOUT: %.loc4_11.4: ref %i32 = ref_return
  58. // CHECK:STDOUT: %return: ref %i32 = return_slot %.loc4_11.4
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @F() -> ref %i32;
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @G() {
  66. // CHECK:STDOUT: !entry:
  67. // CHECK:STDOUT: name_binding_decl {
  68. // CHECK:STDOUT: %x.patt: %pattern_type.7ce = ref_binding_pattern x [concrete]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  71. // CHECK:STDOUT: %F.call: ref %i32 = call %F.ref()
  72. // CHECK:STDOUT: %i32: type = type_literal constants.%i32 [concrete = constants.%i32]
  73. // CHECK:STDOUT: %x: ref %i32 = ref_binding x, %F.call
  74. // CHECK:STDOUT: return
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: