collapse.carbon 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.
  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: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [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: %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: file {
  31. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  32. // CHECK:STDOUT: .Core = %Core
  33. // CHECK:STDOUT: .F = %F.decl
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  36. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  37. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  38. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  39. // CHECK:STDOUT: %int.make_type_32.loc15_15: init type = call constants.%Int32() [template = i32]
  40. // CHECK:STDOUT: %.loc15_9.1: type = value_of_initializer %int.make_type_32.loc15_15 [template = i32]
  41. // CHECK:STDOUT: %.loc15_9.2: type = converted %int.make_type_32.loc15_15, %.loc15_9.1 [template = i32]
  42. // CHECK:STDOUT: %.loc15_9.3: type = const_type i32 [template = constants.%.2]
  43. // CHECK:STDOUT: %.loc15_18: type = ptr_type %.2 [template = constants.%.3]
  44. // CHECK:STDOUT: %.loc15_19: type = ptr_type %.3 [template = constants.%.4]
  45. // CHECK:STDOUT: %p.loc15_6.1: %.4 = param p
  46. // CHECK:STDOUT: @F.%p: %.4 = bind_name p, %p.loc15_6.1
  47. // CHECK:STDOUT: %int.make_type_32.loc15_38: init type = call constants.%Int32() [template = i32]
  48. // CHECK:STDOUT: %.loc15_32.1: type = value_of_initializer %int.make_type_32.loc15_38 [template = i32]
  49. // CHECK:STDOUT: %.loc15_32.2: type = converted %int.make_type_32.loc15_38, %.loc15_32.1 [template = i32]
  50. // CHECK:STDOUT: %.loc15_32.3: type = const_type i32 [template = constants.%.2]
  51. // CHECK:STDOUT: %.loc15_25: type = const_type %.2 [template = constants.%.2]
  52. // CHECK:STDOUT: %.loc15_42: type = ptr_type %.2 [template = constants.%.3]
  53. // CHECK:STDOUT: %.loc15_43: type = ptr_type %.3 [template = constants.%.4]
  54. // CHECK:STDOUT: @F.%return: ref %.4 = var <return slot>
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @F(%p: %.4) -> %.4 {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: %p.ref: %.4 = name_ref p, %p
  63. // CHECK:STDOUT: return %p.ref
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: