copy.carbon 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/enum/copy.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/enum/copy.carbon
  12. // --- enum.h
  13. enum Enum : short { a, b, c };
  14. // --- copy_enum.carbon
  15. library "[[@TEST_NAME]]";
  16. import Cpp library "enum.h";
  17. //@dump-sem-ir-begin
  18. fn F() {
  19. var a: Cpp.Enum = Cpp.Enum.a;
  20. a = Cpp.Enum.b;
  21. }
  22. //@dump-sem-ir-end
  23. // CHECK:STDOUT: --- copy_enum.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  27. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  28. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %Enum: type = class_type @Enum [concrete]
  30. // CHECK:STDOUT: %pattern_type.ebf: type = pattern_type %Enum [concrete]
  31. // CHECK:STDOUT: %int_0: %Enum = int_value 0 [concrete]
  32. // CHECK:STDOUT: %int_1: %Enum = int_value 1 [concrete]
  33. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  34. // CHECK:STDOUT: %facet_value: %type_where = facet_value %Enum, () [concrete]
  35. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.a44: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
  36. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.e1a: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.a44 = struct_value () [concrete]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: imports {
  40. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  41. // CHECK:STDOUT: .Enum = %Enum.decl
  42. // CHECK:STDOUT: import Cpp//...
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %Enum.decl: type = class_decl @Enum [concrete = constants.%Enum] {} {}
  45. // CHECK:STDOUT: %int_0: %Enum = int_value 0 [concrete = constants.%int_0]
  46. // CHECK:STDOUT: %int_1: %Enum = int_value 1 [concrete = constants.%int_1]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: file {
  50. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: fn @F() {
  54. // CHECK:STDOUT: !entry:
  55. // CHECK:STDOUT: name_binding_decl {
  56. // CHECK:STDOUT: %a.patt: %pattern_type.ebf = ref_binding_pattern a [concrete]
  57. // CHECK:STDOUT: %a.var_patt: %pattern_type.ebf = var_pattern %a.patt [concrete]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %a.var: ref %Enum = var %a.var_patt
  60. // CHECK:STDOUT: %Cpp.ref.loc8_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  61. // CHECK:STDOUT: %Enum.ref.loc8_24: type = name_ref Enum, imports.%Enum.decl [concrete = constants.%Enum]
  62. // CHECK:STDOUT: %a.ref.loc8: %Enum = name_ref a, imports.%int_0 [concrete = constants.%int_0]
  63. // CHECK:STDOUT: assign %a.var, %a.ref.loc8
  64. // CHECK:STDOUT: %.loc8: type = splice_block %Enum.ref.loc8_13 [concrete = constants.%Enum] {
  65. // CHECK:STDOUT: %Cpp.ref.loc8_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  66. // CHECK:STDOUT: %Enum.ref.loc8_13: type = name_ref Enum, imports.%Enum.decl [concrete = constants.%Enum]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %a: ref %Enum = ref_binding a, %a.var
  69. // CHECK:STDOUT: %a.ref.loc10: ref %Enum = name_ref a, %a
  70. // CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  71. // CHECK:STDOUT: %Enum.ref.loc10: type = name_ref Enum, imports.%Enum.decl [concrete = constants.%Enum]
  72. // CHECK:STDOUT: %b.ref: %Enum = name_ref b, imports.%int_1 [concrete = constants.%int_1]
  73. // CHECK:STDOUT: assign %a.ref.loc10, %b.ref
  74. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %a.var, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.e1a
  75. // CHECK:STDOUT: <elided>
  76. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.var, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn
  77. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%a.var)
  78. // CHECK:STDOUT: return
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: