basic.carbon 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/const/basic.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/const/basic.carbon
  10. fn A(p: const i32**) -> const i32** {
  11. return p;
  12. }
  13. fn B(p: const (i32*)) -> const (i32*) {
  14. return p;
  15. }
  16. // CHECK:STDOUT: --- basic.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  20. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  21. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  22. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  23. // CHECK:STDOUT: %.2: type = const_type %i32 [template]
  24. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  25. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  26. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  27. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  28. // CHECK:STDOUT: %.5: type = ptr_type %i32 [template]
  29. // CHECK:STDOUT: %.6: type = const_type %.5 [template]
  30. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  31. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  36. // CHECK:STDOUT: .Int = %import_ref
  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: .A = %A.decl
  46. // CHECK:STDOUT: .B = %B.decl
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {
  50. // CHECK:STDOUT: %p.patt: %.4 = binding_pattern p
  51. // CHECK:STDOUT: %p.param_patt: %.4 = value_param_pattern %p.patt, runtime_param0
  52. // CHECK:STDOUT: %return.patt: %.4 = return_slot_pattern
  53. // CHECK:STDOUT: %return.param_patt: %.4 = out_param_pattern %return.patt, runtime_param1
  54. // CHECK:STDOUT: } {
  55. // CHECK:STDOUT: %.loc11_15: Core.IntLiteral = int_value 32 [template = constants.%.1]
  56. // CHECK:STDOUT: %int.make_type_signed.loc11_15: init type = call constants.%Int(%.loc11_15) [template = constants.%i32]
  57. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %int.make_type_signed.loc11_15 [template = constants.%i32]
  58. // CHECK:STDOUT: %.loc11_9.2: type = converted %int.make_type_signed.loc11_15, %.loc11_9.1 [template = constants.%i32]
  59. // CHECK:STDOUT: %.loc11_9.3: type = const_type %i32 [template = constants.%.2]
  60. // CHECK:STDOUT: %.loc11_18: type = ptr_type %.2 [template = constants.%.3]
  61. // CHECK:STDOUT: %.loc11_19: type = ptr_type %.3 [template = constants.%.4]
  62. // CHECK:STDOUT: %.loc11_31: Core.IntLiteral = int_value 32 [template = constants.%.1]
  63. // CHECK:STDOUT: %int.make_type_signed.loc11_31: init type = call constants.%Int(%.loc11_31) [template = constants.%i32]
  64. // CHECK:STDOUT: %.loc11_25.1: type = value_of_initializer %int.make_type_signed.loc11_31 [template = constants.%i32]
  65. // CHECK:STDOUT: %.loc11_25.2: type = converted %int.make_type_signed.loc11_31, %.loc11_25.1 [template = constants.%i32]
  66. // CHECK:STDOUT: %.loc11_25.3: type = const_type %i32 [template = constants.%.2]
  67. // CHECK:STDOUT: %.loc11_34: type = ptr_type %.2 [template = constants.%.3]
  68. // CHECK:STDOUT: %.loc11_35: type = ptr_type %.3 [template = constants.%.4]
  69. // CHECK:STDOUT: %p.param: %.4 = value_param runtime_param0
  70. // CHECK:STDOUT: %p: %.4 = bind_name p, %p.param
  71. // CHECK:STDOUT: %return.param: ref %.4 = out_param runtime_param1
  72. // CHECK:STDOUT: %return: ref %.4 = return_slot %return.param
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  75. // CHECK:STDOUT: %p.patt: %.6 = binding_pattern p
  76. // CHECK:STDOUT: %p.param_patt: %.6 = value_param_pattern %p.patt, runtime_param0
  77. // CHECK:STDOUT: %return.patt: %.6 = return_slot_pattern
  78. // CHECK:STDOUT: %return.param_patt: %.6 = out_param_pattern %return.patt, runtime_param1
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %.loc15_16: Core.IntLiteral = int_value 32 [template = constants.%.1]
  81. // CHECK:STDOUT: %int.make_type_signed.loc15_16: init type = call constants.%Int(%.loc15_16) [template = constants.%i32]
  82. // CHECK:STDOUT: %.loc15_19.1: type = value_of_initializer %int.make_type_signed.loc15_16 [template = constants.%i32]
  83. // CHECK:STDOUT: %.loc15_19.2: type = converted %int.make_type_signed.loc15_16, %.loc15_19.1 [template = constants.%i32]
  84. // CHECK:STDOUT: %.loc15_19.3: type = ptr_type %i32 [template = constants.%.5]
  85. // CHECK:STDOUT: %.loc15_9: type = const_type %.5 [template = constants.%.6]
  86. // CHECK:STDOUT: %.loc15_33: Core.IntLiteral = int_value 32 [template = constants.%.1]
  87. // CHECK:STDOUT: %int.make_type_signed.loc15_33: init type = call constants.%Int(%.loc15_33) [template = constants.%i32]
  88. // CHECK:STDOUT: %.loc15_36.1: type = value_of_initializer %int.make_type_signed.loc15_33 [template = constants.%i32]
  89. // CHECK:STDOUT: %.loc15_36.2: type = converted %int.make_type_signed.loc15_33, %.loc15_36.1 [template = constants.%i32]
  90. // CHECK:STDOUT: %.loc15_36.3: type = ptr_type %i32 [template = constants.%.5]
  91. // CHECK:STDOUT: %.loc15_26: type = const_type %.5 [template = constants.%.6]
  92. // CHECK:STDOUT: %p.param: %.6 = value_param runtime_param0
  93. // CHECK:STDOUT: %p: %.6 = bind_name p, %p.param
  94. // CHECK:STDOUT: %return.param: ref %.6 = out_param runtime_param1
  95. // CHECK:STDOUT: %return: ref %.6 = return_slot %return.param
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @A(%p.param_patt: %.4) -> %.4 {
  100. // CHECK:STDOUT: !entry:
  101. // CHECK:STDOUT: %p.ref: %.4 = name_ref p, %p
  102. // CHECK:STDOUT: return %p.ref
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: fn @B(%p.param_patt: %.6) -> %.6 {
  106. // CHECK:STDOUT: !entry:
  107. // CHECK:STDOUT: %p.ref: %.6 = name_ref p, %p
  108. // CHECK:STDOUT: return %p.ref
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: