collapse.carbon 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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+4]]: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. // CHECK:STDERR:
  15. fn F(p: const i32**) -> const (const i32)** {
  16. return p;
  17. }
  18. // CHECK:STDOUT: --- collapse.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  22. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  23. // CHECK:STDOUT: %const: type = const_type %i32 [template]
  24. // CHECK:STDOUT: %ptr.36b: type = ptr_type %const [template]
  25. // CHECK:STDOUT: %ptr.3bc: type = ptr_type %ptr.36b [template]
  26. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  27. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: imports {
  31. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  32. // CHECK:STDOUT: .Int = %Core.Int
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/...
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = imports.%Core
  41. // CHECK:STDOUT: .F = %F.decl
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Core.import = import Core
  44. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  45. // CHECK:STDOUT: %p.patt: %ptr.3bc = binding_pattern p
  46. // CHECK:STDOUT: %p.param_patt: %ptr.3bc = value_param_pattern %p.patt, runtime_param0
  47. // CHECK:STDOUT: %return.patt: %ptr.3bc = return_slot_pattern
  48. // CHECK:STDOUT: %return.param_patt: %ptr.3bc = out_param_pattern %return.patt, runtime_param1
  49. // CHECK:STDOUT: } {
  50. // CHECK:STDOUT: %int_32.loc16_38: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  51. // CHECK:STDOUT: %i32.loc16_38: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  52. // CHECK:STDOUT: %const.loc16_32: type = const_type %i32 [template = constants.%const]
  53. // CHECK:STDOUT: %const.loc16_25: type = const_type %const [template = constants.%const]
  54. // CHECK:STDOUT: %ptr.loc16_42: type = ptr_type %const [template = constants.%ptr.36b]
  55. // CHECK:STDOUT: %ptr.loc16_43: type = ptr_type %ptr.36b [template = constants.%ptr.3bc]
  56. // CHECK:STDOUT: %p.param: %ptr.3bc = value_param runtime_param0
  57. // CHECK:STDOUT: %.loc16: type = splice_block %ptr.loc16_19 [template = constants.%ptr.3bc] {
  58. // CHECK:STDOUT: %int_32.loc16_15: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  59. // CHECK:STDOUT: %i32.loc16_15: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  60. // CHECK:STDOUT: %const.loc16_9: type = const_type %i32 [template = constants.%const]
  61. // CHECK:STDOUT: %ptr.loc16_18: type = ptr_type %const [template = constants.%ptr.36b]
  62. // CHECK:STDOUT: %ptr.loc16_19: type = ptr_type %ptr.36b [template = constants.%ptr.3bc]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %p: %ptr.3bc = bind_name p, %p.param
  65. // CHECK:STDOUT: %return.param: ref %ptr.3bc = out_param runtime_param1
  66. // CHECK:STDOUT: %return: ref %ptr.3bc = return_slot %return.param
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: fn @F(%p.param_patt: %ptr.3bc) -> %ptr.3bc {
  71. // CHECK:STDOUT: !entry:
  72. // CHECK:STDOUT: %p.ref: %ptr.3bc = name_ref p, %p
  73. // CHECK:STDOUT: return %p.ref
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: