qualified_param.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/qualified_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/qualified_param.carbon
  12. // --- qualifiers.h
  13. void TakesConstInt(const int);
  14. struct S {};
  15. void TakesConstS(const S);
  16. // --- call_qualifiers.carbon
  17. library "[[@TEST_NAME]]";
  18. import Cpp library "qualifiers.h";
  19. fn F() {
  20. //@dump-sem-ir-begin
  21. Cpp.TakesConstInt(42);
  22. var s: Cpp.S = {};
  23. Cpp.TakesConstS(s);
  24. //@dump-sem-ir-end
  25. }
  26. // CHECK:STDOUT: --- call_qualifiers.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  30. // CHECK:STDOUT: %TakesConstInt.cpp_overload_set.type: type = cpp_overload_set_type @TakesConstInt.cpp_overload_set [concrete]
  31. // CHECK:STDOUT: %TakesConstInt.cpp_overload_set.value: %TakesConstInt.cpp_overload_set.type = cpp_overload_set_value @TakesConstInt.cpp_overload_set [concrete]
  32. // CHECK:STDOUT: %int_42.20e: Core.IntLiteral = int_value 42 [concrete]
  33. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  34. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  35. // CHECK:STDOUT: %TakesConstInt.type: type = fn_type @TakesConstInt [concrete]
  36. // CHECK:STDOUT: %TakesConstInt: %TakesConstInt.type = struct_value () [concrete]
  37. // CHECK:STDOUT: %ImplicitAs.type.e8c: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  38. // CHECK:STDOUT: %To: Core.IntLiteral = symbolic_binding To, 0 [symbolic]
  39. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.4e6: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  40. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.3c2: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.4e6 = struct_value () [symbolic]
  41. // CHECK:STDOUT: %ImplicitAs.impl_witness.6bc: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.74f, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  42. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.e0d: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  43. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.e0d = struct_value () [concrete]
  44. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.e8c = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.6bc) [concrete]
  45. // CHECK:STDOUT: %ImplicitAs.WithSelf.Convert.type.b37: type = fn_type @ImplicitAs.WithSelf.Convert, @ImplicitAs.WithSelf(%i32, %ImplicitAs.facet) [concrete]
  46. // CHECK:STDOUT: %.545: type = fn_type_with_self_type %ImplicitAs.WithSelf.Convert.type.b37, %ImplicitAs.facet [concrete]
  47. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %int_42.20e, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5 [concrete]
  48. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  49. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_42.20e, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  50. // CHECK:STDOUT: %int_42.c68: %i32 = int_value 42 [concrete]
  51. // CHECK:STDOUT: %S: type = class_type @S [concrete]
  52. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  53. // CHECK:STDOUT: %pattern_type.7da: type = pattern_type %S [concrete]
  54. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  55. // CHECK:STDOUT: %S.val: %S = struct_value () [concrete]
  56. // CHECK:STDOUT: %TakesConstS.cpp_overload_set.type: type = cpp_overload_set_type @TakesConstS.cpp_overload_set [concrete]
  57. // CHECK:STDOUT: %TakesConstS.cpp_overload_set.value: %TakesConstS.cpp_overload_set.type = cpp_overload_set_value @TakesConstS.cpp_overload_set [concrete]
  58. // CHECK:STDOUT: %const: type = const_type %S [concrete]
  59. // CHECK:STDOUT: %ptr.ff5: type = ptr_type %const [concrete]
  60. // CHECK:STDOUT: %TakesConstS__carbon_thunk.type: type = fn_type @TakesConstS__carbon_thunk [concrete]
  61. // CHECK:STDOUT: %TakesConstS__carbon_thunk: %TakesConstS__carbon_thunk.type = struct_value () [concrete]
  62. // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
  63. // CHECK:STDOUT: %S.cpp_destructor.type: type = fn_type @S.cpp_destructor [concrete]
  64. // CHECK:STDOUT: %S.cpp_destructor: %S.cpp_destructor.type = 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: .TakesConstInt = %TakesConstInt.cpp_overload_set.value
  70. // CHECK:STDOUT: .S = %S.decl
  71. // CHECK:STDOUT: .TakesConstS = %TakesConstS.cpp_overload_set.value
  72. // CHECK:STDOUT: import Cpp//...
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %TakesConstInt.cpp_overload_set.value: %TakesConstInt.cpp_overload_set.type = cpp_overload_set_value @TakesConstInt.cpp_overload_set [concrete = constants.%TakesConstInt.cpp_overload_set.value]
  75. // CHECK:STDOUT: %TakesConstInt.decl: %TakesConstInt.type = fn_decl @TakesConstInt [concrete = constants.%TakesConstInt] {
  76. // CHECK:STDOUT: <elided>
  77. // CHECK:STDOUT: } {
  78. // CHECK:STDOUT: <elided>
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %Core.import_ref.42d: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.4e6) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.3c2)]
  81. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.74f = impl_witness_table (%Core.import_ref.42d), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  82. // CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
  83. // CHECK:STDOUT: %TakesConstS.cpp_overload_set.value: %TakesConstS.cpp_overload_set.type = cpp_overload_set_value @TakesConstS.cpp_overload_set [concrete = constants.%TakesConstS.cpp_overload_set.value]
  84. // CHECK:STDOUT: %TakesConstS__carbon_thunk.decl: %TakesConstS__carbon_thunk.type = fn_decl @TakesConstS__carbon_thunk [concrete = constants.%TakesConstS__carbon_thunk] {
  85. // CHECK:STDOUT: <elided>
  86. // CHECK:STDOUT: } {
  87. // CHECK:STDOUT: <elided>
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @F() {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  94. // CHECK:STDOUT: %TakesConstInt.ref: %TakesConstInt.cpp_overload_set.type = name_ref TakesConstInt, imports.%TakesConstInt.cpp_overload_set.value [concrete = constants.%TakesConstInt.cpp_overload_set.value]
  95. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete = constants.%int_42.20e]
  96. // CHECK:STDOUT: %impl.elem0: %.545 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
  97. // CHECK:STDOUT: %bound_method.loc8_21.1: <bound method> = bound_method %int_42, %impl.elem0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  98. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  99. // CHECK:STDOUT: %bound_method.loc8_21.2: <bound method> = bound_method %int_42, %specific_fn [concrete = constants.%bound_method]
  100. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %i32 = call %bound_method.loc8_21.2(%int_42) [concrete = constants.%int_42.c68]
  101. // CHECK:STDOUT: %.loc8_21.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_42.c68]
  102. // CHECK:STDOUT: %.loc8_21.2: %i32 = converted %int_42, %.loc8_21.1 [concrete = constants.%int_42.c68]
  103. // CHECK:STDOUT: %TakesConstInt.call: init %empty_tuple.type = call imports.%TakesConstInt.decl(%.loc8_21.2)
  104. // CHECK:STDOUT: name_binding_decl {
  105. // CHECK:STDOUT: %s.patt: %pattern_type.7da = ref_binding_pattern s [concrete]
  106. // CHECK:STDOUT: %s.var_patt: %pattern_type.7da = var_pattern %s.patt [concrete]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %s.var: ref %S = var %s.var_patt
  109. // CHECK:STDOUT: %.loc10_19.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  110. // CHECK:STDOUT: %.loc10_19.2: init %S to %s.var = class_init () [concrete = constants.%S.val]
  111. // CHECK:STDOUT: %.loc10_3: init %S = converted %.loc10_19.1, %.loc10_19.2 [concrete = constants.%S.val]
  112. // CHECK:STDOUT: assign %s.var, %.loc10_3
  113. // CHECK:STDOUT: %.loc10_13: type = splice_block %S.ref [concrete = constants.%S] {
  114. // CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  115. // CHECK:STDOUT: %S.ref: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %s: ref %S = ref_binding s, %s.var
  118. // CHECK:STDOUT: %Cpp.ref.loc11: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  119. // CHECK:STDOUT: %TakesConstS.ref: %TakesConstS.cpp_overload_set.type = name_ref TakesConstS, imports.%TakesConstS.cpp_overload_set.value [concrete = constants.%TakesConstS.cpp_overload_set.value]
  120. // CHECK:STDOUT: %s.ref: ref %S = name_ref s, %s
  121. // CHECK:STDOUT: %.loc11_19.1: %S = acquire_value %s.ref
  122. // CHECK:STDOUT: %.loc11_19.2: ref %S = value_as_ref %.loc11_19.1
  123. // CHECK:STDOUT: %addr: %ptr.5c7 = addr_of %.loc11_19.2
  124. // CHECK:STDOUT: %.loc11_20.1: %ptr.ff5 = as_compatible %addr
  125. // CHECK:STDOUT: %.loc11_20.2: %ptr.ff5 = converted %addr, %.loc11_20.1
  126. // CHECK:STDOUT: %TakesConstS__carbon_thunk.call: init %empty_tuple.type = call imports.%TakesConstS__carbon_thunk.decl(%.loc11_20.2)
  127. // CHECK:STDOUT: %S.cpp_destructor.bound: <bound method> = bound_method %s.var, constants.%S.cpp_destructor
  128. // CHECK:STDOUT: %S.cpp_destructor.call: init %empty_tuple.type = call %S.cpp_destructor.bound(%s.var)
  129. // CHECK:STDOUT: <elided>
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: