collapse.carbon 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/collapse.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/const/collapse.carbon
  10. // OK, `const (const i32)` is the same type as `const i32`.
  11. // CHECK:STDERR: collapse.carbon:[[@LINE+3]]:25: warning: `const` applied repeatedly to the same type has no additional effect [RepeatedConst]
  12. // CHECK:STDERR: fn F(p: const i32**) -> const (const i32)** {
  13. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  14. fn F(p: const i32**) -> const (const i32)** {
  15. return p;
  16. }
  17. // CHECK:STDOUT: --- collapse.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  21. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  22. // CHECK:STDOUT: %const: type = const_type %i32 [template]
  23. // CHECK:STDOUT: %ptr.719: type = ptr_type %const [template]
  24. // CHECK:STDOUT: %ptr.733: type = ptr_type %ptr.719 [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: .Int = %import_ref.187
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/...
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .Core = imports.%Core
  40. // CHECK:STDOUT: .F = %F.decl
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %Core.import = import Core
  43. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  44. // CHECK:STDOUT: %p.patt: %ptr.733 = binding_pattern p
  45. // CHECK:STDOUT: %p.param_patt: %ptr.733 = value_param_pattern %p.patt, runtime_param0
  46. // CHECK:STDOUT: %return.patt: %ptr.733 = return_slot_pattern
  47. // CHECK:STDOUT: %return.param_patt: %ptr.733 = out_param_pattern %return.patt, runtime_param1
  48. // CHECK:STDOUT: } {
  49. // CHECK:STDOUT: %int_32.loc15_38: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  50. // CHECK:STDOUT: %i32.loc15_38: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  51. // CHECK:STDOUT: %const.loc15_32: type = const_type %i32 [template = constants.%const]
  52. // CHECK:STDOUT: %const.loc15_25: type = const_type %const [template = constants.%const]
  53. // CHECK:STDOUT: %ptr.loc15_42: type = ptr_type %const [template = constants.%ptr.719]
  54. // CHECK:STDOUT: %ptr.loc15_43: type = ptr_type %ptr.719 [template = constants.%ptr.733]
  55. // CHECK:STDOUT: %p.param: %ptr.733 = value_param runtime_param0
  56. // CHECK:STDOUT: %.loc15: type = splice_block %ptr.loc15_19 [template = constants.%ptr.733] {
  57. // CHECK:STDOUT: %int_32.loc15_15: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  58. // CHECK:STDOUT: %i32.loc15_15: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  59. // CHECK:STDOUT: %const.loc15_9: type = const_type %i32 [template = constants.%const]
  60. // CHECK:STDOUT: %ptr.loc15_18: type = ptr_type %const [template = constants.%ptr.719]
  61. // CHECK:STDOUT: %ptr.loc15_19: type = ptr_type %ptr.719 [template = constants.%ptr.733]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %p: %ptr.733 = bind_name p, %p.param
  64. // CHECK:STDOUT: %return.param: ref %ptr.733 = out_param runtime_param1
  65. // CHECK:STDOUT: %return: ref %ptr.733 = return_slot %return.param
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @F(%p.param_patt: %ptr.733) -> %ptr.733 {
  70. // CHECK:STDOUT: !entry:
  71. // CHECK:STDOUT: %p.ref: %ptr.733 = name_ref p, %p
  72. // CHECK:STDOUT: return %p.ref
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: