basic.carbon 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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: %Int32.type: type = fn_type @Int32 [template]
  20. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  21. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  22. // CHECK:STDOUT: %.2: type = const_type i32 [template]
  23. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  24. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  25. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  26. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  27. // CHECK:STDOUT: %.5: type = ptr_type i32 [template]
  28. // CHECK:STDOUT: %.6: type = const_type %.5 [template]
  29. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  30. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  35. // CHECK:STDOUT: .Int32 = %import_ref
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/operators
  38. // CHECK:STDOUT: import Core//prelude/types
  39. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  40. // CHECK:STDOUT: import Core//prelude/operators/as
  41. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  42. // CHECK:STDOUT: import Core//prelude/operators/comparison
  43. // CHECK:STDOUT: import Core//prelude/types/bool
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = imports.%Core
  51. // CHECK:STDOUT: .A = %A.decl
  52. // CHECK:STDOUT: .B = %B.decl
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core.import = import Core
  55. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {
  56. // CHECK:STDOUT: %p.patt: %.4 = binding_pattern p
  57. // CHECK:STDOUT: } {
  58. // CHECK:STDOUT: %int.make_type_32.loc11_15: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %int.make_type_32.loc11_15 [template = i32]
  60. // CHECK:STDOUT: %.loc11_9.2: type = converted %int.make_type_32.loc11_15, %.loc11_9.1 [template = i32]
  61. // CHECK:STDOUT: %.loc11_9.3: type = const_type i32 [template = constants.%.2]
  62. // CHECK:STDOUT: %.loc11_18: type = ptr_type %.2 [template = constants.%.3]
  63. // CHECK:STDOUT: %.loc11_19: type = ptr_type %.3 [template = constants.%.4]
  64. // CHECK:STDOUT: %p.param: %.4 = param p, runtime_param0
  65. // CHECK:STDOUT: %p: %.4 = bind_name p, %p.param
  66. // CHECK:STDOUT: %int.make_type_32.loc11_31: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc11_25.1: type = value_of_initializer %int.make_type_32.loc11_31 [template = i32]
  68. // CHECK:STDOUT: %.loc11_25.2: type = converted %int.make_type_32.loc11_31, %.loc11_25.1 [template = i32]
  69. // CHECK:STDOUT: %.loc11_25.3: type = const_type i32 [template = constants.%.2]
  70. // CHECK:STDOUT: %.loc11_34: type = ptr_type %.2 [template = constants.%.3]
  71. // CHECK:STDOUT: %.loc11_35: type = ptr_type %.3 [template = constants.%.4]
  72. // CHECK:STDOUT: %return: ref %.4 = var <return slot>
  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: } {
  77. // CHECK:STDOUT: %int.make_type_32.loc15_16: init type = call constants.%Int32() [template = i32]
  78. // CHECK:STDOUT: %.loc15_19.1: type = value_of_initializer %int.make_type_32.loc15_16 [template = i32]
  79. // CHECK:STDOUT: %.loc15_19.2: type = converted %int.make_type_32.loc15_16, %.loc15_19.1 [template = i32]
  80. // CHECK:STDOUT: %.loc15_19.3: type = ptr_type i32 [template = constants.%.5]
  81. // CHECK:STDOUT: %.loc15_9: type = const_type %.5 [template = constants.%.6]
  82. // CHECK:STDOUT: %p.param: %.6 = param p, runtime_param0
  83. // CHECK:STDOUT: %p: %.6 = bind_name p, %p.param
  84. // CHECK:STDOUT: %int.make_type_32.loc15_33: init type = call constants.%Int32() [template = i32]
  85. // CHECK:STDOUT: %.loc15_36.1: type = value_of_initializer %int.make_type_32.loc15_33 [template = i32]
  86. // CHECK:STDOUT: %.loc15_36.2: type = converted %int.make_type_32.loc15_33, %.loc15_36.1 [template = i32]
  87. // CHECK:STDOUT: %.loc15_36.3: type = ptr_type i32 [template = constants.%.5]
  88. // CHECK:STDOUT: %.loc15_26: type = const_type %.5 [template = constants.%.6]
  89. // CHECK:STDOUT: %return: ref %.6 = var <return slot>
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn @A(%p: %.4) -> %.4 {
  96. // CHECK:STDOUT: !entry:
  97. // CHECK:STDOUT: %p.ref: %.4 = name_ref p, %p
  98. // CHECK:STDOUT: return %p.ref
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: fn @B(%p: %.6) -> %.6 {
  102. // CHECK:STDOUT: !entry:
  103. // CHECK:STDOUT: %p.ref: %.6 = name_ref p, %p
  104. // CHECK:STDOUT: return %p.ref
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: