anonymous.carbon 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/anonymous.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/anonymous.carbon
  12. // --- anon.h
  13. enum { a, b, c };
  14. void F(decltype(a)) {}
  15. class C {
  16. public:
  17. enum { d, e, f };
  18. void F(decltype(d)) {}
  19. };
  20. // --- copy_enum.carbon
  21. library "[[@TEST_NAME]]";
  22. import Cpp library "anon.h";
  23. //@dump-sem-ir-begin
  24. fn G() {
  25. Cpp.F(Cpp.b);
  26. Cpp.C.C().F(Cpp.C.e);
  27. }
  28. //@dump-sem-ir-end
  29. // CHECK:STDOUT: --- copy_enum.carbon
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: constants {
  32. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  33. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  34. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  35. // CHECK:STDOUT: %.557: type = cpp_overload_set_type @C.C [concrete]
  36. // CHECK:STDOUT: %.4a9: %.557 = cpp_overload_set_value @C.C [concrete]
  37. // CHECK:STDOUT: %.4f0: type = class_type @.1 [concrete]
  38. // CHECK:STDOUT: %int_1.81a: %.4f0 = int_value 1 [concrete]
  39. // CHECK:STDOUT: %ptr.793: type = ptr_type %.4f0 [concrete]
  40. // CHECK:STDOUT: %F__carbon_thunk.type.eda1ac.1: type = fn_type @F__carbon_thunk.1 [concrete]
  41. // CHECK:STDOUT: %F__carbon_thunk.0cd6a8.1: %F__carbon_thunk.type.eda1ac.1 = struct_value () [concrete]
  42. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  43. // CHECK:STDOUT: %.d40: type = cpp_overload_set_type @C__carbon_thunk [concrete]
  44. // CHECK:STDOUT: %.40b: %.d40 = cpp_overload_set_value @C__carbon_thunk [concrete]
  45. // CHECK:STDOUT: %ptr.d9e: type = ptr_type %C [concrete]
  46. // CHECK:STDOUT: %C__carbon_thunk.type: type = fn_type @C__carbon_thunk [concrete]
  47. // CHECK:STDOUT: %C__carbon_thunk: %C__carbon_thunk.type = struct_value () [concrete]
  48. // CHECK:STDOUT: %.9a3: type = cpp_overload_set_type @C.F [concrete]
  49. // CHECK:STDOUT: %.951: %.9a3 = cpp_overload_set_value @C.F [concrete]
  50. // CHECK:STDOUT: %.bb7: type = class_type @.2 [concrete]
  51. // CHECK:STDOUT: %int_1.1d6: %.bb7 = int_value 1 [concrete]
  52. // CHECK:STDOUT: %ptr.73d: type = ptr_type %.bb7 [concrete]
  53. // CHECK:STDOUT: %F__carbon_thunk.type.eda1ac.2: type = fn_type @F__carbon_thunk.2 [concrete]
  54. // CHECK:STDOUT: %F__carbon_thunk.0cd6a8.2: %F__carbon_thunk.type.eda1ac.2 = struct_value () [concrete]
  55. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  56. // CHECK:STDOUT: %facet_value.597: %type_where = facet_value %.bb7, () [concrete]
  57. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.type.237: type = fn_type @DestroyT.as_type.as.Destroy.impl.Op, @DestroyT.as_type.as.Destroy.impl(%facet_value.597) [concrete]
  58. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.c08: %DestroyT.as_type.as.Destroy.impl.Op.type.237 = struct_value () [concrete]
  59. // CHECK:STDOUT: %facet_value.b21: %type_where = facet_value %C, () [concrete]
  60. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.type.fc1: type = fn_type @DestroyT.as_type.as.Destroy.impl.Op, @DestroyT.as_type.as.Destroy.impl(%facet_value.b21) [concrete]
  61. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.6b9: %DestroyT.as_type.as.Destroy.impl.Op.type.fc1 = struct_value () [concrete]
  62. // CHECK:STDOUT: %facet_value.21d: %type_where = facet_value %.4f0, () [concrete]
  63. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.type.a40: type = fn_type @DestroyT.as_type.as.Destroy.impl.Op, @DestroyT.as_type.as.Destroy.impl(%facet_value.21d) [concrete]
  64. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.d51: %DestroyT.as_type.as.Destroy.impl.Op.type.a40 = struct_value () [concrete]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: imports {
  68. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  69. // CHECK:STDOUT: .F = %.4a9
  70. // CHECK:STDOUT: .b = %int_1.81a
  71. // CHECK:STDOUT: .C = %C.decl
  72. // CHECK:STDOUT: import Cpp//...
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %.4a9: %.557 = cpp_overload_set_value @C.C [concrete = constants.%.4a9]
  75. // CHECK:STDOUT: %int_1.81a: %.4f0 = int_value 1 [concrete = constants.%int_1.81a]
  76. // CHECK:STDOUT: %F__carbon_thunk.decl.e1b8ec.1: %F__carbon_thunk.type.eda1ac.1 = fn_decl @F__carbon_thunk.1 [concrete = constants.%F__carbon_thunk.0cd6a8.1] {
  77. // CHECK:STDOUT: <elided>
  78. // CHECK:STDOUT: } {
  79. // CHECK:STDOUT: <elided>
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  82. // CHECK:STDOUT: %.40b: %.d40 = cpp_overload_set_value @C__carbon_thunk [concrete = constants.%.40b]
  83. // CHECK:STDOUT: %C__carbon_thunk.decl: %C__carbon_thunk.type = fn_decl @C__carbon_thunk [concrete = constants.%C__carbon_thunk] {
  84. // CHECK:STDOUT: <elided>
  85. // CHECK:STDOUT: } {
  86. // CHECK:STDOUT: <elided>
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %.951: %.9a3 = cpp_overload_set_value @C.F [concrete = constants.%.951]
  89. // CHECK:STDOUT: %int_1.1d6: %.bb7 = int_value 1 [concrete = constants.%int_1.1d6]
  90. // CHECK:STDOUT: %F__carbon_thunk.decl.e1b8ec.2: %F__carbon_thunk.type.eda1ac.2 = fn_decl @F__carbon_thunk.2 [concrete = constants.%F__carbon_thunk.0cd6a8.2] {
  91. // CHECK:STDOUT: <elided>
  92. // CHECK:STDOUT: } {
  93. // CHECK:STDOUT: <elided>
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: file {
  98. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: fn @G() {
  102. // CHECK:STDOUT: !entry:
  103. // CHECK:STDOUT: %Cpp.ref.loc8_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  104. // CHECK:STDOUT: %F.ref.loc8: %.557 = name_ref F, imports.%.4a9 [concrete = constants.%.4a9]
  105. // CHECK:STDOUT: %Cpp.ref.loc8_9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  106. // CHECK:STDOUT: %b.ref: %.4f0 = name_ref b, imports.%int_1.81a [concrete = constants.%int_1.81a]
  107. // CHECK:STDOUT: %.loc8_12.1: ref %.4f0 = temporary_storage
  108. // CHECK:STDOUT: %.loc8_12.2: ref %.4f0 = temporary %.loc8_12.1, %b.ref
  109. // CHECK:STDOUT: %addr.loc8_14: %ptr.793 = addr_of %.loc8_12.2
  110. // CHECK:STDOUT: %F__carbon_thunk.call.loc8: init %empty_tuple.type = call imports.%F__carbon_thunk.decl.e1b8ec.1(%addr.loc8_14)
  111. // CHECK:STDOUT: %Cpp.ref.loc10_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  112. // CHECK:STDOUT: %C.ref.loc10_6: type = name_ref C, imports.%C.decl [concrete = constants.%C]
  113. // CHECK:STDOUT: %C.ref.loc10_8: %.d40 = name_ref C, imports.%.40b [concrete = constants.%.40b]
  114. // CHECK:STDOUT: %.loc10_11.1: ref %C = temporary_storage
  115. // CHECK:STDOUT: %addr.loc10_11.1: %ptr.d9e = addr_of %.loc10_11.1
  116. // CHECK:STDOUT: %C__carbon_thunk.call: init %empty_tuple.type = call imports.%C__carbon_thunk.decl(%addr.loc10_11.1)
  117. // CHECK:STDOUT: %.loc10_11.2: init %C = in_place_init %C__carbon_thunk.call, %.loc10_11.1
  118. // CHECK:STDOUT: %.loc10_11.3: ref %C = temporary %.loc10_11.1, %.loc10_11.2
  119. // CHECK:STDOUT: %F.ref.loc10: %.9a3 = name_ref F, imports.%.951 [concrete = constants.%.951]
  120. // CHECK:STDOUT: %bound_method.loc10_12: <bound method> = bound_method %.loc10_11.3, %F.ref.loc10
  121. // CHECK:STDOUT: %Cpp.ref.loc10_15: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  122. // CHECK:STDOUT: %C.ref.loc10_18: type = name_ref C, imports.%C.decl [concrete = constants.%C]
  123. // CHECK:STDOUT: %e.ref: %.bb7 = name_ref e, imports.%int_1.1d6 [concrete = constants.%int_1.1d6]
  124. // CHECK:STDOUT: %addr.loc10_11.2: %ptr.d9e = addr_of %.loc10_11.3
  125. // CHECK:STDOUT: %.loc10_20.1: ref %.bb7 = temporary_storage
  126. // CHECK:STDOUT: %.loc10_20.2: ref %.bb7 = temporary %.loc10_20.1, %e.ref
  127. // CHECK:STDOUT: %addr.loc10_22: %ptr.73d = addr_of %.loc10_20.2
  128. // CHECK:STDOUT: %F__carbon_thunk.call.loc10: init %empty_tuple.type = call imports.%F__carbon_thunk.decl.e1b8ec.2(%addr.loc10_11.2, %addr.loc10_22)
  129. // CHECK:STDOUT: %facet_value.loc10_20: %type_where = facet_value constants.%.bb7, () [concrete = constants.%facet_value.597]
  130. // CHECK:STDOUT: %.loc10_20.3: %type_where = converted constants.%.bb7, %facet_value.loc10_20 [concrete = constants.%facet_value.597]
  131. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.bound.loc10_20: <bound method> = bound_method %.loc10_20.2, constants.%DestroyT.as_type.as.Destroy.impl.Op.c08
  132. // CHECK:STDOUT: <elided>
  133. // CHECK:STDOUT: %bound_method.loc10_20: <bound method> = bound_method %.loc10_20.2, %DestroyT.as_type.as.Destroy.impl.Op.specific_fn.1
  134. // CHECK:STDOUT: %addr.loc10_20: %ptr.73d = addr_of %.loc10_20.2
  135. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.call.loc10_20: init %empty_tuple.type = call %bound_method.loc10_20(%addr.loc10_20)
  136. // CHECK:STDOUT: %facet_value.loc10_11: %type_where = facet_value constants.%C, () [concrete = constants.%facet_value.b21]
  137. // CHECK:STDOUT: %.loc10_11.4: %type_where = converted constants.%C, %facet_value.loc10_11 [concrete = constants.%facet_value.b21]
  138. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.bound.loc10_11: <bound method> = bound_method %.loc10_11.3, constants.%DestroyT.as_type.as.Destroy.impl.Op.6b9
  139. // CHECK:STDOUT: <elided>
  140. // CHECK:STDOUT: %bound_method.loc10_11: <bound method> = bound_method %.loc10_11.3, %DestroyT.as_type.as.Destroy.impl.Op.specific_fn.2
  141. // CHECK:STDOUT: %addr.loc10_11.3: %ptr.d9e = addr_of %.loc10_11.3
  142. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.call.loc10_11: init %empty_tuple.type = call %bound_method.loc10_11(%addr.loc10_11.3)
  143. // CHECK:STDOUT: %facet_value.loc8: %type_where = facet_value constants.%.4f0, () [concrete = constants.%facet_value.21d]
  144. // CHECK:STDOUT: %.loc8_12.3: %type_where = converted constants.%.4f0, %facet_value.loc8 [concrete = constants.%facet_value.21d]
  145. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.bound.loc8: <bound method> = bound_method %.loc8_12.2, constants.%DestroyT.as_type.as.Destroy.impl.Op.d51
  146. // CHECK:STDOUT: <elided>
  147. // CHECK:STDOUT: %bound_method.loc8: <bound method> = bound_method %.loc8_12.2, %DestroyT.as_type.as.Destroy.impl.Op.specific_fn.3
  148. // CHECK:STDOUT: %addr.loc8_12: %ptr.793 = addr_of %.loc8_12.2
  149. // CHECK:STDOUT: %DestroyT.as_type.as.Destroy.impl.Op.call.loc8: init %empty_tuple.type = call %bound_method.loc8(%addr.loc8_12)
  150. // CHECK:STDOUT: return
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: