decayed_param.carbon 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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/int.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/function/decayed_param.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/decayed_param.carbon
  12. // --- params.h
  13. void TakesArray(int arr[42]);
  14. void TakesFunction(int f(int));
  15. int Function(int);
  16. // --- fail_todo_call_params.carbon
  17. library "[[@TEST_NAME]]";
  18. import Cpp library "params.h";
  19. fn G(n: i32) -> i32;
  20. fn F() {
  21. //@dump-sem-ir-begin
  22. var n: array(i32, 42);
  23. // CHECK:STDERR: fail_todo_call_params.carbon:[[@LINE+4]]:3: error: semantics TODO: `Unsupported: parameter type: int *` [SemanticsTodo]
  24. // CHECK:STDERR: Cpp.TakesArray(&n[0]);
  25. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  26. // CHECK:STDERR:
  27. Cpp.TakesArray(&n[0]);
  28. // CHECK:STDERR: fail_todo_call_params.carbon:[[@LINE+4]]:18: error: member name `nullptr` not found in `Cpp` [MemberNameNotFoundInInstScope]
  29. // CHECK:STDERR: Cpp.TakesArray(Cpp.nullptr);
  30. // CHECK:STDERR: ^~~~~~~~~~~
  31. // CHECK:STDERR:
  32. Cpp.TakesArray(Cpp.nullptr);
  33. // CHECK:STDERR: fail_todo_call_params.carbon:[[@LINE+4]]:21: error: call argument of type `<type of G>` is not supported [CppCallArgTypeNotSupported]
  34. // CHECK:STDERR: Cpp.TakesFunction(G);
  35. // CHECK:STDERR: ^
  36. // CHECK:STDERR:
  37. Cpp.TakesFunction(G);
  38. // CHECK:STDERR: fail_todo_call_params.carbon:[[@LINE+4]]:21: error: call argument of type `<type of Cpp.Function>` is not supported [CppCallArgTypeNotSupported]
  39. // CHECK:STDERR: Cpp.TakesFunction(Cpp.Function);
  40. // CHECK:STDERR: ^~~~~~~~~~~~
  41. // CHECK:STDERR:
  42. Cpp.TakesFunction(Cpp.Function);
  43. // CHECK:STDERR: fail_todo_call_params.carbon:[[@LINE+8]]:26: error: no matching function for call to 'TakesFunction' [CppInteropParseError]
  44. // CHECK:STDERR: 43 | Cpp.TakesFunction(&n[0]);
  45. // CHECK:STDERR: | ^
  46. // CHECK:STDERR: fail_todo_call_params.carbon:[[@LINE-34]]:10: in file included here [InCppInclude]
  47. // CHECK:STDERR: ./params.h:3:6: note: candidate function not viable: no known conversion from 'int * _Nonnull' to 'int (*)(int)' for 1st argument [CppInteropParseNote]
  48. // CHECK:STDERR: 3 | void TakesFunction(int f(int));
  49. // CHECK:STDERR: | ^ ~~~~~~~~~~
  50. // CHECK:STDERR:
  51. Cpp.TakesFunction(&n[0]);
  52. // CHECK:STDERR: fail_todo_call_params.carbon:[[@LINE+4]]:21: error: member name `nullptr` not found in `Cpp` [MemberNameNotFoundInInstScope]
  53. // CHECK:STDERR: Cpp.TakesFunction(Cpp.nullptr);
  54. // CHECK:STDERR: ^~~~~~~~~~~
  55. // CHECK:STDERR:
  56. Cpp.TakesFunction(Cpp.nullptr);
  57. //@dump-sem-ir-end
  58. }
  59. // CHECK:STDOUT: --- fail_todo_call_params.carbon
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: constants {
  62. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  63. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  64. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  65. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  66. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  67. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete]
  68. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32 [concrete]
  69. // CHECK:STDOUT: %ptr.830: type = ptr_type %array_type [concrete]
  70. // CHECK:STDOUT: %pattern_type.b6e: type = pattern_type %array_type [concrete]
  71. // CHECK:STDOUT: %.cdf: type = cpp_overload_set_type @Core.IntLiteral.as.ImplicitAs.impl.Convert [concrete]
  72. // CHECK:STDOUT: %empty_struct.5c5: %.cdf = struct_value () [concrete]
  73. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  74. // CHECK:STDOUT: %ImplicitAs.type.d14: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  75. // CHECK:STDOUT: %ImplicitAs.Convert.type.1b6: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
  76. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  77. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.340: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  78. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.1c0: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.340 = struct_value () [symbolic]
  79. // CHECK:STDOUT: %ImplicitAs.impl_witness.204: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.9e9, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  80. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.584: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  81. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.584 = struct_value () [concrete]
  82. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.d14 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.204) [concrete]
  83. // CHECK:STDOUT: %.1df: type = fn_type_with_self_type %ImplicitAs.Convert.type.1b6, %ImplicitAs.facet [concrete]
  84. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %int_0.5c6, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0 [concrete]
  85. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  86. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  87. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  88. // CHECK:STDOUT: %ptr.235: type = ptr_type %i32 [concrete]
  89. // CHECK:STDOUT: %.319: type = cpp_overload_set_type @Int.as.ImplicitAs.impl.Convert [concrete]
  90. // CHECK:STDOUT: %empty_struct.45a: %.319 = struct_value () [concrete]
  91. // CHECK:STDOUT: %.001: type = cpp_overload_set_type @Destroy.Op [concrete]
  92. // CHECK:STDOUT: %empty_struct.89b: %.001 = struct_value () [concrete]
  93. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  94. // CHECK:STDOUT: %facet_value: %type_where = facet_value %array_type, () [concrete]
  95. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.b6e: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value) [concrete]
  96. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.91f: %AggregateT.as_type.as.Destroy.impl.Op.type.b6e = struct_value () [concrete]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: imports {
  100. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  101. // CHECK:STDOUT: .TakesArray = %.782
  102. // CHECK:STDOUT: .nullptr = <poisoned>
  103. // CHECK:STDOUT: .TakesFunction = %.a02
  104. // CHECK:STDOUT: .Function = %.5ec
  105. // CHECK:STDOUT: import Cpp//...
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: %.782: %.cdf = cpp_overload_set_value @Core.IntLiteral.as.ImplicitAs.impl.Convert [concrete = constants.%empty_struct.5c5]
  108. // CHECK:STDOUT: %Core.import_ref.ee7: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.340) = import_ref Core//prelude/parts/int, loc23_39, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.1c0)]
  109. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.9e9 = impl_witness_table (%Core.import_ref.ee7), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  110. // CHECK:STDOUT: %.a02: %.319 = cpp_overload_set_value @Int.as.ImplicitAs.impl.Convert [concrete = constants.%empty_struct.45a]
  111. // CHECK:STDOUT: %.5ec: %.001 = cpp_overload_set_value @Destroy.Op [concrete = constants.%empty_struct.89b]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: fn @F() {
  115. // CHECK:STDOUT: !entry:
  116. // CHECK:STDOUT: name_binding_decl {
  117. // CHECK:STDOUT: %n.patt: %pattern_type.b6e = binding_pattern n [concrete]
  118. // CHECK:STDOUT: %n.var_patt: %pattern_type.b6e = var_pattern %n.patt [concrete]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %n.var: ref %array_type = var %n.var_patt
  121. // CHECK:STDOUT: %.loc10_23: type = splice_block %array_type [concrete = constants.%array_type] {
  122. // CHECK:STDOUT: %int_32.loc10: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  123. // CHECK:STDOUT: %i32.loc10: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  124. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete = constants.%int_42]
  125. // CHECK:STDOUT: %array_type: type = array_type %int_42, %i32.loc10 [concrete = constants.%array_type]
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %n: ref %array_type = bind_name n, %n.var
  128. // CHECK:STDOUT: %Cpp.ref.loc15: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  129. // CHECK:STDOUT: %TakesArray.ref.loc15: %.cdf = name_ref TakesArray, imports.%.782 [concrete = constants.%empty_struct.5c5]
  130. // CHECK:STDOUT: %n.ref.loc15: ref %array_type = name_ref n, %n
  131. // CHECK:STDOUT: %int_0.loc15: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  132. // CHECK:STDOUT: %int_32.loc15: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  133. // CHECK:STDOUT: %i32.loc15: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  134. // CHECK:STDOUT: %impl.elem0.loc15: %.1df = impl_witness_access constants.%ImplicitAs.impl_witness.204, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0]
  135. // CHECK:STDOUT: %bound_method.loc15_21.1: <bound method> = bound_method %int_0.loc15, %impl.elem0.loc15 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  136. // CHECK:STDOUT: %specific_fn.loc15: <specific function> = specific_function %impl.elem0.loc15, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  137. // CHECK:STDOUT: %bound_method.loc15_21.2: <bound method> = bound_method %int_0.loc15, %specific_fn.loc15 [concrete = constants.%bound_method]
  138. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc15: init %i32 = call %bound_method.loc15_21.2(%int_0.loc15) [concrete = constants.%int_0.6a9]
  139. // CHECK:STDOUT: %.loc15_21.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc15 [concrete = constants.%int_0.6a9]
  140. // CHECK:STDOUT: %.loc15_21.2: %i32 = converted %int_0.loc15, %.loc15_21.1 [concrete = constants.%int_0.6a9]
  141. // CHECK:STDOUT: %.loc15_22: ref %i32 = array_index %n.ref.loc15, %.loc15_21.2
  142. // CHECK:STDOUT: %addr.loc15: %ptr.235 = addr_of %.loc15_22
  143. // CHECK:STDOUT: %Cpp.ref.loc21_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  144. // CHECK:STDOUT: %TakesArray.ref.loc21: %.cdf = name_ref TakesArray, imports.%.782 [concrete = constants.%empty_struct.5c5]
  145. // CHECK:STDOUT: %Cpp.ref.loc21_18: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  146. // CHECK:STDOUT: %nullptr.ref.loc21: <error> = name_ref nullptr, <error> [concrete = <error>]
  147. // CHECK:STDOUT: %Cpp.ref.loc27: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  148. // CHECK:STDOUT: %TakesFunction.ref.loc27: %.319 = name_ref TakesFunction, imports.%.a02 [concrete = constants.%empty_struct.45a]
  149. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
  150. // CHECK:STDOUT: %Cpp.ref.loc33_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  151. // CHECK:STDOUT: %TakesFunction.ref.loc33: %.319 = name_ref TakesFunction, imports.%.a02 [concrete = constants.%empty_struct.45a]
  152. // CHECK:STDOUT: %Cpp.ref.loc33_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  153. // CHECK:STDOUT: %Function.ref: %.001 = name_ref Function, imports.%.5ec [concrete = constants.%empty_struct.89b]
  154. // CHECK:STDOUT: %Cpp.ref.loc43: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  155. // CHECK:STDOUT: %TakesFunction.ref.loc43: %.319 = name_ref TakesFunction, imports.%.a02 [concrete = constants.%empty_struct.45a]
  156. // CHECK:STDOUT: %n.ref.loc43: ref %array_type = name_ref n, %n
  157. // CHECK:STDOUT: %int_0.loc43: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  158. // CHECK:STDOUT: %int_32.loc43: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  159. // CHECK:STDOUT: %i32.loc43: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  160. // CHECK:STDOUT: %impl.elem0.loc43: %.1df = impl_witness_access constants.%ImplicitAs.impl_witness.204, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0]
  161. // CHECK:STDOUT: %bound_method.loc43_24.1: <bound method> = bound_method %int_0.loc43, %impl.elem0.loc43 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  162. // CHECK:STDOUT: %specific_fn.loc43: <specific function> = specific_function %impl.elem0.loc43, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  163. // CHECK:STDOUT: %bound_method.loc43_24.2: <bound method> = bound_method %int_0.loc43, %specific_fn.loc43 [concrete = constants.%bound_method]
  164. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc43: init %i32 = call %bound_method.loc43_24.2(%int_0.loc43) [concrete = constants.%int_0.6a9]
  165. // CHECK:STDOUT: %.loc43_24.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc43 [concrete = constants.%int_0.6a9]
  166. // CHECK:STDOUT: %.loc43_24.2: %i32 = converted %int_0.loc43, %.loc43_24.1 [concrete = constants.%int_0.6a9]
  167. // CHECK:STDOUT: %.loc43_25: ref %i32 = array_index %n.ref.loc43, %.loc43_24.2
  168. // CHECK:STDOUT: %addr.loc43: %ptr.235 = addr_of %.loc43_25
  169. // CHECK:STDOUT: %Cpp.ref.loc49_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  170. // CHECK:STDOUT: %TakesFunction.ref.loc49: %.319 = name_ref TakesFunction, imports.%.a02 [concrete = constants.%empty_struct.45a]
  171. // CHECK:STDOUT: %Cpp.ref.loc49_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  172. // CHECK:STDOUT: %nullptr.ref.loc49: <error> = name_ref nullptr, <error> [concrete = <error>]
  173. // CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%array_type, () [concrete = constants.%facet_value]
  174. // CHECK:STDOUT: %.loc10_3: %type_where = converted constants.%array_type, %facet_value [concrete = constants.%facet_value]
  175. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %n.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.91f
  176. // CHECK:STDOUT: <elided>
  177. // CHECK:STDOUT: %bound_method.loc10: <bound method> = bound_method %n.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn
  178. // CHECK:STDOUT: %addr.loc10: %ptr.830 = addr_of %n.var
  179. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc10(%addr.loc10)
  180. // CHECK:STDOUT: <elided>
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT: