mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Interop support for initialization via std::initializer_list. (#6672)
Add a new builtin function `cpp.std.initializer_list.make` that takes an array and returns a `std::initializer_list`, initialized to refer to that array. When C++ initialization wants to perform a `std::initializer_list`-from-array construction, synthesize a declaration of a matching builtin function and use that to perform the initialization. Ideally we would specify this conversion as an impl of `ImplicitAs` in the prelude instead of hardcoding it in the interop layer, but unfortunately that's not currently possible, for various reasons -- we can't make the conversion form-generic, we can't deduce the array length from the initializer, and we can't deduce against the arguments of imported C++ class templates yet -- so for now synthesizing a builtin function on demand is the best we can do. Assisted-by: Gemini 3 Pro via Antigravity
This commit is contained in:
@@ -7,15 +7,20 @@
|
||||
#include "clang/Sema/Initialization.h"
|
||||
#include "clang/Sema/Overload.h"
|
||||
#include "clang/Sema/Sema.h"
|
||||
#include "toolchain/check/convert.h"
|
||||
#include "toolchain/check/core_identifier.h"
|
||||
#include "toolchain/check/cpp/import.h"
|
||||
#include "toolchain/check/cpp/location.h"
|
||||
#include "toolchain/check/cpp/overload_resolution.h"
|
||||
#include "toolchain/check/cpp/type_mapping.h"
|
||||
#include "toolchain/check/function.h"
|
||||
#include "toolchain/check/inst.h"
|
||||
#include "toolchain/check/type.h"
|
||||
#include "toolchain/check/type_completion.h"
|
||||
#include "toolchain/sem_ir/builtin_function_kind.h"
|
||||
#include "toolchain/sem_ir/cpp_initializer_list.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
#include "toolchain/sem_ir/inst.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
|
||||
namespace Carbon::Check {
|
||||
@@ -193,6 +198,72 @@ static auto GetClangOperatorKind(Context& context, SemIR::LocId loc_id,
|
||||
}
|
||||
}
|
||||
|
||||
// Creates and returns a function that can be used to construct a
|
||||
// std::initializer_list from an array.
|
||||
//
|
||||
// TODO: This should ideally be implemented in Carbon code rather than by
|
||||
// synthesizing a function.
|
||||
// TODO: We should cache and reuse the generated function.
|
||||
static auto MakeCppStdInitializerListMake(Context& context, SemIR::LocId loc_id,
|
||||
clang::QualType init_list_type,
|
||||
int32_t size) -> SemIR::InstId {
|
||||
// Extract the element type `T` from the `std::initializer_list<T>` type.
|
||||
clang::QualType element_type;
|
||||
bool is_std_initializer_list =
|
||||
context.clang_sema().isStdInitializerList(init_list_type, &element_type);
|
||||
CARBON_CHECK(is_std_initializer_list);
|
||||
auto element_type_inst_id =
|
||||
ImportCppType(context, loc_id, element_type).inst_id;
|
||||
if (element_type_inst_id == SemIR::ErrorInst::InstId) {
|
||||
return SemIR::ErrorInst::InstId;
|
||||
}
|
||||
|
||||
// Import the `std::initializer_list<T>` type and check we recognize its
|
||||
// layout.
|
||||
auto [init_list_type_inst_id, init_list_type_id] =
|
||||
ImportCppType(context, loc_id, init_list_type);
|
||||
if (init_list_type_id == SemIR::ErrorInst::TypeId) {
|
||||
return SemIR::ErrorInst::InstId;
|
||||
}
|
||||
auto layout =
|
||||
SemIR::GetStdInitializerListLayout(context.sem_ir(), init_list_type_id);
|
||||
if (layout.kind == SemIR::StdInitializerListLayout::None) {
|
||||
context.TODO(loc_id, "Unsupported layout for std::initializer_list");
|
||||
return SemIR::ErrorInst::InstId;
|
||||
}
|
||||
auto init_list_class_id = context.sem_ir()
|
||||
.types()
|
||||
.GetAs<SemIR::ClassType>(init_list_type_id)
|
||||
.class_id;
|
||||
auto& init_list_class = context.classes().Get(init_list_class_id);
|
||||
|
||||
// Build the array type `T[size]` that we use as the parameter type.
|
||||
// TODO: This will eventually be called from impl lookup, possibly while
|
||||
// forming a specific, so we should not be adding instructions here.
|
||||
auto bound_id = AddInst(
|
||||
context, SemIR::LocIdAndInst(
|
||||
loc_id, SemIR::IntValue{
|
||||
.type_id = GetSingletonType(
|
||||
context, SemIR::IntLiteralType::TypeInstId),
|
||||
.int_id = context.ints().Add(size)}));
|
||||
auto array_type_inst_id = AddTypeInst(
|
||||
context, SemIR::LocIdAndInst::UncheckedLoc(
|
||||
loc_id, SemIR::ArrayType{
|
||||
.type_id = SemIR::TypeType::TypeId,
|
||||
.bound_id = bound_id,
|
||||
.element_type_inst_id = element_type_inst_id}));
|
||||
auto array_type_id =
|
||||
context.types().GetTypeIdForTypeInstId(array_type_inst_id);
|
||||
|
||||
// Create a builtin function to perform the conversion from array type to
|
||||
// initializer list type. We name the synthesized function as if it were a
|
||||
// constructor of std::initializer_list.
|
||||
return MakeBuiltinFunction(
|
||||
context, loc_id, SemIR::BuiltinFunctionKind::CppStdInitializerListMake,
|
||||
init_list_class.scope_id, init_list_class.name_id,
|
||||
{.param_type_ids = {array_type_id}, .return_type_id = init_list_type_id});
|
||||
}
|
||||
|
||||
// Returns information about the Carbon signature to import when importing a C++
|
||||
// constructor or conversion operator.
|
||||
static auto GetConversionSignatureToImport(
|
||||
@@ -296,6 +367,7 @@ static auto LookupCppConversion(Context& context, SemIR::LocId loc_id,
|
||||
switch (step.Kind) {
|
||||
case clang::InitializationSequence::SK_UserConversion:
|
||||
case clang::InitializationSequence::SK_ConstructorInitialization:
|
||||
case clang::InitializationSequence::SK_StdInitializerListConstructorCall:
|
||||
case clang::InitializationSequence::
|
||||
SK_ConstructorInitializationFromList: {
|
||||
if (auto* ctor =
|
||||
@@ -331,6 +403,20 @@ static auto LookupCppConversion(Context& context, SemIR::LocId loc_id,
|
||||
return result_id;
|
||||
}
|
||||
|
||||
case clang::InitializationSequence::SK_StdInitializerList: {
|
||||
return MakeCppStdInitializerListMake(
|
||||
context, loc_id, step.Type,
|
||||
cast<clang::InitListExpr>(arg_expr)->getNumInits());
|
||||
}
|
||||
|
||||
case clang::InitializationSequence::SK_ListInitialization: {
|
||||
// Aggregate initialization is handled by the normal Carbon conversion
|
||||
// logic, so we ignore it here.
|
||||
// TODO: So far we only support aggregate initialization for arrays and
|
||||
// empty classes.
|
||||
continue;
|
||||
}
|
||||
|
||||
case clang::InitializationSequence::SK_ConversionSequence:
|
||||
case clang::InitializationSequence::SK_ConversionSequenceNoNarrowing: {
|
||||
// Implicit conversions are handled by the normal Carbon conversion
|
||||
@@ -497,6 +583,9 @@ auto IsCppOperatorMethodDecl(clang::Decl* decl) -> bool {
|
||||
|
||||
static auto GetAsCppFunctionDecl(Context& context, SemIR::InstId inst_id)
|
||||
-> clang::FunctionDecl* {
|
||||
if (inst_id == SemIR::InstId::None) {
|
||||
return nullptr;
|
||||
}
|
||||
auto function_type = context.types().TryGetAs<SemIR::FunctionType>(
|
||||
context.insts().Get(inst_id).type_id());
|
||||
if (!function_type) {
|
||||
|
||||
@@ -5,19 +5,19 @@
|
||||
#include "toolchain/check/custom_witness.h"
|
||||
|
||||
#include "toolchain/base/kind_switch.h"
|
||||
#include "toolchain/check/function.h"
|
||||
#include "toolchain/check/impl.h"
|
||||
#include "toolchain/check/import_ref.h"
|
||||
#include "toolchain/check/inst.h"
|
||||
#include "toolchain/check/name_lookup.h"
|
||||
#include "toolchain/check/pattern.h"
|
||||
#include "toolchain/check/pattern_match.h"
|
||||
#include "toolchain/check/type.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
|
||||
namespace Carbon::Check {
|
||||
|
||||
// Given a value whose type `IsFacetTypeOrError`, returns the corresponding
|
||||
// type.
|
||||
static auto GetFacetAsType(Context& context, SemIR::LocId loc_id,
|
||||
static auto GetFacetAsType(Context& context,
|
||||
SemIR::ConstantId facet_or_type_const_id)
|
||||
-> SemIR::TypeId {
|
||||
auto facet_or_type_id =
|
||||
@@ -27,10 +27,8 @@ static auto GetFacetAsType(Context& context, SemIR::LocId loc_id,
|
||||
|
||||
if (context.types().Is<SemIR::FacetType>(type_type_id)) {
|
||||
// It's a facet; access its type.
|
||||
facet_or_type_id = GetOrAddInst<SemIR::FacetAccessType>(
|
||||
context, loc_id,
|
||||
{.type_id = SemIR::TypeType::TypeId,
|
||||
.facet_value_inst_id = facet_or_type_id});
|
||||
facet_or_type_id = context.types().GetInstId(
|
||||
GetFacetAccessType(context, facet_or_type_id));
|
||||
}
|
||||
return context.types().GetTypeIdForTypeInstId(facet_or_type_id);
|
||||
}
|
||||
@@ -38,76 +36,15 @@ static auto GetFacetAsType(Context& context, SemIR::LocId loc_id,
|
||||
// Returns a manufactured no-op function with `self_const_id` as parameter.
|
||||
// TODO: This is somewhat temporary, but we may want to keep something similar
|
||||
// long-term where names are based on type structure (potentially also for
|
||||
// copy/move). It'll probably be good to look at refactoring with function
|
||||
// construction in thunk.cpp and cpp/import.cpp.
|
||||
// copy/move).
|
||||
static auto MakeNoOpFunction(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::ConstantId self_const_id,
|
||||
SemIR::SpecificId specific_id) -> SemIR::InstId {
|
||||
// Build the parameters, with `[ref self: Self]`
|
||||
context.scope_stack().PushForDeclName();
|
||||
context.inst_block_stack().Push();
|
||||
context.pattern_block_stack().Push();
|
||||
context.full_pattern_stack().PushFullPattern(
|
||||
FullPatternStack::Kind::ExplicitParamList);
|
||||
|
||||
BeginSubpattern(context);
|
||||
auto type_id = GetFacetAsType(context, loc_id, self_const_id);
|
||||
SemIR::ExprRegionId type_expr_region_id =
|
||||
EndSubpatternAsExpr(context, context.types().GetInstId(type_id));
|
||||
auto self_param_id = AddParamPattern(
|
||||
context, loc_id, SemIR::NameId::SelfValue, type_expr_region_id, type_id,
|
||||
/*is_ref=*/true);
|
||||
auto implicit_param_patterns_id = context.inst_blocks().Add({self_param_id});
|
||||
auto [call_param_patterns_id, call_params_id] =
|
||||
CalleePatternMatch(context, implicit_param_patterns_id,
|
||||
/*param_patterns_id=*/SemIR::InstBlockId::Empty,
|
||||
/*return_patterns_id=*/SemIR::InstBlockId::None);
|
||||
|
||||
context.full_pattern_stack().PopFullPattern();
|
||||
auto pattern_block_id = context.pattern_block_stack().Pop();
|
||||
auto decl_block_id = context.inst_block_stack().Pop();
|
||||
context.scope_stack().Pop();
|
||||
|
||||
// Add the function declaration.
|
||||
SemIR::FunctionDecl function_decl = {.type_id = SemIR::TypeId::None,
|
||||
.function_id = SemIR::FunctionId::None,
|
||||
.decl_block_id = decl_block_id};
|
||||
auto noop_id = AddPlaceholderInstInNoBlock(
|
||||
context, SemIR::LocIdAndInst::UncheckedLoc(loc_id, function_decl));
|
||||
|
||||
auto noop_name_id =
|
||||
SemIR::NameId::ForIdentifier(context.identifiers().Add("DestroyOp"));
|
||||
|
||||
// Build the function entity.
|
||||
auto noop_function = SemIR::Function{
|
||||
{
|
||||
.name_id = noop_name_id,
|
||||
.parent_scope_id = SemIR::NameScopeId::None,
|
||||
.generic_id = SemIR::GenericId::None,
|
||||
.first_param_node_id = Parse::NodeId::None,
|
||||
.last_param_node_id = Parse::NodeId::None,
|
||||
.pattern_block_id = pattern_block_id,
|
||||
.implicit_param_patterns_id = implicit_param_patterns_id,
|
||||
.param_patterns_id = SemIR::InstBlockId::Empty,
|
||||
.is_extern = false,
|
||||
.extern_library_id = SemIR::LibraryNameId::None,
|
||||
.non_owning_decl_id = SemIR::InstId::None,
|
||||
.first_owning_decl_id = noop_id,
|
||||
},
|
||||
{
|
||||
.call_param_patterns_id = call_param_patterns_id,
|
||||
.call_params_id = call_params_id,
|
||||
.return_type_inst_id = SemIR::TypeInstId::None,
|
||||
.return_form_inst_id = SemIR::InstId::None,
|
||||
.return_patterns_id = SemIR::InstBlockId::None,
|
||||
.self_param_id = self_param_id,
|
||||
}};
|
||||
noop_function.SetBuiltinFunction(SemIR::BuiltinFunctionKind::NoOp);
|
||||
function_decl.function_id = context.functions().Add(noop_function);
|
||||
function_decl.type_id =
|
||||
GetFunctionType(context, function_decl.function_id, specific_id);
|
||||
ReplaceInstBeforeConstantUse(context, noop_id, function_decl);
|
||||
return noop_id;
|
||||
SemIR::NameScopeId name_scope_id,
|
||||
SemIR::NameId name_id,
|
||||
SemIR::ConstantId self_const_id) -> SemIR::InstId {
|
||||
auto self_type_id = GetFacetAsType(context, self_const_id);
|
||||
return MakeBuiltinFunction(context, loc_id, SemIR::BuiltinFunctionKind::NoOp,
|
||||
name_scope_id, name_id,
|
||||
{.self_type_id = self_type_id});
|
||||
}
|
||||
|
||||
auto BuildCustomWitness(Context& context, SemIR::LocId loc_id,
|
||||
@@ -161,8 +98,7 @@ auto BuildCustomWitness(Context& context, SemIR::LocId loc_id,
|
||||
if (struct_value.type_id == SemIR::ErrorInst::TypeId) {
|
||||
return SemIR::ErrorInst::InstId;
|
||||
}
|
||||
auto self_type_id =
|
||||
GetFacetAsType(context, loc_id, query_self_const_id);
|
||||
auto self_type_id = GetFacetAsType(context, query_self_const_id);
|
||||
// TODO: If a thunk is needed, this will build a different value each
|
||||
// time it's called, so we won't properly deduplicate repeated
|
||||
// witnesses.
|
||||
@@ -285,8 +221,10 @@ auto LookupCustomWitness(Context& context, SemIR::LocId loc_id,
|
||||
// TODO: This needs more complex logic to apply the correct behavior. Also, we
|
||||
// should avoid building a new function on each lookup since a similar query
|
||||
// could result in identical functions.
|
||||
auto noop_id = MakeNoOpFunction(context, loc_id, query_self_const_id,
|
||||
query_specific_interface.specific_id);
|
||||
auto noop_id = MakeNoOpFunction(
|
||||
context, loc_id, SemIR::NameScopeId::None,
|
||||
SemIR::NameId::ForIdentifier(context.identifiers().Add("DestroyOp")),
|
||||
query_self_const_id);
|
||||
return BuildCustomWitness(context, loc_id, query_self_const_id,
|
||||
query_specific_interface_id, {noop_id});
|
||||
}
|
||||
|
||||
@@ -1784,7 +1784,8 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context,
|
||||
case SemIR::BuiltinFunctionKind::IntRightShiftAssign:
|
||||
case SemIR::BuiltinFunctionKind::PointerMakeNull:
|
||||
case SemIR::BuiltinFunctionKind::PointerIsNull:
|
||||
case SemIR::BuiltinFunctionKind::PointerUnsafeConvert: {
|
||||
case SemIR::BuiltinFunctionKind::PointerUnsafeConvert:
|
||||
case SemIR::BuiltinFunctionKind::CppStdInitializerListMake: {
|
||||
// These are runtime-only builtins.
|
||||
// TODO: Consider tracking this on the `BuiltinFunctionKind`.
|
||||
return SemIR::ConstantId::NotConstant;
|
||||
|
||||
@@ -5,9 +5,15 @@
|
||||
#include "toolchain/check/function.h"
|
||||
|
||||
#include "common/find.h"
|
||||
#include "toolchain/base/kind_switch.h"
|
||||
#include "toolchain/check/convert.h"
|
||||
#include "toolchain/check/inst.h"
|
||||
#include "toolchain/check/merge.h"
|
||||
#include "toolchain/check/pattern.h"
|
||||
#include "toolchain/check/pattern_match.h"
|
||||
#include "toolchain/check/type.h"
|
||||
#include "toolchain/check/type_completion.h"
|
||||
#include "toolchain/sem_ir/builtin_function_kind.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
#include "toolchain/sem_ir/pattern.h"
|
||||
|
||||
@@ -23,6 +29,177 @@ auto FindSelfPattern(Context& context,
|
||||
});
|
||||
}
|
||||
|
||||
auto AddReturnPatterns(Context& context, SemIR::LocId loc_id,
|
||||
Context::FormExpr form_expr) -> SemIR::InstBlockId {
|
||||
llvm::SmallVector<SemIR::InstId, 1> return_patterns;
|
||||
auto form_inst = context.insts().Get(form_expr.form_inst_id);
|
||||
CARBON_KIND_SWITCH(form_inst) {
|
||||
case SemIR::RefForm::Kind: {
|
||||
break;
|
||||
}
|
||||
case CARBON_KIND(SemIR::InitForm init_form): {
|
||||
auto pattern_type_id = GetPatternType(context, form_expr.type_id);
|
||||
auto return_slot_pattern_id = AddPatternInst<SemIR::ReturnSlotPattern>(
|
||||
context, loc_id,
|
||||
{.type_id = pattern_type_id,
|
||||
.type_inst_id = form_expr.type_component_id});
|
||||
return_patterns.push_back(AddPatternInst<SemIR::OutParamPattern>(
|
||||
context, SemIR::LocId(form_expr.form_inst_id),
|
||||
{.type_id = pattern_type_id,
|
||||
.subpattern_id = return_slot_pattern_id,
|
||||
.index = init_form.index}));
|
||||
break;
|
||||
}
|
||||
case SemIR::ErrorInst::Kind: {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
CARBON_FATAL("unexpected inst kind: {0}", form_inst);
|
||||
}
|
||||
return context.inst_blocks().AddCanonical(return_patterns);
|
||||
}
|
||||
|
||||
auto IsValidBuiltinDeclaration(Context& context,
|
||||
const SemIR::Function& function,
|
||||
SemIR::BuiltinFunctionKind builtin_kind)
|
||||
-> bool {
|
||||
if (!function.call_params_id.has_value()) {
|
||||
// For now, we have no builtins that support positional parameters.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the list of call parameters other than the implicit return slots.
|
||||
auto call_params = context.inst_blocks()
|
||||
.Get(function.call_params_id)
|
||||
.drop_back(context.inst_blocks()
|
||||
.GetOrEmpty(function.return_patterns_id)
|
||||
.size());
|
||||
|
||||
// Get the return type. This is `()` if none was specified.
|
||||
auto return_type_id = function.GetDeclaredReturnType(context.sem_ir());
|
||||
if (!return_type_id.has_value()) {
|
||||
return_type_id = GetTupleType(context, {});
|
||||
}
|
||||
|
||||
return builtin_kind.IsValidType(context.sem_ir(), call_params,
|
||||
return_type_id);
|
||||
}
|
||||
|
||||
auto MakeBuiltinFunction(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::BuiltinFunctionKind builtin_kind,
|
||||
SemIR::NameScopeId name_scope_id,
|
||||
SemIR::NameId name_id,
|
||||
BuiltinFunctionSignature signature) -> SemIR::InstId {
|
||||
// TODO: Refactor with function construction in thunk.cpp and cpp/import.cpp.
|
||||
context.scope_stack().PushForDeclName();
|
||||
context.inst_block_stack().Push();
|
||||
context.pattern_block_stack().Push();
|
||||
|
||||
// Build and add a `[ref self: Self]` parameter if needed.
|
||||
auto implicit_param_patterns_id = SemIR::InstBlockId::None;
|
||||
auto self_param_id = SemIR::InstId::None;
|
||||
if (signature.self_type_id.has_value()) {
|
||||
context.full_pattern_stack().PushFullPattern(
|
||||
FullPatternStack::Kind::ImplicitParamList);
|
||||
|
||||
BeginSubpattern(context);
|
||||
auto self_type_region_id = EndSubpatternAsExpr(
|
||||
context, context.types().GetInstId(signature.self_type_id));
|
||||
|
||||
self_param_id = AddParamPattern(context, loc_id, SemIR::NameId::SelfValue,
|
||||
self_type_region_id, signature.self_type_id,
|
||||
signature.self_is_ref);
|
||||
implicit_param_patterns_id = context.inst_blocks().Add({self_param_id});
|
||||
|
||||
context.full_pattern_stack().EndImplicitParamList();
|
||||
} else {
|
||||
context.full_pattern_stack().PushFullPattern(
|
||||
FullPatternStack::Kind::ExplicitParamList);
|
||||
}
|
||||
|
||||
// Build and add any explicit parameters. We always use value parameters for
|
||||
// now.
|
||||
auto param_patterns_id = SemIR::InstBlockId::Empty;
|
||||
if (!signature.param_type_ids.empty()) {
|
||||
context.inst_block_stack().Push();
|
||||
for (auto param_type_id : signature.param_type_ids) {
|
||||
BeginSubpattern(context);
|
||||
auto param_type_region_id = EndSubpatternAsExpr(
|
||||
context, context.types().GetInstId(param_type_id));
|
||||
|
||||
context.inst_block_stack().AddInstId(AddParamPattern(
|
||||
context, loc_id, SemIR::NameId::Underscore, param_type_region_id,
|
||||
param_type_id, /*is_ref=*/false));
|
||||
}
|
||||
param_patterns_id = context.inst_block_stack().Pop();
|
||||
}
|
||||
|
||||
// Build and add the return type. We always use an initializing form for now.
|
||||
auto return_patterns_id = SemIR::InstBlockId::None;
|
||||
Context::FormExpr return_form = {.form_inst_id = SemIR::InstId::None,
|
||||
.type_component_id = SemIR::TypeInstId::None,
|
||||
.type_id = SemIR::TypeId::None};
|
||||
if (signature.return_type_id.has_value()) {
|
||||
return_form = ExprAsReturnForm(
|
||||
context, loc_id, context.types().GetInstId(signature.return_type_id));
|
||||
return_patterns_id = AddReturnPatterns(context, loc_id, return_form);
|
||||
}
|
||||
|
||||
auto [call_param_patterns_id, call_params_id] =
|
||||
CalleePatternMatch(context, implicit_param_patterns_id, param_patterns_id,
|
||||
return_patterns_id);
|
||||
|
||||
context.full_pattern_stack().PopFullPattern();
|
||||
auto pattern_block_id = context.pattern_block_stack().Pop();
|
||||
auto decl_block_id = context.inst_block_stack().Pop();
|
||||
context.scope_stack().Pop();
|
||||
|
||||
// Add the function declaration.
|
||||
SemIR::FunctionDecl function_decl = {.type_id = SemIR::TypeId::None,
|
||||
.function_id = SemIR::FunctionId::None,
|
||||
.decl_block_id = decl_block_id};
|
||||
auto decl_id = AddPlaceholderInstInNoBlock(
|
||||
context, SemIR::LocIdAndInst::UncheckedLoc(loc_id, function_decl));
|
||||
|
||||
// Build the function entity.
|
||||
auto function = SemIR::Function{
|
||||
{
|
||||
.name_id = name_id,
|
||||
.parent_scope_id = name_scope_id,
|
||||
.generic_id = SemIR::GenericId::None,
|
||||
.first_param_node_id = Parse::NodeId::None,
|
||||
.last_param_node_id = Parse::NodeId::None,
|
||||
.pattern_block_id = pattern_block_id,
|
||||
.implicit_param_patterns_id = implicit_param_patterns_id,
|
||||
.param_patterns_id = param_patterns_id,
|
||||
.is_extern = false,
|
||||
.extern_library_id = SemIR::LibraryNameId::None,
|
||||
.non_owning_decl_id = SemIR::InstId::None,
|
||||
.first_owning_decl_id = decl_id,
|
||||
.definition_id = decl_id,
|
||||
},
|
||||
{
|
||||
.call_param_patterns_id = call_param_patterns_id,
|
||||
.call_params_id = call_params_id,
|
||||
.return_type_inst_id = return_form.type_component_id,
|
||||
.return_form_inst_id = return_form.form_inst_id,
|
||||
.return_patterns_id = return_patterns_id,
|
||||
.self_param_id = self_param_id,
|
||||
}};
|
||||
CARBON_CHECK(IsValidBuiltinDeclaration(context, function, builtin_kind));
|
||||
function.SetBuiltinFunction(builtin_kind);
|
||||
function_decl.function_id = context.functions().Add(function);
|
||||
function_decl.type_id = GetFunctionType(context, function_decl.function_id,
|
||||
SemIR::SpecificId::None);
|
||||
ReplaceInstBeforeConstantUse(context, decl_id, function_decl);
|
||||
// Add the builtin to the imports block so that it appears in the formatted
|
||||
// IR.
|
||||
// TODO: Find a better way to handle this. Ideally we should stop using this
|
||||
// function entirely and declare builtins in the prelude.
|
||||
context.imports().push_back(decl_id);
|
||||
return decl_id;
|
||||
}
|
||||
|
||||
auto CheckFunctionReturnTypeMatches(Context& context,
|
||||
const SemIR::Function& new_function,
|
||||
const SemIR::Function& prev_function,
|
||||
|
||||
@@ -19,6 +19,39 @@ auto FindSelfPattern(Context& context,
|
||||
SemIR::InstBlockId implicit_param_patterns_id)
|
||||
-> SemIR::InstId;
|
||||
|
||||
// Creates suitable return patterns for the given return form, and adds them to
|
||||
// the current pattern block.
|
||||
auto AddReturnPatterns(Context& context, SemIR::LocId loc_id,
|
||||
Context::FormExpr form_expr) -> SemIR::InstBlockId;
|
||||
|
||||
// Returns whether `function` is a valid declaration of `builtin_kind`.
|
||||
auto IsValidBuiltinDeclaration(Context& context,
|
||||
const SemIR::Function& function,
|
||||
SemIR::BuiltinFunctionKind builtin_kind) -> bool;
|
||||
|
||||
// The signature to declare for a builtin function.
|
||||
struct BuiltinFunctionSignature {
|
||||
// The type of the implicit `[self: Self]` parameter, or `None` if there is
|
||||
// none.
|
||||
SemIR::TypeId self_type_id = SemIR::TypeId::None;
|
||||
// Whether `self` is a ref parameter.
|
||||
bool self_is_ref = true;
|
||||
// The types of the explicit parameters.
|
||||
llvm::ArrayRef<SemIR::TypeId> param_type_ids = {};
|
||||
// The return type, or `None` if the function doesn't declare a return type.
|
||||
SemIR::TypeId return_type_id = SemIR::TypeId::None;
|
||||
};
|
||||
|
||||
// Creates and returns a new builtin function declaration.
|
||||
//
|
||||
// TODO: Instead of synthesizing builtin function declarations, we should
|
||||
// ideally declare the builtin functions in Carbon code instead.
|
||||
auto MakeBuiltinFunction(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::BuiltinFunctionKind builtin_kind,
|
||||
SemIR::NameScopeId name_scope_id,
|
||||
SemIR::NameId name_id,
|
||||
BuiltinFunctionSignature signature) -> SemIR::InstId;
|
||||
|
||||
// Checks that `new_function` has the same return type as `prev_function`, or if
|
||||
// `prev_function_id` is specified, a specific version of `prev_function`.
|
||||
// Prints a suitable diagnostic and returns false if not. Never checks for a
|
||||
|
||||
@@ -71,37 +71,8 @@ auto HandleParseNode(Context& context, Parse::ReturnTypeId node_id) -> bool {
|
||||
// Propagate the type expression.
|
||||
auto form_expr = ExprAsReturnForm(context, type_node_id, type_inst_id);
|
||||
context.PushReturnForm(form_expr);
|
||||
|
||||
llvm::SmallVector<SemIR::InstId, 1> return_patterns;
|
||||
auto form_inst = context.insts().Get(form_expr.form_inst_id);
|
||||
CARBON_KIND_SWITCH(form_inst) {
|
||||
case SemIR::RefForm::Kind: {
|
||||
break;
|
||||
}
|
||||
case CARBON_KIND(SemIR::InitForm init_form): {
|
||||
auto pattern_type_id = GetPatternType(context, form_expr.type_id);
|
||||
auto return_slot_pattern_id = AddPatternInst<SemIR::ReturnSlotPattern>(
|
||||
context, node_id,
|
||||
{.type_id = pattern_type_id,
|
||||
.type_inst_id = form_expr.type_component_id});
|
||||
return_patterns.push_back(AddPatternInst(
|
||||
context,
|
||||
SemIR::LocIdAndInst::UncheckedLoc(
|
||||
type_node_id,
|
||||
SemIR::OutParamPattern{.type_id = pattern_type_id,
|
||||
.subpattern_id = return_slot_pattern_id,
|
||||
.index = init_form.index})));
|
||||
break;
|
||||
}
|
||||
case SemIR::ErrorInst::Kind: {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
CARBON_FATAL("unexpected inst kind: {0}", form_inst);
|
||||
}
|
||||
|
||||
context.node_stack().Push(
|
||||
node_id, context.inst_blocks().AddCanonical(return_patterns));
|
||||
auto return_patterns_id = AddReturnPatterns(context, node_id, form_expr);
|
||||
context.node_stack().Push(node_id, return_patterns_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -631,33 +602,6 @@ static auto LookupBuiltinFunctionKind(Context& context,
|
||||
return kind;
|
||||
}
|
||||
|
||||
// Returns whether `function` is a valid declaration of `builtin_kind`.
|
||||
static auto IsValidBuiltinDeclaration(Context& context,
|
||||
const SemIR::Function& function,
|
||||
SemIR::BuiltinFunctionKind builtin_kind)
|
||||
-> bool {
|
||||
if (!function.call_params_id.has_value()) {
|
||||
// For now, we have no builtins that support positional parameters.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the list of call parameters other than the implicit return slots.
|
||||
auto call_params = context.inst_blocks()
|
||||
.Get(function.call_params_id)
|
||||
.drop_back(context.inst_blocks()
|
||||
.GetOrEmpty(function.return_patterns_id)
|
||||
.size());
|
||||
|
||||
// Get the return type. This is `()` if none was specified.
|
||||
auto return_type_id = function.GetDeclaredReturnType(context.sem_ir());
|
||||
if (!return_type_id.has_value()) {
|
||||
return_type_id = GetTupleType(context, {});
|
||||
}
|
||||
|
||||
return builtin_kind.IsValidType(context.sem_ir(), call_params,
|
||||
return_type_id);
|
||||
}
|
||||
|
||||
auto HandleParseNode(Context& context,
|
||||
Parse::BuiltinFunctionDefinitionId /*node_id*/) -> bool {
|
||||
auto name_id =
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/cpp/std/initializer_list/make.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/cpp/std/initializer_list/make.carbon
|
||||
|
||||
// --- valid_pointer_pointer.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
class PointerPointer {
|
||||
var start: i32*;
|
||||
var end: i32*;
|
||||
}
|
||||
|
||||
fn Make(arr: array(i32, 3)) -> PointerPointer = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- valid_pointer_int.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
class PointerInt {
|
||||
var start: i32*;
|
||||
var size: i32;
|
||||
}
|
||||
|
||||
fn Make(arr: array(i32, 3)) -> PointerInt = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- imported_from_cpp.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp inline '''
|
||||
struct PointerPointer {
|
||||
int* start;
|
||||
int* end;
|
||||
};
|
||||
|
||||
struct PointerInt {
|
||||
int* start;
|
||||
int size;
|
||||
};
|
||||
''';
|
||||
|
||||
fn MakePointerPointer(arr: array(i32, 3)) -> Cpp.PointerPointer = "cpp.std.initializer_list.make";
|
||||
|
||||
fn MakePointerInt(arr: array(i32, 3)) -> Cpp.PointerInt = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- fail_incomplete.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
class FailIncomplete;
|
||||
|
||||
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE+18]]:20: error: function returns incomplete type `FailIncomplete` [IncompleteTypeInFunctionReturnType]
|
||||
// CHECK:STDERR: fn Make(n: i32) -> FailIncomplete = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-5]]:1: note: class was forward declared here [ClassForwardDeclaredHere]
|
||||
// CHECK:STDERR: class FailIncomplete;
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE+11]]:20: error: parameter has incomplete type `FailIncomplete` in function definition [IncompleteTypeInFunctionParam]
|
||||
// CHECK:STDERR: fn Make(n: i32) -> FailIncomplete = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE-12]]:1: note: class was forward declared here [ClassForwardDeclaredHere]
|
||||
// CHECK:STDERR: class FailIncomplete;
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_incomplete.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "cpp.std.initializer_list.make" [InvalidBuiltinSignature]
|
||||
// CHECK:STDERR: fn Make(n: i32) -> FailIncomplete = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn Make(n: i32) -> FailIncomplete = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- fail_wrong_arg.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
class FailWrongArg {
|
||||
var start: i32*;
|
||||
var end: i32*;
|
||||
}
|
||||
|
||||
// CHECK:STDERR: fail_wrong_arg.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "cpp.std.initializer_list.make" [InvalidBuiltinSignature]
|
||||
// CHECK:STDERR: fn Make(n: i32) -> FailWrongArg = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn Make(n: i32) -> FailWrongArg = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- fail_wrong_arg_count.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
class FailWrongArgCount {
|
||||
var start: i32*;
|
||||
var end: i32*;
|
||||
}
|
||||
|
||||
// CHECK:STDERR: fail_wrong_arg_count.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "cpp.std.initializer_list.make" [InvalidBuiltinSignature]
|
||||
// CHECK:STDERR: fn Make(arr: array(i32, 3), n: i32) -> FailWrongArgCount = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn Make(arr: array(i32, 3), n: i32) -> FailWrongArgCount = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- fail_not_a_class.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_not_a_class.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "cpp.std.initializer_list.make" [InvalidBuiltinSignature]
|
||||
// CHECK:STDERR: fn Make(arr: array(i32, 3)) -> i32 = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn Make(arr: array(i32, 3)) -> i32 = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- fail_wrong_field_count.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
class FailWrongFieldCount {
|
||||
var start: i32*;
|
||||
}
|
||||
|
||||
// CHECK:STDERR: fail_wrong_field_count.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "cpp.std.initializer_list.make" [InvalidBuiltinSignature]
|
||||
// CHECK:STDERR: fn Make(arr: array(i32, 3)) -> FailWrongFieldCount = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn Make(arr: array(i32, 3)) -> FailWrongFieldCount = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- fail_wrong_first_field.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
class FailWrongFirstField {
|
||||
var start: i32;
|
||||
var end: i32;
|
||||
}
|
||||
|
||||
// CHECK:STDERR: fail_wrong_first_field.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "cpp.std.initializer_list.make" [InvalidBuiltinSignature]
|
||||
// CHECK:STDERR: fn Make(arr: array(i32, 3)) -> FailWrongFirstField = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn Make(arr: array(i32, 3)) -> FailWrongFirstField = "cpp.std.initializer_list.make";
|
||||
|
||||
// --- fail_wrong_second_field.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
class FailWrongSecondField {
|
||||
var start: i32*;
|
||||
var end: {.a: i32};
|
||||
}
|
||||
|
||||
// CHECK:STDERR: fail_wrong_second_field.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "cpp.std.initializer_list.make" [InvalidBuiltinSignature]
|
||||
// CHECK:STDERR: fn Make(arr: array(i32, 3)) -> FailWrongSecondField = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn Make(arr: array(i32, 3)) -> FailWrongSecondField = "cpp.std.initializer_list.make";
|
||||
@@ -344,8 +344,8 @@ fn F[template T:! Core.Destroy](x: T) {
|
||||
// CHECK:STDOUT: assign %v.var, <error>
|
||||
// CHECK:STDOUT: %.loc14_10.1: type = splice_block %.loc14_10.2 [template = %T.binding.as_type (constants.%T.binding.as_type.140)] {
|
||||
// CHECK:STDOUT: %T.ref.loc14: %Destroy.type = name_ref T, %T.loc4_15.2 [template = %T.loc4_15.1 (constants.%T.765)]
|
||||
// CHECK:STDOUT: %T.as_type.loc14_10: type = facet_access_type %T.ref.loc14 [template = %T.binding.as_type (constants.%T.binding.as_type.140)]
|
||||
// CHECK:STDOUT: %.loc14_10.2: type = converted %T.ref.loc14, %T.as_type.loc14_10 [template = %T.binding.as_type (constants.%T.binding.as_type.140)]
|
||||
// CHECK:STDOUT: %T.as_type.loc14: type = facet_access_type %T.ref.loc14 [template = %T.binding.as_type (constants.%T.binding.as_type.140)]
|
||||
// CHECK:STDOUT: %.loc14_10.2: type = converted %T.ref.loc14, %T.as_type.loc14 [template = %T.binding.as_type (constants.%T.binding.as_type.140)]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %v: ref @F.%T.binding.as_type (%T.binding.as_type.140) = ref_binding v, %v.var
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
@@ -363,7 +363,6 @@ fn F[template T:! Core.Destroy](x: T) {
|
||||
// CHECK:STDOUT: %w: ref %i32 = ref_binding w, %w.var
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc22: <bound method> = bound_method %w.var, constants.%DestroyOp.b0ebf8.1
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc22: init %empty_tuple.type = call %DestroyOp.bound.loc22(%w.var)
|
||||
// CHECK:STDOUT: %T.as_type.loc14_3: type = facet_access_type constants.%T.765 [template = %T.binding.as_type (constants.%T.binding.as_type.140)]
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc14: <bound method> = bound_method %v.var, constants.%DestroyOp.b0ebf8.2
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc14: init %empty_tuple.type = call %DestroyOp.bound.loc14(%v.var)
|
||||
// CHECK:STDOUT: return
|
||||
|
||||
@@ -1910,7 +1910,6 @@ fn F() {
|
||||
// CHECK:STDOUT: %.loc13_29.4: ref @GenericResult.%as_type.loc12_35.1 (%as_type.baf) = temporary %.loc13_29.3, %J.F.call.loc13_29
|
||||
// CHECK:STDOUT: %.loc13_29.5: @GenericResult.%as_type.loc12_35.1 (%as_type.baf) = acquire_value %.loc13_29.4
|
||||
// CHECK:STDOUT: %I.Op.call: init @GenericResult.%as_type.loc12_35.1 (%as_type.baf) to %.loc12_43.1 = call %bound_method.loc13_30(%.loc13_15.5, %.loc13_29.5)
|
||||
// CHECK:STDOUT: %as_type.loc13: type = facet_access_type constants.%impl.elem0.397 [symbolic = %as_type.loc12_35.1 (constants.%as_type.baf)]
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc13_29: <bound method> = bound_method %.loc13_29.4, constants.%DestroyOp
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc13_29: init %empty_tuple.type = call %DestroyOp.bound.loc13_29(%.loc13_29.4)
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc13_15: <bound method> = bound_method %.loc13_15.4, constants.%DestroyOp
|
||||
|
||||
+118
-106
@@ -382,48 +382,52 @@ import Cpp library "struct_init.h";
|
||||
fn MakeEmpty() -> ();
|
||||
|
||||
fn Empty(value: (), ref reference: ()) {
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+10]]:20: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct NoFields]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+11]]:20: error: cannot implicitly convert expression of type `()` to `Cpp.NoFields` [ConversionFailure]
|
||||
// CHECK:STDERR: Cpp.PassNoFields(());
|
||||
// CHECK:STDERR: ^~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-13]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+8]]:20: note: type `()` does not implement interface `Core.ImplicitAs(Cpp.NoFields)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: Cpp.PassNoFields(());
|
||||
// CHECK:STDERR: ^~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-14]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./struct_init.h:4:28: note: initializing function parameter [InCallToFunctionParam]
|
||||
// CHECK:STDERR: auto PassNoFields(NoFields s) -> void;
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
Cpp.PassNoFields(());
|
||||
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+10]]:20: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct NoFields]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+11]]:20: error: cannot implicitly convert expression of type `()` to `Cpp.NoFields` [ConversionFailure]
|
||||
// CHECK:STDERR: Cpp.PassNoFields(value);
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-25]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+8]]:20: note: type `()` does not implement interface `Core.ImplicitAs(Cpp.NoFields)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: Cpp.PassNoFields(value);
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-27]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./struct_init.h:4:28: note: initializing function parameter [InCallToFunctionParam]
|
||||
// CHECK:STDERR: auto PassNoFields(NoFields s) -> void;
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
Cpp.PassNoFields(value);
|
||||
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+10]]:20: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct NoFields]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+11]]:20: error: cannot implicitly convert expression of type `()` to `Cpp.NoFields` [ConversionFailure]
|
||||
// CHECK:STDERR: Cpp.PassNoFields(reference);
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-37]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+8]]:20: note: type `()` does not implement interface `Core.ImplicitAs(Cpp.NoFields)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: Cpp.PassNoFields(reference);
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-40]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./struct_init.h:4:28: note: initializing function parameter [InCallToFunctionParam]
|
||||
// CHECK:STDERR: auto PassNoFields(NoFields s) -> void;
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
Cpp.PassNoFields(reference);
|
||||
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+10]]:20: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct NoFields]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+11]]:20: error: cannot implicitly convert expression of type `()` to `Cpp.NoFields` [ConversionFailure]
|
||||
// CHECK:STDERR: Cpp.PassNoFields(MakeEmpty());
|
||||
// CHECK:STDERR: ^~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-49]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+8]]:20: note: type `()` does not implement interface `Core.ImplicitAs(Cpp.NoFields)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: Cpp.PassNoFields(MakeEmpty());
|
||||
// CHECK:STDERR: ^~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-53]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./struct_init.h:4:28: note: initializing function parameter [InCallToFunctionParam]
|
||||
// CHECK:STDERR: auto PassNoFields(NoFields s) -> void;
|
||||
// CHECK:STDERR: ^
|
||||
@@ -434,48 +438,52 @@ fn Empty(value: (), ref reference: ()) {
|
||||
fn MakeThreeFields() -> (i32, i32, i32);
|
||||
|
||||
fn ThreeFields(value: (i32, i32, i32), ref reference: (i32, i32, i32)) {
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+10]]:23: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct ThreeFields]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+11]]:23: error: cannot implicitly convert expression of type `(Core.IntLiteral, Core.IntLiteral, Core.IntLiteral)` to `Cpp.ThreeFields` [ConversionFailure]
|
||||
// CHECK:STDERR: Cpp.PassThreeFields((1, 2, 3));
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-65]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+8]]:23: note: type `(Core.IntLiteral, Core.IntLiteral, Core.IntLiteral)` does not implement interface `Core.ImplicitAs(Cpp.ThreeFields)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: Cpp.PassThreeFields((1, 2, 3));
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-70]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./struct_init.h:10:34: note: initializing function parameter [InCallToFunctionParam]
|
||||
// CHECK:STDERR: auto PassThreeFields(ThreeFields t) -> void;
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
Cpp.PassThreeFields((1, 2, 3));
|
||||
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+10]]:23: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct ThreeFields]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+11]]:23: error: cannot implicitly convert expression of type `(i32, i32, i32)` to `Cpp.ThreeFields` [ConversionFailure]
|
||||
// CHECK:STDERR: Cpp.PassThreeFields(value);
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-77]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+8]]:23: note: type `(i32, i32, i32)` does not implement interface `Core.ImplicitAs(Cpp.ThreeFields)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: Cpp.PassThreeFields(value);
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-83]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./struct_init.h:10:34: note: initializing function parameter [InCallToFunctionParam]
|
||||
// CHECK:STDERR: auto PassThreeFields(ThreeFields t) -> void;
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
Cpp.PassThreeFields(value);
|
||||
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+10]]:23: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct ThreeFields]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+11]]:23: error: cannot implicitly convert expression of type `(i32, i32, i32)` to `Cpp.ThreeFields` [ConversionFailure]
|
||||
// CHECK:STDERR: Cpp.PassThreeFields(reference);
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-89]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+8]]:23: note: type `(i32, i32, i32)` does not implement interface `Core.ImplicitAs(Cpp.ThreeFields)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: Cpp.PassThreeFields(reference);
|
||||
// CHECK:STDERR: ^~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-96]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./struct_init.h:10:34: note: initializing function parameter [InCallToFunctionParam]
|
||||
// CHECK:STDERR: auto PassThreeFields(ThreeFields t) -> void;
|
||||
// CHECK:STDERR: ^
|
||||
// CHECK:STDERR:
|
||||
Cpp.PassThreeFields(reference);
|
||||
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+10]]:23: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct ThreeFields]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+11]]:23: error: cannot implicitly convert expression of type `(i32, i32, i32)` to `Cpp.ThreeFields` [ConversionFailure]
|
||||
// CHECK:STDERR: Cpp.PassThreeFields(MakeThreeFields());
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-101]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE+8]]:23: note: type `(i32, i32, i32)` does not implement interface `Core.ImplicitAs(Cpp.ThreeFields)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: Cpp.PassThreeFields(MakeThreeFields());
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_struct_init_from_tuple.carbon:[[@LINE-109]]:10: in file included here [InCppInclude]
|
||||
// CHECK:STDERR: ./struct_init.h:10:34: note: initializing function parameter [InCallToFunctionParam]
|
||||
// CHECK:STDERR: auto PassThreeFields(ThreeFields t) -> void;
|
||||
// CHECK:STDERR: ^
|
||||
@@ -2827,6 +2835,8 @@ fn F() {
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk: %PassNoFields__carbon_thunk.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
||||
// CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
|
||||
// CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
|
||||
// CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
|
||||
@@ -2838,7 +2848,7 @@ fn F() {
|
||||
// CHECK:STDOUT: %pattern_type.b5a: type = pattern_type %tuple.type.189 [concrete]
|
||||
// CHECK:STDOUT: %MakeThreeFields.type: type = fn_type @MakeThreeFields [concrete]
|
||||
// CHECK:STDOUT: %MakeThreeFields: %MakeThreeFields.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %ThreeFields.type: type = fn_type @ThreeFields.loc63 [concrete]
|
||||
// CHECK:STDOUT: %ThreeFields.type: type = fn_type @ThreeFields.loc67 [concrete]
|
||||
// CHECK:STDOUT: %ThreeFields.c3a: %ThreeFields.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %PassThreeFields.cpp_overload_set.type: type = cpp_overload_set_type @PassThreeFields.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %PassThreeFields.cpp_overload_set.value: %PassThreeFields.cpp_overload_set.type = cpp_overload_set_value @PassThreeFields.cpp_overload_set [concrete]
|
||||
@@ -2859,6 +2869,7 @@ fn F() {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
||||
// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
|
||||
// CHECK:STDOUT: .Int = %Core.Int
|
||||
// CHECK:STDOUT: import Core//prelude
|
||||
// CHECK:STDOUT: import Core//prelude/...
|
||||
@@ -2876,6 +2887,7 @@ fn F() {
|
||||
// CHECK:STDOUT: %s.param: %ptr.dd0 = value_param call_param0
|
||||
// CHECK:STDOUT: %s: %ptr.dd0 = value_binding s, %s.param
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
|
||||
// CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
|
||||
// CHECK:STDOUT: %PassThreeFields.cpp_overload_set.value: %PassThreeFields.cpp_overload_set.type = cpp_overload_set_value @PassThreeFields.cpp_overload_set [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.decl: %PassThreeFields__carbon_thunk.type = fn_decl @PassThreeFields__carbon_thunk [concrete = constants.%PassThreeFields__carbon_thunk] {
|
||||
@@ -2933,46 +2945,46 @@ fn F() {
|
||||
// CHECK:STDOUT: %return.patt: %pattern_type.b5a = return_slot_pattern [concrete]
|
||||
// CHECK:STDOUT: %return.param_patt: %pattern_type.b5a = out_param_pattern %return.patt, call_param0 [concrete]
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: %int_32.loc61_26: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc61_26: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc61_31: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc61_31: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc61_36: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc61_36: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc61_39.1: %tuple.type.ff9 = tuple_literal (%i32.loc61_26, %i32.loc61_31, %i32.loc61_36) [concrete = constants.%tuple.e64]
|
||||
// CHECK:STDOUT: %.loc61_39.2: type = converted %.loc61_39.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
|
||||
// CHECK:STDOUT: %.loc61_39.3: form = init_form %.loc61_39.2, call_param0 [concrete = constants.%.084]
|
||||
// CHECK:STDOUT: %int_32.loc65_26: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc65_26: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc65_31: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc65_31: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc65_36: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc65_36: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc65_39.1: %tuple.type.ff9 = tuple_literal (%i32.loc65_26, %i32.loc65_31, %i32.loc65_36) [concrete = constants.%tuple.e64]
|
||||
// CHECK:STDOUT: %.loc65_39.2: type = converted %.loc65_39.1, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
|
||||
// CHECK:STDOUT: %.loc65_39.3: form = init_form %.loc65_39.2, call_param0 [concrete = constants.%.084]
|
||||
// CHECK:STDOUT: %return.param: ref %tuple.type.189 = out_param call_param0
|
||||
// CHECK:STDOUT: %return: ref %tuple.type.189 = return_slot %return.param
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %ThreeFields.decl: %ThreeFields.type = fn_decl @ThreeFields.loc63 [concrete = constants.%ThreeFields.c3a] {
|
||||
// CHECK:STDOUT: %ThreeFields.decl: %ThreeFields.type = fn_decl @ThreeFields.loc67 [concrete = constants.%ThreeFields.c3a] {
|
||||
// CHECK:STDOUT: %value.patt: %pattern_type.b5a = value_binding_pattern value [concrete]
|
||||
// CHECK:STDOUT: %value.param_patt: %pattern_type.b5a = value_param_pattern %value.patt, call_param0 [concrete]
|
||||
// CHECK:STDOUT: %reference.patt: %pattern_type.b5a = ref_binding_pattern reference [concrete]
|
||||
// CHECK:STDOUT: %reference.param_patt: %pattern_type.b5a = ref_param_pattern %reference.patt, call_param1 [concrete]
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: %value.param: %tuple.type.189 = value_param call_param0
|
||||
// CHECK:STDOUT: %.loc63_37.1: type = splice_block %.loc63_37.3 [concrete = constants.%tuple.type.189] {
|
||||
// CHECK:STDOUT: %int_32.loc63_24: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc63_24: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc63_29: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc63_29: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc63_34: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc63_34: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc63_37.2: %tuple.type.ff9 = tuple_literal (%i32.loc63_24, %i32.loc63_29, %i32.loc63_34) [concrete = constants.%tuple.e64]
|
||||
// CHECK:STDOUT: %.loc63_37.3: type = converted %.loc63_37.2, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
|
||||
// CHECK:STDOUT: %.loc67_37.1: type = splice_block %.loc67_37.3 [concrete = constants.%tuple.type.189] {
|
||||
// CHECK:STDOUT: %int_32.loc67_24: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc67_24: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc67_29: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc67_29: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc67_34: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc67_34: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc67_37.2: %tuple.type.ff9 = tuple_literal (%i32.loc67_24, %i32.loc67_29, %i32.loc67_34) [concrete = constants.%tuple.e64]
|
||||
// CHECK:STDOUT: %.loc67_37.3: type = converted %.loc67_37.2, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %value: %tuple.type.189 = value_binding value, %value.param
|
||||
// CHECK:STDOUT: %reference.param: ref %tuple.type.189 = ref_param call_param1
|
||||
// CHECK:STDOUT: %.loc63_69.1: type = splice_block %.loc63_69.3 [concrete = constants.%tuple.type.189] {
|
||||
// CHECK:STDOUT: %int_32.loc63_56: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc63_56: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc63_61: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc63_61: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc63_66: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc63_66: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc63_69.2: %tuple.type.ff9 = tuple_literal (%i32.loc63_56, %i32.loc63_61, %i32.loc63_66) [concrete = constants.%tuple.e64]
|
||||
// CHECK:STDOUT: %.loc63_69.3: type = converted %.loc63_69.2, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
|
||||
// CHECK:STDOUT: %.loc67_69.1: type = splice_block %.loc67_69.3 [concrete = constants.%tuple.type.189] {
|
||||
// CHECK:STDOUT: %int_32.loc67_56: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc67_56: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc67_61: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc67_61: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %int_32.loc67_66: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
||||
// CHECK:STDOUT: %i32.loc67_66: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc67_69.2: %tuple.type.ff9 = tuple_literal (%i32.loc67_56, %i32.loc67_61, %i32.loc67_66) [concrete = constants.%tuple.e64]
|
||||
// CHECK:STDOUT: %.loc67_69.3: type = converted %.loc67_69.2, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %reference: ref %tuple.type.189 = ref_binding reference, %reference.param
|
||||
// CHECK:STDOUT: }
|
||||
@@ -3009,31 +3021,31 @@ fn F() {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @Empty(%value.param: %empty_tuple.type, %reference.param: %empty_tuple.type) {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %Cpp.ref.loc22: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassNoFields.ref.loc22: %PassNoFields.cpp_overload_set.type = name_ref PassNoFields, imports.%PassNoFields.cpp_overload_set.value [concrete = constants.%PassNoFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %.loc22_21.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc22_21.2: %NoFields = converted %.loc22_21.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc22: %ptr.dd0 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk.call.loc22: init %empty_tuple.type = call imports.%PassNoFields__carbon_thunk.decl(%addr.loc22)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc34: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassNoFields.ref.loc34: %PassNoFields.cpp_overload_set.type = name_ref PassNoFields, imports.%PassNoFields.cpp_overload_set.value [concrete = constants.%PassNoFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %Cpp.ref.loc23: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassNoFields.ref.loc23: %PassNoFields.cpp_overload_set.type = name_ref PassNoFields, imports.%PassNoFields.cpp_overload_set.value [concrete = constants.%PassNoFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %.loc23_21.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc23_21.2: %NoFields = converted %.loc23_21.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc23: %ptr.dd0 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk.call.loc23: init %empty_tuple.type = call imports.%PassNoFields__carbon_thunk.decl(%addr.loc23)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc36: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassNoFields.ref.loc36: %PassNoFields.cpp_overload_set.type = name_ref PassNoFields, imports.%PassNoFields.cpp_overload_set.value [concrete = constants.%PassNoFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %value.ref: %empty_tuple.type = name_ref value, %value
|
||||
// CHECK:STDOUT: %.loc34: %NoFields = converted %value.ref, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc34: %ptr.dd0 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk.call.loc34: init %empty_tuple.type = call imports.%PassNoFields__carbon_thunk.decl(%addr.loc34)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc46: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassNoFields.ref.loc46: %PassNoFields.cpp_overload_set.type = name_ref PassNoFields, imports.%PassNoFields.cpp_overload_set.value [concrete = constants.%PassNoFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %.loc36: %NoFields = converted %value.ref, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc36: %ptr.dd0 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk.call.loc36: init %empty_tuple.type = call imports.%PassNoFields__carbon_thunk.decl(%addr.loc36)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc49: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassNoFields.ref.loc49: %PassNoFields.cpp_overload_set.type = name_ref PassNoFields, imports.%PassNoFields.cpp_overload_set.value [concrete = constants.%PassNoFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %reference.ref: ref %empty_tuple.type = name_ref reference, %reference
|
||||
// CHECK:STDOUT: %.loc46: %NoFields = converted %reference.ref, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc46: %ptr.dd0 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk.call.loc46: init %empty_tuple.type = call imports.%PassNoFields__carbon_thunk.decl(%addr.loc46)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc58: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassNoFields.ref.loc58: %PassNoFields.cpp_overload_set.type = name_ref PassNoFields, imports.%PassNoFields.cpp_overload_set.value [concrete = constants.%PassNoFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %.loc49: %NoFields = converted %reference.ref, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc49: %ptr.dd0 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk.call.loc49: init %empty_tuple.type = call imports.%PassNoFields__carbon_thunk.decl(%addr.loc49)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc62: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassNoFields.ref.loc62: %PassNoFields.cpp_overload_set.type = name_ref PassNoFields, imports.%PassNoFields.cpp_overload_set.value [concrete = constants.%PassNoFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %MakeEmpty.ref: %MakeEmpty.type = name_ref MakeEmpty, file.%MakeEmpty.decl [concrete = constants.%MakeEmpty]
|
||||
// CHECK:STDOUT: %MakeEmpty.call: init %empty_tuple.type = call %MakeEmpty.ref()
|
||||
// CHECK:STDOUT: %.loc58: %NoFields = converted %MakeEmpty.call, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc58: %ptr.dd0 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk.call.loc58: init %empty_tuple.type = call imports.%PassNoFields__carbon_thunk.decl(%addr.loc58)
|
||||
// CHECK:STDOUT: %.loc62: %NoFields = converted %MakeEmpty.call, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc62: %ptr.dd0 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassNoFields__carbon_thunk.call.loc62: init %empty_tuple.type = call imports.%PassNoFields__carbon_thunk.decl(%addr.loc62)
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -3043,37 +3055,37 @@ fn F() {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @MakeThreeFields() -> out %return.param: %tuple.type.189;
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @ThreeFields.loc63(%value.param: %tuple.type.189, %reference.param: %tuple.type.189) {
|
||||
// CHECK:STDOUT: fn @ThreeFields.loc67(%value.param: %tuple.type.189, %reference.param: %tuple.type.189) {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %Cpp.ref.loc74: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassThreeFields.ref.loc74: %PassThreeFields.cpp_overload_set.type = name_ref PassThreeFields, imports.%PassThreeFields.cpp_overload_set.value [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %Cpp.ref.loc79: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassThreeFields.ref.loc79: %PassThreeFields.cpp_overload_set.type = name_ref PassThreeFields, imports.%PassThreeFields.cpp_overload_set.value [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
||||
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2]
|
||||
// CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3]
|
||||
// CHECK:STDOUT: %.loc74_31.1: %tuple.type.37f = tuple_literal (%int_1, %int_2, %int_3) [concrete = constants.%tuple.2d5]
|
||||
// CHECK:STDOUT: %.loc74_31.2: %ThreeFields.942 = converted %.loc74_31.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc74: %ptr.f81 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.call.loc74: init %empty_tuple.type = call imports.%PassThreeFields__carbon_thunk.decl(%addr.loc74)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc86: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassThreeFields.ref.loc86: %PassThreeFields.cpp_overload_set.type = name_ref PassThreeFields, imports.%PassThreeFields.cpp_overload_set.value [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %.loc79_31.1: %tuple.type.37f = tuple_literal (%int_1, %int_2, %int_3) [concrete = constants.%tuple.2d5]
|
||||
// CHECK:STDOUT: %.loc79_31.2: %ThreeFields.942 = converted %.loc79_31.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc79: %ptr.f81 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.call.loc79: init %empty_tuple.type = call imports.%PassThreeFields__carbon_thunk.decl(%addr.loc79)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc92: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassThreeFields.ref.loc92: %PassThreeFields.cpp_overload_set.type = name_ref PassThreeFields, imports.%PassThreeFields.cpp_overload_set.value [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %value.ref: %tuple.type.189 = name_ref value, %value
|
||||
// CHECK:STDOUT: %.loc86: %ThreeFields.942 = converted %value.ref, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc86: %ptr.f81 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.call.loc86: init %empty_tuple.type = call imports.%PassThreeFields__carbon_thunk.decl(%addr.loc86)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc98: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassThreeFields.ref.loc98: %PassThreeFields.cpp_overload_set.type = name_ref PassThreeFields, imports.%PassThreeFields.cpp_overload_set.value [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %.loc92: %ThreeFields.942 = converted %value.ref, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc92: %ptr.f81 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.call.loc92: init %empty_tuple.type = call imports.%PassThreeFields__carbon_thunk.decl(%addr.loc92)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc105: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassThreeFields.ref.loc105: %PassThreeFields.cpp_overload_set.type = name_ref PassThreeFields, imports.%PassThreeFields.cpp_overload_set.value [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %reference.ref: ref %tuple.type.189 = name_ref reference, %reference
|
||||
// CHECK:STDOUT: %.loc98: %ThreeFields.942 = converted %reference.ref, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc98: %ptr.f81 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.call.loc98: init %empty_tuple.type = call imports.%PassThreeFields__carbon_thunk.decl(%addr.loc98)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc110: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassThreeFields.ref.loc110: %PassThreeFields.cpp_overload_set.type = name_ref PassThreeFields, imports.%PassThreeFields.cpp_overload_set.value [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %.loc105: %ThreeFields.942 = converted %reference.ref, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc105: %ptr.f81 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.call.loc105: init %empty_tuple.type = call imports.%PassThreeFields__carbon_thunk.decl(%addr.loc105)
|
||||
// CHECK:STDOUT: %Cpp.ref.loc118: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %PassThreeFields.ref.loc118: %PassThreeFields.cpp_overload_set.type = name_ref PassThreeFields, imports.%PassThreeFields.cpp_overload_set.value [concrete = constants.%PassThreeFields.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %MakeThreeFields.ref: %MakeThreeFields.type = name_ref MakeThreeFields, file.%MakeThreeFields.decl [concrete = constants.%MakeThreeFields]
|
||||
// CHECK:STDOUT: %.loc110_39.1: ref %tuple.type.189 = temporary_storage
|
||||
// CHECK:STDOUT: %MakeThreeFields.call: init %tuple.type.189 to %.loc110_39.1 = call %MakeThreeFields.ref()
|
||||
// CHECK:STDOUT: %.loc110_39.2: %ThreeFields.942 = converted %MakeThreeFields.call, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc110: %ptr.f81 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.call.loc110: init %empty_tuple.type = call imports.%PassThreeFields__carbon_thunk.decl(%addr.loc110)
|
||||
// CHECK:STDOUT: %.loc118_39.1: ref %tuple.type.189 = temporary_storage
|
||||
// CHECK:STDOUT: %MakeThreeFields.call: init %tuple.type.189 to %.loc118_39.1 = call %MakeThreeFields.ref()
|
||||
// CHECK:STDOUT: %.loc118_39.2: %ThreeFields.942 = converted %MakeThreeFields.call, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %addr.loc118: %ptr.f81 = addr_of <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %PassThreeFields__carbon_thunk.call.loc118: init %empty_tuple.type = call imports.%PassThreeFields__carbon_thunk.decl(%addr.loc118)
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
|
||||
+35
-32
@@ -304,23 +304,26 @@ import Cpp library "aggregate.h";
|
||||
|
||||
fn InitFromTuple() {
|
||||
//@dump-sem-ir-begin
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+6]]:26: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct Aggregate]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+7]]:26: error: cannot implicitly convert expression of type `()` to `Cpp.Aggregate` [ConversionFailure]
|
||||
// CHECK:STDERR: let _: Cpp.Aggregate = ();
|
||||
// CHECK:STDERR: ^~
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+4]]:26: note: type `()` does not implement interface `Core.ImplicitAs(Cpp.Aggregate)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: let _: Cpp.Aggregate = ();
|
||||
// CHECK:STDERR: ^~
|
||||
// CHECK:STDERR:
|
||||
let _: Cpp.Aggregate = ();
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+6]]:26: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct Aggregate]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+7]]:26: error: cannot implicitly convert expression of type `(Core.IntLiteral,)` to `Cpp.Aggregate` [ConversionFailure]
|
||||
// CHECK:STDERR: let _: Cpp.Aggregate = (1,);
|
||||
// CHECK:STDERR: ^~~~
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+4]]:26: note: type `(Core.IntLiteral,)` does not implement interface `Core.ImplicitAs(Cpp.Aggregate)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: let _: Cpp.Aggregate = (1,);
|
||||
// CHECK:STDERR: ^~~~
|
||||
// CHECK:STDERR:
|
||||
let _: Cpp.Aggregate = (1,);
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+6]]:26: error: semantics TODO: `Unsupported initialization sequence:
|
||||
// CHECK:STDERR: Normal sequence: list aggregate initialization [struct Aggregate]
|
||||
// CHECK:STDERR: ` [SemanticsTodo]
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+7]]:26: error: cannot implicitly convert expression of type `(Core.IntLiteral, Core.IntLiteral)` to `Cpp.Aggregate` [ConversionFailure]
|
||||
// CHECK:STDERR: let _: Cpp.Aggregate = (1, 2);
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR: fail_todo_aggregate_from_tuple.carbon:[[@LINE+4]]:26: note: type `(Core.IntLiteral, Core.IntLiteral)` does not implement interface `Core.ImplicitAs(Cpp.Aggregate)` [MissingImplInMemberAccessNote]
|
||||
// CHECK:STDERR: let _: Cpp.Aggregate = (1, 2);
|
||||
// CHECK:STDERR: ^~~~~~
|
||||
// CHECK:STDERR:
|
||||
@@ -1263,38 +1266,38 @@ fn InitFromStruct() {
|
||||
// CHECK:STDOUT: fn @InitFromTuple() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %_.patt.loc14: %pattern_type.235 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: %_.patt.loc15: %pattern_type.235 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %.loc14_27.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc14_13: type = splice_block %Aggregate.ref.loc14 [concrete = constants.%Aggregate] {
|
||||
// CHECK:STDOUT: %Cpp.ref.loc14: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %Aggregate.ref.loc14: type = name_ref Aggregate, imports.%Aggregate.decl [concrete = constants.%Aggregate]
|
||||
// CHECK:STDOUT: %.loc15_27.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc15_13: type = splice_block %Aggregate.ref.loc15 [concrete = constants.%Aggregate] {
|
||||
// CHECK:STDOUT: %Cpp.ref.loc15: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %Aggregate.ref.loc15: type = name_ref Aggregate, imports.%Aggregate.decl [concrete = constants.%Aggregate]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %.loc14_27.2: %Aggregate = converted %.loc14_27.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %_.loc14: %Aggregate = value_binding _, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %.loc15_27.2: %Aggregate = converted %.loc15_27.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %_.loc15: %Aggregate = value_binding _, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %_.patt.loc21: %pattern_type.235 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: %_.patt.loc23: %pattern_type.235 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %int_1.loc21: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
||||
// CHECK:STDOUT: %.loc21_29.1: %tuple.type.985 = tuple_literal (%int_1.loc21) [concrete = constants.%tuple.378]
|
||||
// CHECK:STDOUT: %.loc21_13: type = splice_block %Aggregate.ref.loc21 [concrete = constants.%Aggregate] {
|
||||
// CHECK:STDOUT: %Cpp.ref.loc21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %Aggregate.ref.loc21: type = name_ref Aggregate, imports.%Aggregate.decl [concrete = constants.%Aggregate]
|
||||
// CHECK:STDOUT: %int_1.loc23: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
||||
// CHECK:STDOUT: %.loc23_29.1: %tuple.type.985 = tuple_literal (%int_1.loc23) [concrete = constants.%tuple.378]
|
||||
// CHECK:STDOUT: %.loc23_13: type = splice_block %Aggregate.ref.loc23 [concrete = constants.%Aggregate] {
|
||||
// CHECK:STDOUT: %Cpp.ref.loc23: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %Aggregate.ref.loc23: type = name_ref Aggregate, imports.%Aggregate.decl [concrete = constants.%Aggregate]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %.loc21_29.2: %Aggregate = converted %.loc21_29.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %_.loc21: %Aggregate = value_binding _, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %.loc23_29.2: %Aggregate = converted %.loc23_29.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %_.loc23: %Aggregate = value_binding _, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %_.patt.loc28: %pattern_type.235 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: %_.patt.loc31: %pattern_type.235 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %int_1.loc28: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
||||
// CHECK:STDOUT: %int_1.loc31: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
||||
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2]
|
||||
// CHECK:STDOUT: %.loc28_31.1: %tuple.type.f94 = tuple_literal (%int_1.loc28, %int_2) [concrete = constants.%tuple.ad8]
|
||||
// CHECK:STDOUT: %.loc28_13: type = splice_block %Aggregate.ref.loc28 [concrete = constants.%Aggregate] {
|
||||
// CHECK:STDOUT: %Cpp.ref.loc28: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %Aggregate.ref.loc28: type = name_ref Aggregate, imports.%Aggregate.decl [concrete = constants.%Aggregate]
|
||||
// CHECK:STDOUT: %.loc31_31.1: %tuple.type.f94 = tuple_literal (%int_1.loc31, %int_2) [concrete = constants.%tuple.ad8]
|
||||
// CHECK:STDOUT: %.loc31_13: type = splice_block %Aggregate.ref.loc31 [concrete = constants.%Aggregate] {
|
||||
// CHECK:STDOUT: %Cpp.ref.loc31: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %Aggregate.ref.loc31: type = name_ref Aggregate, imports.%Aggregate.decl [concrete = constants.%Aggregate]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %.loc28_31.2: %Aggregate = converted %.loc28_31.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %_.loc28: %Aggregate = value_binding _, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %.loc31_31.2: %Aggregate = converted %.loc31_31.1, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: %_.loc31: %Aggregate = value_binding _, <error> [concrete = <error>]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/stdlib/initializer_list.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/stdlib/initializer_list.carbon
|
||||
|
||||
// --- initializer_list.h
|
||||
|
||||
namespace std {
|
||||
using size_t = __SIZE_TYPE__;
|
||||
|
||||
template<typename T> class initializer_list {
|
||||
public:
|
||||
initializer_list() {}
|
||||
const T* begin() { return data_; }
|
||||
const T* end() { return data_ + size_; }
|
||||
size_t size() { return size_; }
|
||||
|
||||
private:
|
||||
const T* data_ = nullptr;
|
||||
size_t size_ = 0;
|
||||
};
|
||||
}
|
||||
|
||||
auto Consume(std::initializer_list<int> il) -> void;
|
||||
|
||||
struct InitListConstructor {
|
||||
InitListConstructor(std::initializer_list<int> il) {}
|
||||
};
|
||||
|
||||
// --- convert.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "initializer_list.h";
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
fn F() {
|
||||
let _: Cpp.std.initializer_list(i32) = (1, 2, 3);
|
||||
|
||||
Cpp.Consume((1, 2, 3));
|
||||
|
||||
let _: Cpp.InitListConstructor = (1, 2, 3);
|
||||
}
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// CHECK:STDOUT: --- convert.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.type: type = cpp_type_template_type initializer_list [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.template: %initializer_list.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
|
||||
// CHECK:STDOUT: %initializer_list: type = class_type @initializer_list [concrete]
|
||||
// CHECK:STDOUT: %pattern_type.22f: type = pattern_type %initializer_list [concrete]
|
||||
// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
|
||||
// CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [concrete]
|
||||
// CHECK:STDOUT: %int_3.1ba: Core.IntLiteral = int_value 3 [concrete]
|
||||
// CHECK:STDOUT: %tuple.type: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [concrete]
|
||||
// CHECK:STDOUT: %tuple: %tuple.type = tuple_value (%int_1.5b8, %int_2.ecc, %int_3.1ba) [concrete]
|
||||
// CHECK:STDOUT: %array_type: type = array_type %int_3.1ba, %i32 [concrete]
|
||||
// CHECK:STDOUT: %pattern_type.5d8: type = pattern_type %array_type [concrete]
|
||||
// CHECK:STDOUT: %.cec: form = init_form %initializer_list, call_param1 [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.type.9fcb7f.1: type = fn_type @initializer_list.initializer_list.loc8 [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.643507.1: %initializer_list.initializer_list.type.9fcb7f.1 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
|
||||
// CHECK:STDOUT: %ImplicitAs.type.e8c: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
|
||||
// CHECK:STDOUT: %ImplicitAs.Convert.type.1b6: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
|
||||
// CHECK:STDOUT: %To: Core.IntLiteral = symbolic_binding To, 0 [symbolic]
|
||||
// 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]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.3c2: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.4e6 = struct_value () [symbolic]
|
||||
// CHECK:STDOUT: %ImplicitAs.impl_witness.6bc: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.74f, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
|
||||
// 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]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.e0d = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.e8c = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.6bc) [concrete]
|
||||
// CHECK:STDOUT: %.863: type = fn_type_with_self_type %ImplicitAs.Convert.type.1b6, %ImplicitAs.facet [concrete]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.215: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5 [concrete]
|
||||
// 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]
|
||||
// CHECK:STDOUT: %bound_method.38b: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
|
||||
// CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.4e5: <bound method> = bound_method %int_2.ecc, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5 [concrete]
|
||||
// CHECK:STDOUT: %bound_method.646: <bound method> = bound_method %int_2.ecc, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
|
||||
// CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [concrete]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.061: <bound method> = bound_method %int_3.1ba, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5 [concrete]
|
||||
// CHECK:STDOUT: %bound_method.fa7: <bound method> = bound_method %int_3.1ba, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
|
||||
// CHECK:STDOUT: %int_3.822: %i32 = int_value 3 [concrete]
|
||||
// CHECK:STDOUT: %array: %array_type = tuple_value (%int_1.5d2, %int_2.ef8, %int_3.822) [concrete]
|
||||
// CHECK:STDOUT: %Consume.cpp_overload_set.type: type = cpp_overload_set_type @Consume.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %Consume.cpp_overload_set.value: %Consume.cpp_overload_set.type = cpp_overload_set_value @Consume.cpp_overload_set [concrete]
|
||||
// CHECK:STDOUT: %ptr.82f: type = ptr_type %initializer_list [concrete]
|
||||
// CHECK:STDOUT: %Consume__carbon_thunk.type: type = fn_type @Consume__carbon_thunk [concrete]
|
||||
// CHECK:STDOUT: %Consume__carbon_thunk: %Consume__carbon_thunk.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.type.9fcb7f.2: type = fn_type @initializer_list.initializer_list.loc10 [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.643507.2: %initializer_list.initializer_list.type.9fcb7f.2 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %InitListConstructor: type = class_type @InitListConstructor [concrete]
|
||||
// CHECK:STDOUT: %pattern_type.92d: type = pattern_type %InitListConstructor [concrete]
|
||||
// CHECK:STDOUT: %ptr.79d: type = ptr_type %InitListConstructor [concrete]
|
||||
// CHECK:STDOUT: %InitListConstructor__carbon_thunk.type: type = fn_type @InitListConstructor__carbon_thunk [concrete]
|
||||
// CHECK:STDOUT: %InitListConstructor__carbon_thunk: %InitListConstructor__carbon_thunk.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.type.9fcb7f.3: type = fn_type @initializer_list.initializer_list.loc12 [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.643507.3: %initializer_list.initializer_list.type.9fcb7f.3 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %InitListConstructor.cpp_destructor.type: type = fn_type @InitListConstructor.cpp_destructor [concrete]
|
||||
// CHECK:STDOUT: %InitListConstructor.cpp_destructor: %InitListConstructor.cpp_destructor.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.cpp_destructor.type: type = fn_type @initializer_list.cpp_destructor [concrete]
|
||||
// CHECK:STDOUT: %initializer_list.cpp_destructor: %initializer_list.cpp_destructor.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc12_44.3 [concrete]
|
||||
// CHECK:STDOUT: %DestroyOp.b0ebf8.6: %DestroyOp.type.3e79c2.6 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
|
||||
// CHECK:STDOUT: .std = %std
|
||||
// CHECK:STDOUT: .Consume = %Consume.cpp_overload_set.value
|
||||
// CHECK:STDOUT: .InitListConstructor = %InitListConstructor.decl
|
||||
// CHECK:STDOUT: import Cpp//...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %std: <namespace> = namespace [concrete] {
|
||||
// CHECK:STDOUT: .initializer_list = %initializer_list.template
|
||||
// CHECK:STDOUT: import Cpp//...
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %initializer_list.template: %initializer_list.type = struct_value () [concrete = constants.%initializer_list.template]
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.decl.2bdc3e.1: %initializer_list.initializer_list.type.9fcb7f.1 = fn_decl @initializer_list.initializer_list.loc8 [concrete = constants.%initializer_list.initializer_list.643507.1] {
|
||||
// CHECK:STDOUT: %_.patt: %pattern_type.5d8 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: %_.param_patt: %pattern_type.5d8 = value_param_pattern %_.patt, call_param0 [concrete]
|
||||
// CHECK:STDOUT: %return.patt: %pattern_type.22f = return_slot_pattern [concrete]
|
||||
// CHECK:STDOUT: %return.param_patt: %pattern_type.22f = out_param_pattern %return.patt, call_param1 [concrete]
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: %.loc8: form = init_form constants.%initializer_list, call_param1 [concrete = constants.%.cec]
|
||||
// CHECK:STDOUT: %_.param: %array_type = value_param call_param0
|
||||
// CHECK:STDOUT: %_: %array_type = value_binding _, %_.param
|
||||
// CHECK:STDOUT: %return.param: ref %initializer_list = out_param call_param1
|
||||
// CHECK:STDOUT: %return: ref %initializer_list = return_slot %return.param
|
||||
// CHECK:STDOUT: }
|
||||
// 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/types/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)]
|
||||
// CHECK:STDOUT: %ImplicitAs.impl_witness_table.74f = impl_witness_table (%Core.import_ref.42d), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
|
||||
// CHECK:STDOUT: %Consume.cpp_overload_set.value: %Consume.cpp_overload_set.type = cpp_overload_set_value @Consume.cpp_overload_set [concrete = constants.%Consume.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %Consume__carbon_thunk.decl: %Consume__carbon_thunk.type = fn_decl @Consume__carbon_thunk [concrete = constants.%Consume__carbon_thunk] {
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.decl.2bdc3e.2: %initializer_list.initializer_list.type.9fcb7f.2 = fn_decl @initializer_list.initializer_list.loc10 [concrete = constants.%initializer_list.initializer_list.643507.2] {
|
||||
// CHECK:STDOUT: %_.patt: %pattern_type.5d8 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: %_.param_patt: %pattern_type.5d8 = value_param_pattern %_.patt, call_param0 [concrete]
|
||||
// CHECK:STDOUT: %return.patt: %pattern_type.22f = return_slot_pattern [concrete]
|
||||
// CHECK:STDOUT: %return.param_patt: %pattern_type.22f = out_param_pattern %return.patt, call_param1 [concrete]
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: %.loc10: form = init_form constants.%initializer_list, call_param1 [concrete = constants.%.cec]
|
||||
// CHECK:STDOUT: %_.param: %array_type = value_param call_param0
|
||||
// CHECK:STDOUT: %_: %array_type = value_binding _, %_.param
|
||||
// CHECK:STDOUT: %return.param: ref %initializer_list = out_param call_param1
|
||||
// CHECK:STDOUT: %return: ref %initializer_list = return_slot %return.param
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %InitListConstructor.decl: type = class_decl @InitListConstructor [concrete = constants.%InitListConstructor] {} {}
|
||||
// CHECK:STDOUT: %InitListConstructor__carbon_thunk.decl: %InitListConstructor__carbon_thunk.type = fn_decl @InitListConstructor__carbon_thunk [concrete = constants.%InitListConstructor__carbon_thunk] {
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.decl.2bdc3e.3: %initializer_list.initializer_list.type.9fcb7f.3 = fn_decl @initializer_list.initializer_list.loc12 [concrete = constants.%initializer_list.initializer_list.643507.3] {
|
||||
// CHECK:STDOUT: %_.patt: %pattern_type.5d8 = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: %_.param_patt: %pattern_type.5d8 = value_param_pattern %_.patt, call_param0 [concrete]
|
||||
// CHECK:STDOUT: %return.patt: %pattern_type.22f = return_slot_pattern [concrete]
|
||||
// CHECK:STDOUT: %return.param_patt: %pattern_type.22f = out_param_pattern %return.patt, call_param1 [concrete]
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: %.loc12: form = init_form constants.%initializer_list, call_param1 [concrete = constants.%.cec]
|
||||
// CHECK:STDOUT: %_.param: %array_type = value_param call_param0
|
||||
// CHECK:STDOUT: %_: %array_type = value_binding _, %_.param
|
||||
// CHECK:STDOUT: %return.param: ref %initializer_list = out_param call_param1
|
||||
// CHECK:STDOUT: %return: ref %initializer_list = return_slot %return.param
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %_.patt.loc8: %pattern_type.22f = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %int_1.loc8_43: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %int_2.loc8_46: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
|
||||
// CHECK:STDOUT: %int_3.loc8_49: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
|
||||
// CHECK:STDOUT: %.loc8_50.1: %tuple.type = tuple_literal (%int_1.loc8_43, %int_2.loc8_46, %int_3.loc8_49) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: %int_3.loc8_50: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
|
||||
// CHECK:STDOUT: %array_type.loc8: type = array_type %int_3.loc8_50, %i32.1 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: %.loc8_50.2: ref %initializer_list = temporary_storage
|
||||
// CHECK:STDOUT: %impl.elem0.loc8_50.1: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc8_50.1: <bound method> = bound_method %int_1.loc8_43, %impl.elem0.loc8_50.1 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.215]
|
||||
// CHECK:STDOUT: %specific_fn.loc8_50.1: <specific function> = specific_function %impl.elem0.loc8_50.1, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc8_50.2: <bound method> = bound_method %int_1.loc8_43, %specific_fn.loc8_50.1 [concrete = constants.%bound_method.38b]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc8_50.1: init %i32 = call %bound_method.loc8_50.2(%int_1.loc8_43) [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %.loc8_50.3: init %i32 = converted %int_1.loc8_43, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc8_50.1 [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %.loc8_50.4: ref %array_type = temporary_storage
|
||||
// CHECK:STDOUT: %int_0.loc8: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
|
||||
// CHECK:STDOUT: %.loc8_50.5: ref %i32 = array_index %.loc8_50.4, %int_0.loc8
|
||||
// CHECK:STDOUT: %.loc8_50.6: init %i32 to %.loc8_50.5 = initialize_from %.loc8_50.3 [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %impl.elem0.loc8_50.2: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc8_50.3: <bound method> = bound_method %int_2.loc8_46, %impl.elem0.loc8_50.2 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.4e5]
|
||||
// CHECK:STDOUT: %specific_fn.loc8_50.2: <specific function> = specific_function %impl.elem0.loc8_50.2, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc8_50.4: <bound method> = bound_method %int_2.loc8_46, %specific_fn.loc8_50.2 [concrete = constants.%bound_method.646]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc8_50.2: init %i32 = call %bound_method.loc8_50.4(%int_2.loc8_46) [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %.loc8_50.7: init %i32 = converted %int_2.loc8_46, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc8_50.2 [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %int_1.loc8_50: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %.loc8_50.8: ref %i32 = array_index %.loc8_50.4, %int_1.loc8_50
|
||||
// CHECK:STDOUT: %.loc8_50.9: init %i32 to %.loc8_50.8 = initialize_from %.loc8_50.7 [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %impl.elem0.loc8_50.3: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc8_50.5: <bound method> = bound_method %int_3.loc8_49, %impl.elem0.loc8_50.3 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.061]
|
||||
// CHECK:STDOUT: %specific_fn.loc8_50.3: <specific function> = specific_function %impl.elem0.loc8_50.3, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc8_50.6: <bound method> = bound_method %int_3.loc8_49, %specific_fn.loc8_50.3 [concrete = constants.%bound_method.fa7]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc8_50.3: init %i32 = call %bound_method.loc8_50.6(%int_3.loc8_49) [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %.loc8_50.10: init %i32 = converted %int_3.loc8_49, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc8_50.3 [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %int_2.loc8_50: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
|
||||
// CHECK:STDOUT: %.loc8_50.11: ref %i32 = array_index %.loc8_50.4, %int_2.loc8_50
|
||||
// CHECK:STDOUT: %.loc8_50.12: init %i32 to %.loc8_50.11 = initialize_from %.loc8_50.10 [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %.loc8_50.13: init %array_type to %.loc8_50.4 = array_init (%.loc8_50.6, %.loc8_50.9, %.loc8_50.12) [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc8_50.14: init %array_type = converted %.loc8_50.1, %.loc8_50.13 [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc8_50.15: ref %array_type = temporary %.loc8_50.4, %.loc8_50.14
|
||||
// CHECK:STDOUT: %.loc8_50.16: %array_type = acquire_value %.loc8_50.15
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.loc8: init %initializer_list to %.loc8_50.2 = call imports.%initializer_list.initializer_list.decl.2bdc3e.1(%.loc8_50.16)
|
||||
// CHECK:STDOUT: %.loc8_50.17: init %initializer_list = converted %.loc8_50.1, %initializer_list.initializer_list.call.loc8
|
||||
// CHECK:STDOUT: %.loc8_50.18: ref %initializer_list = temporary %.loc8_50.2, %.loc8_50.17
|
||||
// CHECK:STDOUT: %.loc8_50.19: %initializer_list = acquire_value %.loc8_50.18
|
||||
// CHECK:STDOUT: %_.loc8: %initializer_list = value_binding _, %.loc8_50.19
|
||||
// CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %Consume.ref: %Consume.cpp_overload_set.type = name_ref Consume, imports.%Consume.cpp_overload_set.value [concrete = constants.%Consume.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %int_1.loc10_16: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %int_2.loc10_19: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
|
||||
// CHECK:STDOUT: %int_3.loc10_22: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
|
||||
// CHECK:STDOUT: %.loc10_23.1: %tuple.type = tuple_literal (%int_1.loc10_16, %int_2.loc10_19, %int_3.loc10_22) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: %int_3.loc10_23: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
|
||||
// CHECK:STDOUT: %array_type.loc10: type = array_type %int_3.loc10_23, %i32.2 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: %.loc10_23.2: ref %initializer_list = temporary_storage
|
||||
// CHECK:STDOUT: %impl.elem0.loc10_23.1: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc10_23.1: <bound method> = bound_method %int_1.loc10_16, %impl.elem0.loc10_23.1 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.215]
|
||||
// CHECK:STDOUT: %specific_fn.loc10_23.1: <specific function> = specific_function %impl.elem0.loc10_23.1, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc10_23.2: <bound method> = bound_method %int_1.loc10_16, %specific_fn.loc10_23.1 [concrete = constants.%bound_method.38b]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc10_23.1: init %i32 = call %bound_method.loc10_23.2(%int_1.loc10_16) [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %.loc10_23.3: init %i32 = converted %int_1.loc10_16, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc10_23.1 [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %.loc10_23.4: ref %array_type = temporary_storage
|
||||
// CHECK:STDOUT: %int_0.loc10: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
|
||||
// CHECK:STDOUT: %.loc10_23.5: ref %i32 = array_index %.loc10_23.4, %int_0.loc10
|
||||
// CHECK:STDOUT: %.loc10_23.6: init %i32 to %.loc10_23.5 = initialize_from %.loc10_23.3 [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %impl.elem0.loc10_23.2: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc10_23.3: <bound method> = bound_method %int_2.loc10_19, %impl.elem0.loc10_23.2 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.4e5]
|
||||
// CHECK:STDOUT: %specific_fn.loc10_23.2: <specific function> = specific_function %impl.elem0.loc10_23.2, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc10_23.4: <bound method> = bound_method %int_2.loc10_19, %specific_fn.loc10_23.2 [concrete = constants.%bound_method.646]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc10_23.2: init %i32 = call %bound_method.loc10_23.4(%int_2.loc10_19) [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %.loc10_23.7: init %i32 = converted %int_2.loc10_19, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc10_23.2 [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %int_1.loc10_23: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %.loc10_23.8: ref %i32 = array_index %.loc10_23.4, %int_1.loc10_23
|
||||
// CHECK:STDOUT: %.loc10_23.9: init %i32 to %.loc10_23.8 = initialize_from %.loc10_23.7 [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %impl.elem0.loc10_23.3: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc10_23.5: <bound method> = bound_method %int_3.loc10_22, %impl.elem0.loc10_23.3 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.061]
|
||||
// CHECK:STDOUT: %specific_fn.loc10_23.3: <specific function> = specific_function %impl.elem0.loc10_23.3, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc10_23.6: <bound method> = bound_method %int_3.loc10_22, %specific_fn.loc10_23.3 [concrete = constants.%bound_method.fa7]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc10_23.3: init %i32 = call %bound_method.loc10_23.6(%int_3.loc10_22) [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %.loc10_23.10: init %i32 = converted %int_3.loc10_22, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc10_23.3 [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %int_2.loc10_23: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
|
||||
// CHECK:STDOUT: %.loc10_23.11: ref %i32 = array_index %.loc10_23.4, %int_2.loc10_23
|
||||
// CHECK:STDOUT: %.loc10_23.12: init %i32 to %.loc10_23.11 = initialize_from %.loc10_23.10 [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %.loc10_23.13: init %array_type to %.loc10_23.4 = array_init (%.loc10_23.6, %.loc10_23.9, %.loc10_23.12) [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc10_23.14: init %array_type = converted %.loc10_23.1, %.loc10_23.13 [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc10_23.15: ref %array_type = temporary %.loc10_23.4, %.loc10_23.14
|
||||
// CHECK:STDOUT: %.loc10_23.16: %array_type = acquire_value %.loc10_23.15
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.loc10: init %initializer_list to %.loc10_23.2 = call imports.%initializer_list.initializer_list.decl.2bdc3e.2(%.loc10_23.16)
|
||||
// CHECK:STDOUT: %.loc10_23.17: init %initializer_list = converted %.loc10_23.1, %initializer_list.initializer_list.call.loc10
|
||||
// CHECK:STDOUT: %.loc10_23.18: ref %initializer_list = temporary %.loc10_23.2, %.loc10_23.17
|
||||
// CHECK:STDOUT: %.loc10_23.19: %initializer_list = acquire_value %.loc10_23.18
|
||||
// CHECK:STDOUT: %.loc10_23.20: ref %initializer_list = value_as_ref %.loc10_23.19
|
||||
// CHECK:STDOUT: %addr.loc10: %ptr.82f = addr_of %.loc10_23.20
|
||||
// CHECK:STDOUT: %Consume__carbon_thunk.call: init %empty_tuple.type = call imports.%Consume__carbon_thunk.decl(%addr.loc10)
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
// CHECK:STDOUT: %_.patt.loc12: %pattern_type.92d = value_binding_pattern _ [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %int_1.loc12_37: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %int_2.loc12_40: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
|
||||
// CHECK:STDOUT: %int_3.loc12_43: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
|
||||
// CHECK:STDOUT: %.loc12_44.1: %tuple.type = tuple_literal (%int_1.loc12_37, %int_2.loc12_40, %int_3.loc12_43) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: %.loc12_13: type = splice_block %InitListConstructor.ref [concrete = constants.%InitListConstructor] {
|
||||
// CHECK:STDOUT: %Cpp.ref.loc12: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
||||
// CHECK:STDOUT: %InitListConstructor.ref: type = name_ref InitListConstructor, imports.%InitListConstructor.decl [concrete = constants.%InitListConstructor]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %.loc12_44.2: ref %InitListConstructor = temporary_storage
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: %int_3.loc12_44: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
|
||||
// CHECK:STDOUT: %array_type.loc12: type = array_type %int_3.loc12_44, %i32.3 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: %.loc12_44.3: ref %initializer_list = temporary_storage
|
||||
// CHECK:STDOUT: %impl.elem0.loc12_44.1: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc12_44.1: <bound method> = bound_method %int_1.loc12_37, %impl.elem0.loc12_44.1 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.215]
|
||||
// CHECK:STDOUT: %specific_fn.loc12_44.1: <specific function> = specific_function %impl.elem0.loc12_44.1, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc12_44.2: <bound method> = bound_method %int_1.loc12_37, %specific_fn.loc12_44.1 [concrete = constants.%bound_method.38b]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc12_44.1: init %i32 = call %bound_method.loc12_44.2(%int_1.loc12_37) [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %.loc12_44.4: init %i32 = converted %int_1.loc12_37, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc12_44.1 [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %.loc12_44.5: ref %array_type = temporary_storage
|
||||
// CHECK:STDOUT: %int_0.loc12: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
|
||||
// CHECK:STDOUT: %.loc12_44.6: ref %i32 = array_index %.loc12_44.5, %int_0.loc12
|
||||
// CHECK:STDOUT: %.loc12_44.7: init %i32 to %.loc12_44.6 = initialize_from %.loc12_44.4 [concrete = constants.%int_1.5d2]
|
||||
// CHECK:STDOUT: %impl.elem0.loc12_44.2: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc12_44.3: <bound method> = bound_method %int_2.loc12_40, %impl.elem0.loc12_44.2 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.4e5]
|
||||
// CHECK:STDOUT: %specific_fn.loc12_44.2: <specific function> = specific_function %impl.elem0.loc12_44.2, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc12_44.4: <bound method> = bound_method %int_2.loc12_40, %specific_fn.loc12_44.2 [concrete = constants.%bound_method.646]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc12_44.2: init %i32 = call %bound_method.loc12_44.4(%int_2.loc12_40) [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %.loc12_44.8: init %i32 = converted %int_2.loc12_40, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc12_44.2 [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %int_1.loc12_44: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
|
||||
// CHECK:STDOUT: %.loc12_44.9: ref %i32 = array_index %.loc12_44.5, %int_1.loc12_44
|
||||
// CHECK:STDOUT: %.loc12_44.10: init %i32 to %.loc12_44.9 = initialize_from %.loc12_44.8 [concrete = constants.%int_2.ef8]
|
||||
// CHECK:STDOUT: %impl.elem0.loc12_44.3: %.863 = impl_witness_access constants.%ImplicitAs.impl_witness.6bc, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0b5]
|
||||
// CHECK:STDOUT: %bound_method.loc12_44.5: <bound method> = bound_method %int_3.loc12_43, %impl.elem0.loc12_44.3 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.061]
|
||||
// CHECK:STDOUT: %specific_fn.loc12_44.3: <specific function> = specific_function %impl.elem0.loc12_44.3, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
|
||||
// CHECK:STDOUT: %bound_method.loc12_44.6: <bound method> = bound_method %int_3.loc12_43, %specific_fn.loc12_44.3 [concrete = constants.%bound_method.fa7]
|
||||
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc12_44.3: init %i32 = call %bound_method.loc12_44.6(%int_3.loc12_43) [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %.loc12_44.11: init %i32 = converted %int_3.loc12_43, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc12_44.3 [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %int_2.loc12_44: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
|
||||
// CHECK:STDOUT: %.loc12_44.12: ref %i32 = array_index %.loc12_44.5, %int_2.loc12_44
|
||||
// CHECK:STDOUT: %.loc12_44.13: init %i32 to %.loc12_44.12 = initialize_from %.loc12_44.11 [concrete = constants.%int_3.822]
|
||||
// CHECK:STDOUT: %.loc12_44.14: init %array_type to %.loc12_44.5 = array_init (%.loc12_44.7, %.loc12_44.10, %.loc12_44.13) [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc12_44.15: init %array_type = converted %.loc12_44.1, %.loc12_44.14 [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc12_44.16: ref %array_type = temporary %.loc12_44.5, %.loc12_44.15
|
||||
// CHECK:STDOUT: %.loc12_44.17: %array_type = acquire_value %.loc12_44.16
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.loc12: init %initializer_list to %.loc12_44.3 = call imports.%initializer_list.initializer_list.decl.2bdc3e.3(%.loc12_44.17)
|
||||
// CHECK:STDOUT: %.loc12_44.18: init %initializer_list = converted %.loc12_44.1, %initializer_list.initializer_list.call.loc12
|
||||
// CHECK:STDOUT: %.loc12_44.19: ref %initializer_list = temporary %.loc12_44.3, %.loc12_44.18
|
||||
// CHECK:STDOUT: %.loc12_44.20: %initializer_list = acquire_value %.loc12_44.19
|
||||
// CHECK:STDOUT: %.loc12_44.21: ref %initializer_list = value_as_ref %.loc12_44.20
|
||||
// CHECK:STDOUT: %addr.loc12_44.1: %ptr.82f = addr_of %.loc12_44.21
|
||||
// CHECK:STDOUT: %addr.loc12_44.2: %ptr.79d = addr_of %.loc12_44.2
|
||||
// CHECK:STDOUT: %InitListConstructor__carbon_thunk.call: init %empty_tuple.type = call imports.%InitListConstructor__carbon_thunk.decl(%addr.loc12_44.1, %addr.loc12_44.2)
|
||||
// CHECK:STDOUT: %.loc12_44.22: init %InitListConstructor to %.loc12_44.2 = in_place_init %InitListConstructor__carbon_thunk.call
|
||||
// CHECK:STDOUT: %.loc12_44.23: init %InitListConstructor = converted %.loc12_44.1, %.loc12_44.22
|
||||
// CHECK:STDOUT: %.loc12_44.24: ref %InitListConstructor = temporary %.loc12_44.2, %.loc12_44.23
|
||||
// CHECK:STDOUT: %.loc12_44.25: %InitListConstructor = acquire_value %.loc12_44.24
|
||||
// CHECK:STDOUT: %_.loc12: %InitListConstructor = value_binding _, %.loc12_44.25
|
||||
// CHECK:STDOUT: %InitListConstructor.cpp_destructor.bound: <bound method> = bound_method %.loc12_44.24, constants.%InitListConstructor.cpp_destructor
|
||||
// CHECK:STDOUT: %InitListConstructor.cpp_destructor.call: init %empty_tuple.type = call %InitListConstructor.cpp_destructor.bound(%.loc12_44.24)
|
||||
// CHECK:STDOUT: %initializer_list.cpp_destructor.bound.loc12: <bound method> = bound_method %.loc12_44.19, constants.%initializer_list.cpp_destructor
|
||||
// CHECK:STDOUT: %initializer_list.cpp_destructor.call.loc12: init %empty_tuple.type = call %initializer_list.cpp_destructor.bound.loc12(%.loc12_44.19)
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc12: <bound method> = bound_method %.loc12_44.16, constants.%DestroyOp.b0ebf8.6
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc12: init %empty_tuple.type = call %DestroyOp.bound.loc12(%.loc12_44.16)
|
||||
// CHECK:STDOUT: %initializer_list.cpp_destructor.bound.loc10: <bound method> = bound_method %.loc10_23.18, constants.%initializer_list.cpp_destructor
|
||||
// CHECK:STDOUT: %initializer_list.cpp_destructor.call.loc10: init %empty_tuple.type = call %initializer_list.cpp_destructor.bound.loc10(%.loc10_23.18)
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc10: <bound method> = bound_method %.loc10_23.15, constants.%DestroyOp.b0ebf8.6
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc10: init %empty_tuple.type = call %DestroyOp.bound.loc10(%.loc10_23.15)
|
||||
// CHECK:STDOUT: %initializer_list.cpp_destructor.bound.loc8: <bound method> = bound_method %.loc8_50.18, constants.%initializer_list.cpp_destructor
|
||||
// CHECK:STDOUT: %initializer_list.cpp_destructor.call.loc8: init %empty_tuple.type = call %initializer_list.cpp_destructor.bound.loc8(%.loc8_50.18)
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc8: <bound method> = bound_method %.loc8_50.15, constants.%DestroyOp.b0ebf8.6
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc8: init %empty_tuple.type = call %DestroyOp.bound.loc8(%.loc8_50.15)
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @initializer_list.initializer_list.loc8(%_.param: %array_type) -> out %return.param: %initializer_list = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @initializer_list.initializer_list.loc10(%_.param: %array_type) -> out %return.param: %initializer_list = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @initializer_list.initializer_list.loc12(%_.param: %array_type) -> out %return.param: %initializer_list = "cpp.std.initializer_list.make";
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @DestroyOp.loc12_44.1(%self.param: %InitListConstructor) = "no_op";
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @DestroyOp.loc12_44.2(%self.param: %initializer_list) = "no_op";
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @DestroyOp.loc12_44.3(%self.param: %array_type) = "no_op";
|
||||
// CHECK:STDOUT:
|
||||
@@ -240,6 +240,11 @@ auto GetFacetType(Context& context, const SemIR::FacetTypeInfo& info)
|
||||
context.facet_types().Add(info));
|
||||
}
|
||||
|
||||
auto GetFacetAccessType(Context& context, SemIR::InstId facet_value_inst_id)
|
||||
-> SemIR::TypeId {
|
||||
return GetTypeImpl<SemIR::FacetAccessType>(context, facet_value_inst_id);
|
||||
}
|
||||
|
||||
auto GetPointerType(Context& context, SemIR::TypeInstId pointee_type_id)
|
||||
-> SemIR::TypeId {
|
||||
return GetCompleteTypeImpl<SemIR::PointerType>(context, pointee_type_id);
|
||||
|
||||
@@ -104,6 +104,10 @@ auto GetNamedConstraintType(Context& context,
|
||||
auto GetFacetType(Context& context, const SemIR::FacetTypeInfo& info)
|
||||
-> SemIR::TypeId;
|
||||
|
||||
// Gets the type contained within the given facet value.
|
||||
auto GetFacetAccessType(Context& context, SemIR::InstId facet_value_inst_id)
|
||||
-> SemIR::TypeId;
|
||||
|
||||
// Returns a pointer type whose pointee type is `pointee_type_id`. The returned
|
||||
// type will be complete.
|
||||
auto GetPointerType(Context& context, SemIR::TypeInstId pointee_type_id)
|
||||
|
||||
@@ -39,6 +39,7 @@ cc_library(
|
||||
cc_library(
|
||||
name = "context",
|
||||
srcs = [
|
||||
"aggregate.cpp",
|
||||
"clang_global_decl.cpp",
|
||||
"clang_global_decl.h",
|
||||
"constant.cpp",
|
||||
@@ -55,6 +56,7 @@ cc_library(
|
||||
"handle*.cpp",
|
||||
]),
|
||||
hdrs = [
|
||||
"aggregate.h",
|
||||
"context.h",
|
||||
"file_context.h",
|
||||
"function_context.h",
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "toolchain/lower/aggregate.h"
|
||||
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "toolchain/sem_ir/expr_info.h"
|
||||
#include "toolchain/sem_ir/inst.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
|
||||
namespace Carbon::Lower {
|
||||
|
||||
static auto GetPointeeType(FunctionContext::TypeInFile type)
|
||||
-> FunctionContext::TypeInFile {
|
||||
return {.file = type.file,
|
||||
.type_id = type.file->GetPointeeType(type.type_id)};
|
||||
}
|
||||
|
||||
// Given an index within a SemIR aggregate type, returns the corresponding index
|
||||
// of the element within the LLVM type suitable for use with the getelementptr
|
||||
// instruction.
|
||||
static auto GetElementIndex(FunctionContext::TypeInFile type,
|
||||
SemIR::ElementIndex idx) -> unsigned int {
|
||||
auto type_inst = type.file->types().GetAsInst(type.type_id);
|
||||
|
||||
if (auto custom_layout_type = type_inst.TryAs<SemIR::CustomLayoutType>()) {
|
||||
// For custom layout types, we form an array of i8 as the LLVM type, so the
|
||||
// offset in the type is the getelementptr index.
|
||||
// TODO: This offset might not fit into an `unsigned int`.
|
||||
return type.file->custom_layouts().Get(
|
||||
custom_layout_type
|
||||
->layout_id)[SemIR::CustomLayoutId::FirstFieldIndex + idx.index];
|
||||
}
|
||||
|
||||
// For now, struct and tuple types map directly into LLVM struct types with
|
||||
// identical field numbering.
|
||||
CARBON_CHECK((type_inst.IsOneOf<SemIR::StructType, SemIR::TupleType>()),
|
||||
"Indexing unexpected aggregate type {0}", type_inst);
|
||||
return idx.index;
|
||||
}
|
||||
|
||||
auto GetAggregateElement(FunctionContext& context, SemIR::InstId aggr_inst_id,
|
||||
SemIR::ElementIndex idx, SemIR::InstId result_inst_id,
|
||||
llvm::Twine name) -> llvm::Value* {
|
||||
auto* aggr_value = context.GetValue(aggr_inst_id);
|
||||
|
||||
switch (SemIR::GetExprCategory(context.sem_ir(), aggr_inst_id)) {
|
||||
case SemIR::ExprCategory::RefTagged:
|
||||
case SemIR::ExprCategory::Error:
|
||||
case SemIR::ExprCategory::NotExpr:
|
||||
case SemIR::ExprCategory::Pattern:
|
||||
case SemIR::ExprCategory::Initializing:
|
||||
case SemIR::ExprCategory::Mixed:
|
||||
CARBON_FATAL(
|
||||
"Unexpected expression category for aggregate access into {0}",
|
||||
context.sem_ir().insts().Get(aggr_inst_id));
|
||||
|
||||
case SemIR::ExprCategory::Value: {
|
||||
auto aggr_type = context.GetTypeIdOfInst(aggr_inst_id);
|
||||
auto value_repr = context.GetValueRepr(aggr_type);
|
||||
CARBON_CHECK(
|
||||
value_repr.repr.aggregate_kind != SemIR::ValueRepr::NotAggregate,
|
||||
"aggregate type should have aggregate value representation");
|
||||
switch (value_repr.repr.kind) {
|
||||
case SemIR::ValueRepr::Unknown:
|
||||
CARBON_FATAL("Lowering access to incomplete aggregate type");
|
||||
case SemIR::ValueRepr::Dependent:
|
||||
CARBON_FATAL("Lowering access to dependent aggregate type");
|
||||
case SemIR::ValueRepr::None:
|
||||
return aggr_value;
|
||||
case SemIR::ValueRepr::Copy:
|
||||
// We are holding the values of the aggregate directly, elementwise.
|
||||
return context.builder().CreateExtractValue(
|
||||
aggr_value, GetElementIndex(value_repr.type(), idx), name);
|
||||
case SemIR::ValueRepr::Pointer: {
|
||||
// The value representation is a pointer to an aggregate that we want
|
||||
// to index into.
|
||||
auto value_rep_type = GetPointeeType(value_repr.type());
|
||||
auto* value_type = context.GetType(value_rep_type);
|
||||
auto* elem_ptr = context.builder().CreateStructGEP(
|
||||
value_type, aggr_value, GetElementIndex(value_rep_type, idx),
|
||||
name);
|
||||
|
||||
if (!value_repr.repr.elements_are_values()) {
|
||||
// `elem_ptr` points to an object representation, which is our
|
||||
// result.
|
||||
return elem_ptr;
|
||||
}
|
||||
|
||||
// `elem_ptr` points to a value representation. Load it.
|
||||
auto result_type = context.GetTypeIdOfInst(result_inst_id);
|
||||
auto result_value_type = context.GetValueRepr(result_type).type();
|
||||
return context.LoadObject(result_value_type, elem_ptr,
|
||||
name + ".load");
|
||||
}
|
||||
case SemIR::ValueRepr::Custom:
|
||||
CARBON_FATAL(
|
||||
"Aggregate should never have custom value representation");
|
||||
}
|
||||
}
|
||||
|
||||
case SemIR::ExprCategory::DurableRef:
|
||||
case SemIR::ExprCategory::EphemeralRef: {
|
||||
// Just locate the aggregate element.
|
||||
auto aggr_type = context.GetTypeIdOfInst(aggr_inst_id);
|
||||
auto object_repr = FunctionContext::TypeInFile{
|
||||
.file = aggr_type.file,
|
||||
.type_id = aggr_type.file->types().GetObjectRepr(aggr_type.type_id)};
|
||||
return context.builder().CreateStructGEP(
|
||||
context.GetType(object_repr), aggr_value,
|
||||
GetElementIndex(object_repr, idx), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto EmitAggregateValueRepr(FunctionContext& context,
|
||||
SemIR::InstId value_inst_id,
|
||||
SemIR::InstBlockId refs_id) -> llvm::Value* {
|
||||
auto type = context.GetTypeIdOfInst(value_inst_id);
|
||||
auto value_repr = context.GetValueRepr(type);
|
||||
auto value_type = value_repr.type();
|
||||
switch (value_repr.repr.kind) {
|
||||
case SemIR::ValueRepr::Unknown:
|
||||
CARBON_FATAL("Lowering value of incomplete aggregate type");
|
||||
|
||||
case SemIR::ValueRepr::Dependent:
|
||||
CARBON_FATAL("Lowering value of dependent aggregate type");
|
||||
|
||||
case SemIR::ValueRepr::None:
|
||||
// TODO: Add a helper to get a "no value representation" value.
|
||||
return llvm::PoisonValue::get(context.GetType(value_type));
|
||||
|
||||
case SemIR::ValueRepr::Copy: {
|
||||
auto refs = context.sem_ir().inst_blocks().Get(refs_id);
|
||||
CARBON_CHECK(
|
||||
refs.size() == 1,
|
||||
"Unexpected size for aggregate with by-copy value representation");
|
||||
// TODO: Remove the LLVM StructType wrapper in this case, so we don't
|
||||
// need this `insert_value` wrapping.
|
||||
return context.builder().CreateInsertValue(
|
||||
llvm::PoisonValue::get(context.GetType(value_type)),
|
||||
context.GetValue(refs[0]), {0});
|
||||
}
|
||||
|
||||
case SemIR::ValueRepr::Pointer: {
|
||||
auto* llvm_value_rep_type = context.GetType(GetPointeeType(value_type));
|
||||
|
||||
// Write the value representation to a local alloca so we can produce a
|
||||
// pointer to it as the value representation of the struct or tuple.
|
||||
auto* alloca = context.builder().CreateAlloca(llvm_value_rep_type);
|
||||
for (auto [i, ref_id] :
|
||||
llvm::enumerate(context.sem_ir().inst_blocks().Get(refs_id))) {
|
||||
context.StoreObject(
|
||||
context.GetValueRepr(context.GetTypeIdOfInst(ref_id)).type(),
|
||||
context.GetValue(ref_id),
|
||||
context.builder().CreateStructGEP(llvm_value_rep_type, alloca, i));
|
||||
}
|
||||
return alloca;
|
||||
}
|
||||
|
||||
case SemIR::ValueRepr::Custom:
|
||||
CARBON_FATAL("Aggregate should never have custom value representation");
|
||||
}
|
||||
}
|
||||
|
||||
auto EmitAggregateInitializer(FunctionContext& context,
|
||||
SemIR::InstId init_inst_id,
|
||||
SemIR::InstBlockId refs_id, llvm::Twine name)
|
||||
-> llvm::Value* {
|
||||
auto type = context.GetTypeIdOfInst(init_inst_id);
|
||||
auto* llvm_type = context.GetType(type);
|
||||
auto refs = context.sem_ir().inst_blocks().Get(refs_id);
|
||||
|
||||
switch (context.GetInitRepr(type).kind) {
|
||||
case SemIR::InitRepr::None: {
|
||||
// TODO: Add a helper to poison a value slot.
|
||||
return llvm::PoisonValue::get(llvm_type);
|
||||
}
|
||||
|
||||
case SemIR::InitRepr::InPlace: {
|
||||
// Finish initialization of constant fields. We will have skipped this
|
||||
// when emitting the initializers because they have constant values.
|
||||
//
|
||||
// TODO: This emits the initializers for constant fields after all
|
||||
// initialization of non-constant fields. This may be observable in some
|
||||
// ways such as under a debugger in a debug build. It would be preferable
|
||||
// to initialize the constant portions of the aggregate first, but this
|
||||
// will likely need a change to the SemIR representation.
|
||||
//
|
||||
// TODO: If most of the bytes of the result have known constant values,
|
||||
// it'd be nice to emit a memcpy from a constant followed by the
|
||||
// non-constant initialization.
|
||||
for (auto [i, ref_id] : llvm::enumerate(refs)) {
|
||||
if (context.sem_ir().constant_values().Get(ref_id).is_constant()) {
|
||||
auto dest_id =
|
||||
SemIR::FindReturnSlotArgForInitializer(context.sem_ir(), ref_id);
|
||||
auto src_id = ref_id;
|
||||
auto storage_type = context.GetTypeIdOfInst(dest_id);
|
||||
context.FinishInit(storage_type, dest_id, src_id);
|
||||
}
|
||||
}
|
||||
// TODO: Add a helper to poison a value slot.
|
||||
return llvm::PoisonValue::get(llvm_type);
|
||||
}
|
||||
|
||||
case SemIR::InitRepr::ByCopy: {
|
||||
auto refs = context.sem_ir().inst_blocks().Get(refs_id);
|
||||
CARBON_CHECK(
|
||||
refs.size() == 1,
|
||||
"Unexpected size for aggregate with by-copy value representation");
|
||||
// TODO: Remove the LLVM StructType wrapper in this case, so we don't
|
||||
// need this `insert_value` wrapping.
|
||||
return context.builder().CreateInsertValue(
|
||||
llvm::PoisonValue::get(llvm_type), context.GetValue(refs[0]), {0},
|
||||
name);
|
||||
}
|
||||
|
||||
case SemIR::InitRepr::Abstract:
|
||||
CARBON_FATAL("Lowering aggregate initialization of abstract type {0}",
|
||||
type.file->types().GetAsInst(type.type_id));
|
||||
|
||||
case SemIR::InitRepr::Incomplete:
|
||||
CARBON_FATAL("Lowering aggregate initialization of incomplete type {0}",
|
||||
type.file->types().GetAsInst(type.type_id));
|
||||
|
||||
case SemIR::InitRepr::Dependent:
|
||||
CARBON_FATAL("Lowering aggregate initialization of dependent type {0}",
|
||||
type.file->types().GetAsInst(type.type_id));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Carbon::Lower
|
||||
@@ -0,0 +1,36 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#ifndef CARBON_TOOLCHAIN_LOWER_AGGREGATE_H_
|
||||
#define CARBON_TOOLCHAIN_LOWER_AGGREGATE_H_
|
||||
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "toolchain/lower/function_context.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
|
||||
namespace Carbon::Lower {
|
||||
|
||||
// Extracts an element of an aggregate, such as a struct, tuple, or class, by
|
||||
// index. Depending on the expression category and value representation of the
|
||||
// aggregate input, this will either produce a value or a reference.
|
||||
auto GetAggregateElement(FunctionContext& context, SemIR::InstId aggr_inst_id,
|
||||
SemIR::ElementIndex idx, SemIR::InstId result_inst_id,
|
||||
llvm::Twine name) -> llvm::Value*;
|
||||
|
||||
// Emits the value representation for a struct or tuple whose elements are the
|
||||
// contents of `refs_id`.
|
||||
auto EmitAggregateValueRepr(FunctionContext& context,
|
||||
SemIR::InstId value_inst_id,
|
||||
SemIR::InstBlockId refs_id) -> llvm::Value*;
|
||||
|
||||
// Emits the initialization for a struct or tuple.
|
||||
auto EmitAggregateInitializer(FunctionContext& context,
|
||||
SemIR::InstId init_inst_id,
|
||||
SemIR::InstBlockId refs_id, llvm::Twine name)
|
||||
-> llvm::Value*;
|
||||
|
||||
} // namespace Carbon::Lower
|
||||
|
||||
#endif // CARBON_TOOLCHAIN_LOWER_AGGREGATE_H_
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "toolchain/lower/aggregate.h"
|
||||
#include "toolchain/lower/function_context.h"
|
||||
#include "toolchain/sem_ir/expr_info.h"
|
||||
#include "toolchain/sem_ir/file.h"
|
||||
@@ -21,114 +22,6 @@ auto HandleInst(FunctionContext& /*context*/, SemIR::InstId /*inst_id*/,
|
||||
// No action to perform.
|
||||
}
|
||||
|
||||
static auto GetPointeeType(FunctionContext::TypeInFile type)
|
||||
-> FunctionContext::TypeInFile {
|
||||
return {.file = type.file,
|
||||
.type_id = type.file->GetPointeeType(type.type_id)};
|
||||
}
|
||||
|
||||
// Given an index within a SemIR aggregate type, returns the corresponding index
|
||||
// of the element within the LLVM type suitable for use with the getelementptr
|
||||
// instruction.
|
||||
static auto GetElementIndex(FunctionContext::TypeInFile type,
|
||||
SemIR::ElementIndex idx) -> unsigned int {
|
||||
auto type_inst = type.file->types().GetAsInst(type.type_id);
|
||||
|
||||
if (auto custom_layout_type = type_inst.TryAs<SemIR::CustomLayoutType>()) {
|
||||
// For custom layout types, we form an array of i8 as the LLVM type, so the
|
||||
// offset in the type is the getelementptr index.
|
||||
// TODO: This offset might not fit into an `unsigned int`.
|
||||
return type.file->custom_layouts().Get(
|
||||
custom_layout_type
|
||||
->layout_id)[SemIR::CustomLayoutId::FirstFieldIndex + idx.index];
|
||||
}
|
||||
|
||||
// For now, struct and tuple types map directly into LLVM struct types with
|
||||
// identical field numbering.
|
||||
CARBON_CHECK((type_inst.IsOneOf<SemIR::StructType, SemIR::TupleType>()),
|
||||
"Indexing unexpected aggregate type {0}", type_inst);
|
||||
return idx.index;
|
||||
}
|
||||
|
||||
// Extracts an element of an aggregate, such as a struct, tuple, or class, by
|
||||
// index. Depending on the expression category and value representation of the
|
||||
// aggregate input, this will either produce a value or a reference.
|
||||
static auto GetAggregateElement(FunctionContext& context,
|
||||
SemIR::InstId aggr_inst_id,
|
||||
SemIR::ElementIndex idx,
|
||||
SemIR::InstId result_inst_id, llvm::Twine name)
|
||||
-> llvm::Value* {
|
||||
auto* aggr_value = context.GetValue(aggr_inst_id);
|
||||
|
||||
switch (SemIR::GetExprCategory(context.sem_ir(), aggr_inst_id)) {
|
||||
case SemIR::ExprCategory::RefTagged:
|
||||
case SemIR::ExprCategory::Error:
|
||||
case SemIR::ExprCategory::NotExpr:
|
||||
case SemIR::ExprCategory::Pattern:
|
||||
case SemIR::ExprCategory::Initializing:
|
||||
case SemIR::ExprCategory::Mixed:
|
||||
CARBON_FATAL(
|
||||
"Unexpected expression category for aggregate access into {0}",
|
||||
context.sem_ir().insts().Get(aggr_inst_id));
|
||||
|
||||
case SemIR::ExprCategory::Value: {
|
||||
auto aggr_type = context.GetTypeIdOfInst(aggr_inst_id);
|
||||
auto value_repr = context.GetValueRepr(aggr_type);
|
||||
CARBON_CHECK(
|
||||
value_repr.repr.aggregate_kind != SemIR::ValueRepr::NotAggregate,
|
||||
"aggregate type should have aggregate value representation");
|
||||
switch (value_repr.repr.kind) {
|
||||
case SemIR::ValueRepr::Unknown:
|
||||
CARBON_FATAL("Lowering access to incomplete aggregate type");
|
||||
case SemIR::ValueRepr::Dependent:
|
||||
CARBON_FATAL("Lowering access to dependent aggregate type");
|
||||
case SemIR::ValueRepr::None:
|
||||
return aggr_value;
|
||||
case SemIR::ValueRepr::Copy:
|
||||
// We are holding the values of the aggregate directly, elementwise.
|
||||
return context.builder().CreateExtractValue(
|
||||
aggr_value, GetElementIndex(value_repr.type(), idx), name);
|
||||
case SemIR::ValueRepr::Pointer: {
|
||||
// The value representation is a pointer to an aggregate that we want
|
||||
// to index into.
|
||||
auto value_rep_type = GetPointeeType(value_repr.type());
|
||||
auto* value_type = context.GetType(value_rep_type);
|
||||
auto* elem_ptr = context.builder().CreateStructGEP(
|
||||
value_type, aggr_value, GetElementIndex(value_rep_type, idx),
|
||||
name);
|
||||
|
||||
if (!value_repr.repr.elements_are_values()) {
|
||||
// `elem_ptr` points to an object representation, which is our
|
||||
// result.
|
||||
return elem_ptr;
|
||||
}
|
||||
|
||||
// `elem_ptr` points to a value representation. Load it.
|
||||
auto result_type = context.GetTypeIdOfInst(result_inst_id);
|
||||
auto result_value_type = context.GetValueRepr(result_type).type();
|
||||
return context.LoadObject(result_value_type, elem_ptr,
|
||||
name + ".load");
|
||||
}
|
||||
case SemIR::ValueRepr::Custom:
|
||||
CARBON_FATAL(
|
||||
"Aggregate should never have custom value representation");
|
||||
}
|
||||
}
|
||||
|
||||
case SemIR::ExprCategory::DurableRef:
|
||||
case SemIR::ExprCategory::EphemeralRef: {
|
||||
// Just locate the aggregate element.
|
||||
auto aggr_type = context.GetTypeIdOfInst(aggr_inst_id);
|
||||
auto object_repr = FunctionContext::TypeInFile{
|
||||
.file = aggr_type.file,
|
||||
.type_id = aggr_type.file->types().GetObjectRepr(aggr_type.type_id)};
|
||||
return context.builder().CreateStructGEP(
|
||||
context.GetType(object_repr), aggr_value,
|
||||
GetElementIndex(object_repr, idx), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static auto GetStructFieldName(FunctionContext::TypeInFile struct_type,
|
||||
SemIR::ElementIndex index) -> llvm::StringRef {
|
||||
auto struct_type_inst = struct_type.file->types().GetAs<SemIR::AnyStructType>(
|
||||
@@ -155,72 +48,6 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
|
||||
GetStructFieldName(object_repr, inst.index)));
|
||||
}
|
||||
|
||||
static auto EmitAggregateInitializer(FunctionContext& context,
|
||||
SemIR::InstId init_inst_id,
|
||||
SemIR::InstBlockId refs_id,
|
||||
llvm::Twine name) -> llvm::Value* {
|
||||
auto type = context.GetTypeIdOfInst(init_inst_id);
|
||||
auto* llvm_type = context.GetType(type);
|
||||
auto refs = context.sem_ir().inst_blocks().Get(refs_id);
|
||||
|
||||
switch (context.GetInitRepr(type).kind) {
|
||||
case SemIR::InitRepr::None: {
|
||||
// TODO: Add a helper to poison a value slot.
|
||||
return llvm::PoisonValue::get(llvm_type);
|
||||
}
|
||||
|
||||
case SemIR::InitRepr::InPlace: {
|
||||
// Finish initialization of constant fields. We will have skipped this
|
||||
// when emitting the initializers because they have constant values.
|
||||
//
|
||||
// TODO: This emits the initializers for constant fields after all
|
||||
// initialization of non-constant fields. This may be observable in some
|
||||
// ways such as under a debugger in a debug build. It would be preferable
|
||||
// to initialize the constant portions of the aggregate first, but this
|
||||
// will likely need a change to the SemIR representation.
|
||||
//
|
||||
// TODO: If most of the bytes of the result have known constant values,
|
||||
// it'd be nice to emit a memcpy from a constant followed by the
|
||||
// non-constant initialization.
|
||||
for (auto [i, ref_id] : llvm::enumerate(refs)) {
|
||||
if (context.sem_ir().constant_values().Get(ref_id).is_constant()) {
|
||||
auto dest_id =
|
||||
SemIR::FindReturnSlotArgForInitializer(context.sem_ir(), ref_id);
|
||||
auto src_id = ref_id;
|
||||
auto storage_type = context.GetTypeIdOfInst(dest_id);
|
||||
context.FinishInit(storage_type, dest_id, src_id);
|
||||
}
|
||||
}
|
||||
// TODO: Add a helper to poison a value slot.
|
||||
return llvm::PoisonValue::get(llvm_type);
|
||||
}
|
||||
|
||||
case SemIR::InitRepr::ByCopy: {
|
||||
auto refs = context.sem_ir().inst_blocks().Get(refs_id);
|
||||
CARBON_CHECK(
|
||||
refs.size() == 1,
|
||||
"Unexpected size for aggregate with by-copy value representation");
|
||||
// TODO: Remove the LLVM StructType wrapper in this case, so we don't
|
||||
// need this `insert_value` wrapping.
|
||||
return context.builder().CreateInsertValue(
|
||||
llvm::PoisonValue::get(llvm_type), context.GetValue(refs[0]), {0},
|
||||
name);
|
||||
}
|
||||
|
||||
case SemIR::InitRepr::Abstract:
|
||||
CARBON_FATAL("Lowering aggregate initialization of abstract type {0}",
|
||||
type.file->types().GetAsInst(type.type_id));
|
||||
|
||||
case SemIR::InitRepr::Incomplete:
|
||||
CARBON_FATAL("Lowering aggregate initialization of incomplete type {0}",
|
||||
type.file->types().GetAsInst(type.type_id));
|
||||
|
||||
case SemIR::InitRepr::Dependent:
|
||||
CARBON_FATAL("Lowering aggregate initialization of dependent type {0}",
|
||||
type.file->types().GetAsInst(type.type_id));
|
||||
}
|
||||
}
|
||||
|
||||
auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
|
||||
SemIR::ClassInit inst) -> void {
|
||||
context.SetLocal(inst_id,
|
||||
@@ -242,58 +69,6 @@ auto HandleInst(FunctionContext& /*context*/, SemIR::InstId /*inst_id*/,
|
||||
// if its value is needed.
|
||||
}
|
||||
|
||||
// Emits the value representation for a struct or tuple whose elements are the
|
||||
// contents of `refs_id`.
|
||||
static auto EmitAggregateValueRepr(FunctionContext& context,
|
||||
SemIR::InstId value_inst_id,
|
||||
SemIR::InstBlockId refs_id) -> llvm::Value* {
|
||||
auto type = context.GetTypeIdOfInst(value_inst_id);
|
||||
auto value_repr = context.GetValueRepr(type);
|
||||
auto value_type = value_repr.type();
|
||||
switch (value_repr.repr.kind) {
|
||||
case SemIR::ValueRepr::Unknown:
|
||||
CARBON_FATAL("Lowering value of incomplete aggregate type");
|
||||
|
||||
case SemIR::ValueRepr::Dependent:
|
||||
CARBON_FATAL("Lowering value of dependent aggregate type");
|
||||
|
||||
case SemIR::ValueRepr::None:
|
||||
// TODO: Add a helper to get a "no value representation" value.
|
||||
return llvm::PoisonValue::get(context.GetType(value_type));
|
||||
|
||||
case SemIR::ValueRepr::Copy: {
|
||||
auto refs = context.sem_ir().inst_blocks().Get(refs_id);
|
||||
CARBON_CHECK(
|
||||
refs.size() == 1,
|
||||
"Unexpected size for aggregate with by-copy value representation");
|
||||
// TODO: Remove the LLVM StructType wrapper in this case, so we don't
|
||||
// need this `insert_value` wrapping.
|
||||
return context.builder().CreateInsertValue(
|
||||
llvm::PoisonValue::get(context.GetType(value_type)),
|
||||
context.GetValue(refs[0]), {0});
|
||||
}
|
||||
|
||||
case SemIR::ValueRepr::Pointer: {
|
||||
auto* llvm_value_rep_type = context.GetType(GetPointeeType(value_type));
|
||||
|
||||
// Write the value representation to a local alloca so we can produce a
|
||||
// pointer to it as the value representation of the struct or tuple.
|
||||
auto* alloca = context.builder().CreateAlloca(llvm_value_rep_type);
|
||||
for (auto [i, ref_id] :
|
||||
llvm::enumerate(context.sem_ir().inst_blocks().Get(refs_id))) {
|
||||
context.StoreObject(
|
||||
context.GetValueRepr(context.GetTypeIdOfInst(ref_id)).type(),
|
||||
context.GetValue(ref_id),
|
||||
context.builder().CreateStructGEP(llvm_value_rep_type, alloca, i));
|
||||
}
|
||||
return alloca;
|
||||
}
|
||||
|
||||
case SemIR::ValueRepr::Custom:
|
||||
CARBON_FATAL("Aggregate should never have custom value representation");
|
||||
}
|
||||
}
|
||||
|
||||
auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
|
||||
SemIR::StructInit inst) -> void {
|
||||
context.SetLocal(inst_id,
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
#include "common/raw_string_ostream.h"
|
||||
#include "llvm/IR/Type.h"
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "toolchain/lower/aggregate.h"
|
||||
#include "toolchain/lower/function_context.h"
|
||||
#include "toolchain/sem_ir/builtin_function_kind.h"
|
||||
#include "toolchain/sem_ir/cpp_initializer_list.h"
|
||||
#include "toolchain/sem_ir/function.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
@@ -257,6 +259,61 @@ static auto CreateBinaryOperatorForBuiltin(
|
||||
}
|
||||
}
|
||||
|
||||
// Handles a call to `cpp.std.initializer_list.make`.
|
||||
static auto StoreArrayAsStdInitializerList(FunctionContext& context,
|
||||
SemIR::InstId init_list_id,
|
||||
SemIR::InstId array_inst_id)
|
||||
-> void {
|
||||
// Extract the bound from the array type.
|
||||
auto [array_type_file, array_type_id] =
|
||||
context.GetTypeIdOfInst(array_inst_id);
|
||||
auto array_type = array_type_file->types().GetAs<SemIR::ArrayType>(
|
||||
array_type_file->types().GetObjectRepr(array_type_id));
|
||||
auto array_bound = array_type_file->GetArrayBoundValue(array_type.bound_id);
|
||||
CARBON_CHECK(array_bound, "Array type with non-constant bound");
|
||||
|
||||
// Store the array pointer in the first element of the initializer list.
|
||||
auto* array_ptr = context.GetValue(array_inst_id);
|
||||
auto* begin_ptr =
|
||||
GetAggregateElement(context, init_list_id, SemIR::ElementIndex(0),
|
||||
SemIR::InstId::None, "init_list.begin");
|
||||
context.builder().CreateStore(array_ptr, begin_ptr);
|
||||
|
||||
// Store the end or size to the second element, depending on the layout.
|
||||
auto init_list_type = context.GetTypeIdOfInst(init_list_id);
|
||||
switch (auto layout = SemIR::GetStdInitializerListLayout(
|
||||
*init_list_type.file, init_list_type.type_id);
|
||||
layout.kind) {
|
||||
case SemIR::StdInitializerListLayout::None: {
|
||||
CARBON_FATAL("Unrecognized initializer list");
|
||||
break;
|
||||
}
|
||||
|
||||
case SemIR::StdInitializerListLayout::PointerPointer: {
|
||||
auto* end_ptr =
|
||||
GetAggregateElement(context, init_list_id, SemIR::ElementIndex(1),
|
||||
SemIR::InstId::None, "init_list.end");
|
||||
auto* array_end_ptr = context.builder().CreateConstInBoundsGEP1_32(
|
||||
context.GetTypeOfInst(array_inst_id), array_ptr, 1, "array.end");
|
||||
context.builder().CreateStore(array_end_ptr, end_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
case SemIR::StdInitializerListLayout::PointerInt: {
|
||||
auto* size_ptr =
|
||||
GetAggregateElement(context, init_list_id, SemIR::ElementIndex(1),
|
||||
SemIR::InstId::None, "init_list.size");
|
||||
context.builder().CreateStore(
|
||||
llvm::ConstantInt::get(
|
||||
context.GetType(FunctionContext::TypeInFile{
|
||||
.file = &context.sem_ir(), .type_id = layout.size_type_id}),
|
||||
*array_bound),
|
||||
size_ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handles a call to a builtin function.
|
||||
static auto HandleBuiltinCall(FunctionContext& context, SemIR::InstId inst_id,
|
||||
SemIR::BuiltinFunctionKind builtin_kind,
|
||||
@@ -511,6 +568,15 @@ static auto HandleBuiltinCall(FunctionContext& context, SemIR::InstId inst_id,
|
||||
context.SetLocal(inst_id, context.GetValue(arg_ids[0]));
|
||||
return;
|
||||
}
|
||||
|
||||
case SemIR::BuiltinFunctionKind::CppStdInitializerListMake: {
|
||||
// TODO: We assume that the initializer list uses an in-place initializing
|
||||
// representation, but we don't enforce that when type-checking the
|
||||
// builtin.
|
||||
StoreArrayAsStdInitializerList(context, arg_ids[1], arg_ids[0]);
|
||||
context.SetLocal(inst_id, context.GetValue(arg_ids[1]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CARBON_FATAL("Unsupported builtin call.");
|
||||
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/builtins/cpp.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/builtins/cpp.carbon
|
||||
|
||||
// --- std_initializer_list_make.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp inline '''
|
||||
template<typename T>
|
||||
struct InitializerListPointerPointer {
|
||||
T* begin;
|
||||
T* end;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct InitializerListPointerSize {
|
||||
T* begin;
|
||||
decltype(sizeof(T)) size;
|
||||
};
|
||||
''';
|
||||
|
||||
fn MakePointerPointer(a: array(i32, 4)) -> Cpp.InitializerListPointerPointer(i32) = "cpp.std.initializer_list.make";
|
||||
fn MakePointerSize(a: array(i32, 4)) -> Cpp.InitializerListPointerSize(i32) = "cpp.std.initializer_list.make";
|
||||
|
||||
fn TakePointerPointer(a: Cpp.InitializerListPointerPointer(i32));
|
||||
fn TakePointerSize(a: Cpp.InitializerListPointerSize(i32));
|
||||
|
||||
fn Test() {
|
||||
TakePointerPointer(MakePointerPointer((1, 2, 3, 4)));
|
||||
TakePointerSize(MakePointerSize((1, 2, 3, 4)));
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: ; ModuleID = 'std_initializer_list_make.carbon'
|
||||
// CHECK:STDOUT: source_filename = "std_initializer_list_make.carbon"
|
||||
// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
|
||||
// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: @array.loc25_52.16 = internal constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: declare void @_CTakePointerPointer.Main(ptr)
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: declare void @_CTakePointerSize.Main(ptr)
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define void @_CTest.Main() #0 !dbg !12 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %.loc25_53.1.temp = alloca [16 x i8], align 1, !dbg !15
|
||||
// CHECK:STDOUT: %.loc25_52.3.temp = alloca [4 x i32], align 4, !dbg !16
|
||||
// CHECK:STDOUT: %.loc26_47.1.temp = alloca [16 x i8], align 1, !dbg !17
|
||||
// CHECK:STDOUT: %.loc26_46.3.temp = alloca [4 x i32], align 4, !dbg !18
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc25_53.1.temp), !dbg !15
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc25_52.3.temp), !dbg !16
|
||||
// CHECK:STDOUT: %.loc25_52.4.array.index = getelementptr inbounds [4 x i32], ptr %.loc25_52.3.temp, i32 0, i64 0, !dbg !16
|
||||
// CHECK:STDOUT: %.loc25_52.7.array.index = getelementptr inbounds [4 x i32], ptr %.loc25_52.3.temp, i32 0, i64 1, !dbg !16
|
||||
// CHECK:STDOUT: %.loc25_52.10.array.index = getelementptr inbounds [4 x i32], ptr %.loc25_52.3.temp, i32 0, i64 2, !dbg !16
|
||||
// CHECK:STDOUT: %.loc25_52.13.array.index = getelementptr inbounds [4 x i32], ptr %.loc25_52.3.temp, i32 0, i64 3, !dbg !16
|
||||
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %.loc25_52.3.temp, ptr align 4 @array.loc25_52.16, i64 16, i1 false), !dbg !16
|
||||
// CHECK:STDOUT: %MakePointerPointer.call.init_list.begin = getelementptr inbounds nuw [16 x i8], ptr %.loc25_53.1.temp, i32 0, i32 0, !dbg !15
|
||||
// CHECK:STDOUT: store ptr %.loc25_52.3.temp, ptr %MakePointerPointer.call.init_list.begin, align 8, !dbg !15
|
||||
// CHECK:STDOUT: %MakePointerPointer.call.init_list.end = getelementptr inbounds nuw [16 x i8], ptr %.loc25_53.1.temp, i32 0, i32 8, !dbg !15
|
||||
// CHECK:STDOUT: %MakePointerPointer.call.array.end = getelementptr inbounds [4 x i32], ptr %.loc25_52.3.temp, i32 1, !dbg !15
|
||||
// CHECK:STDOUT: store ptr %MakePointerPointer.call.array.end, ptr %MakePointerPointer.call.init_list.end, align 8, !dbg !15
|
||||
// CHECK:STDOUT: call void @_CTakePointerPointer.Main(ptr %.loc25_53.1.temp), !dbg !19
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc26_47.1.temp), !dbg !17
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc26_46.3.temp), !dbg !18
|
||||
// CHECK:STDOUT: %.loc26_46.4.array.index = getelementptr inbounds [4 x i32], ptr %.loc26_46.3.temp, i32 0, i64 0, !dbg !18
|
||||
// CHECK:STDOUT: %.loc26_46.7.array.index = getelementptr inbounds [4 x i32], ptr %.loc26_46.3.temp, i32 0, i64 1, !dbg !18
|
||||
// CHECK:STDOUT: %.loc26_46.10.array.index = getelementptr inbounds [4 x i32], ptr %.loc26_46.3.temp, i32 0, i64 2, !dbg !18
|
||||
// CHECK:STDOUT: %.loc26_46.13.array.index = getelementptr inbounds [4 x i32], ptr %.loc26_46.3.temp, i32 0, i64 3, !dbg !18
|
||||
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %.loc26_46.3.temp, ptr align 4 @array.loc25_52.16, i64 16, i1 false), !dbg !18
|
||||
// CHECK:STDOUT: %MakePointerSize.call.init_list.begin = getelementptr inbounds nuw [16 x i8], ptr %.loc26_47.1.temp, i32 0, i32 0, !dbg !17
|
||||
// CHECK:STDOUT: store ptr %.loc26_46.3.temp, ptr %MakePointerSize.call.init_list.begin, align 8, !dbg !17
|
||||
// CHECK:STDOUT: %MakePointerSize.call.init_list.size = getelementptr inbounds nuw [16 x i8], ptr %.loc26_47.1.temp, i32 0, i32 8, !dbg !17
|
||||
// CHECK:STDOUT: store i64 4, ptr %MakePointerSize.call.init_list.size, align 8, !dbg !17
|
||||
// CHECK:STDOUT: call void @_CTakePointerSize.Main(ptr %.loc26_47.1.temp), !dbg !20
|
||||
// CHECK:STDOUT: ret void, !dbg !21
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; uselistorder directives
|
||||
// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 3, 2, 1, 0 }
|
||||
// CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 1, 0 }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: attributes #0 = { nounwind }
|
||||
// CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4, !5}
|
||||
// CHECK:STDOUT: !llvm.dbg.cu = !{!6}
|
||||
// CHECK:STDOUT: !llvm.errno.tbaa = !{!8}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
|
||||
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
|
||||
// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 2}
|
||||
// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
|
||||
// CHECK:STDOUT: !5 = !{i32 7, !"uwtable", i32 2}
|
||||
// CHECK:STDOUT: !6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !7, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
||||
// CHECK:STDOUT: !7 = !DIFile(filename: "std_initializer_list_make.carbon", directory: "")
|
||||
// CHECK:STDOUT: !8 = !{!9, !9, i64 0}
|
||||
// CHECK:STDOUT: !9 = !{!"int", !10, i64 0}
|
||||
// CHECK:STDOUT: !10 = !{!"omnipotent char", !11, i64 0}
|
||||
// CHECK:STDOUT: !11 = !{!"Simple C++ TBAA"}
|
||||
// CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Test", linkageName: "_CTest.Main", scope: null, file: !7, line: 24, type: !13, spFlags: DISPFlagDefinition, unit: !6)
|
||||
// CHECK:STDOUT: !13 = !DISubroutineType(types: !14)
|
||||
// CHECK:STDOUT: !14 = !{null}
|
||||
// CHECK:STDOUT: !15 = !DILocation(line: 25, column: 22, scope: !12)
|
||||
// CHECK:STDOUT: !16 = !DILocation(line: 25, column: 41, scope: !12)
|
||||
// CHECK:STDOUT: !17 = !DILocation(line: 26, column: 19, scope: !12)
|
||||
// CHECK:STDOUT: !18 = !DILocation(line: 26, column: 35, scope: !12)
|
||||
// CHECK:STDOUT: !19 = !DILocation(line: 25, column: 3, scope: !12)
|
||||
// CHECK:STDOUT: !20 = !DILocation(line: 26, column: 3, scope: !12)
|
||||
// CHECK:STDOUT: !21 = !DILocation(line: 24, column: 1, scope: !12)
|
||||
@@ -0,0 +1,516 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/interop/cpp/std_initializer_list.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/std_initializer_list.carbon
|
||||
|
||||
// --- initializer_list_pointer_pointer.h
|
||||
|
||||
namespace std {
|
||||
using size_t = decltype(sizeof(0));
|
||||
|
||||
template <typename T> class initializer_list {
|
||||
public:
|
||||
initializer_list() {}
|
||||
|
||||
private:
|
||||
T* begin_ = nullptr;
|
||||
T* end_ = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
struct vector_like {
|
||||
vector_like(std::initializer_list<int> list) {}
|
||||
~vector_like() {}
|
||||
};
|
||||
|
||||
// --- initializer_list_pointer_size.h
|
||||
|
||||
namespace std {
|
||||
using size_t = decltype(sizeof(0));
|
||||
|
||||
template <typename T> class initializer_list {
|
||||
public:
|
||||
initializer_list() {}
|
||||
|
||||
private:
|
||||
T* begin_ = nullptr;
|
||||
size_t size_ = 0;
|
||||
};
|
||||
}
|
||||
|
||||
struct vector_like {
|
||||
vector_like(std::initializer_list<int> list) {}
|
||||
~vector_like() {}
|
||||
};
|
||||
|
||||
// --- nontrivial_dtor.h
|
||||
|
||||
struct nontrivial_dtor {
|
||||
nontrivial_dtor() {}
|
||||
~nontrivial_dtor() {}
|
||||
};
|
||||
|
||||
// --- use_pointer_pointer.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "initializer_list_pointer_pointer.h";
|
||||
import Cpp library "nontrivial_dtor.h";
|
||||
|
||||
// TODO: When we support more precise modeling of temporary lifetimes, ensure
|
||||
// that this is called *before* the elements of the underlying array are
|
||||
// destroyed in the non-vector-like cases.
|
||||
fn WithinLifetime();
|
||||
|
||||
fn InitDirectly() {
|
||||
var _: Cpp.std.initializer_list(i32) = (1, 2, 3);
|
||||
WithinLifetime();
|
||||
}
|
||||
|
||||
fn InitVectorLike() {
|
||||
var _: Cpp.vector_like = (1, 2, 3);
|
||||
WithinLifetime();
|
||||
}
|
||||
|
||||
fn InitNontrivialDtor() {
|
||||
var _: Cpp.std.initializer_list(Cpp.nontrivial_dtor) = ((), (), ());
|
||||
WithinLifetime();
|
||||
}
|
||||
|
||||
// --- use_pointer_size.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "initializer_list_pointer_size.h";
|
||||
import Cpp library "nontrivial_dtor.h";
|
||||
|
||||
// TODO: When we support more precise modeling of temporary lifetimes, ensure
|
||||
// that this is called *before* the elements of the underlying array are
|
||||
// destroyed in the non-vector-like cases.
|
||||
fn WithinLifetime();
|
||||
|
||||
fn InitDirectly() {
|
||||
var _: Cpp.std.initializer_list(i32) = (1, 2, 3);
|
||||
WithinLifetime();
|
||||
}
|
||||
|
||||
fn InitVectorLike() {
|
||||
var _: Cpp.vector_like = (1, 2, 3);
|
||||
WithinLifetime();
|
||||
}
|
||||
|
||||
fn InitNontrivialDtor() {
|
||||
var _: Cpp.std.initializer_list(Cpp.nontrivial_dtor) = ((), (), ());
|
||||
WithinLifetime();
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: ; ModuleID = 'use_pointer_pointer.carbon'
|
||||
// CHECK:STDOUT: source_filename = "use_pointer_pointer.carbon"
|
||||
// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
|
||||
// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: %"class.std::initializer_list" = type { ptr, ptr }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: $_ZN11vector_likeC2ESt16initializer_listIiE = comdat any
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: $_ZN15nontrivial_dtorC2Ev = comdat any
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: $_ZN11vector_likeD2Ev = comdat any
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: @array.loc13_50.13 = internal constant [3 x i32] [i32 1, i32 2, i32 3]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
|
||||
// CHECK:STDOUT: define dso_local void @_ZN11vector_likeC1ESt16initializer_listIiE.carbon_thunk(ptr noundef %list, ptr noundef %return) #0 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %list.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: %agg.tmp = alloca %"class.std::initializer_list", align 8
|
||||
// CHECK:STDOUT: store ptr %list, ptr %list.addr, align 8, !tbaa !12
|
||||
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !15
|
||||
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !15
|
||||
// CHECK:STDOUT: %1 = load ptr, ptr %list.addr, align 8, !tbaa !12
|
||||
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %agg.tmp, ptr align 8 %1, i64 16, i1 false), !tbaa.struct !17
|
||||
// CHECK:STDOUT: %2 = getelementptr inbounds nuw { ptr, ptr }, ptr %agg.tmp, i32 0, i32 0
|
||||
// CHECK:STDOUT: %3 = load ptr, ptr %2, align 8
|
||||
// CHECK:STDOUT: %4 = getelementptr inbounds nuw { ptr, ptr }, ptr %agg.tmp, i32 0, i32 1
|
||||
// CHECK:STDOUT: %5 = load ptr, ptr %4, align 8
|
||||
// CHECK:STDOUT: call void @_ZN11vector_likeC2ESt16initializer_listIiE(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr %3, ptr %5)
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #1
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: mustprogress nounwind uwtable
|
||||
// CHECK:STDOUT: define linkonce_odr dso_local void @_ZN11vector_likeC2ESt16initializer_listIiE(ptr noundef nonnull align 1 dereferenceable(1) %this, ptr %list.coerce0, ptr %list.coerce1) unnamed_addr #2 comdat align 2 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %list = alloca %"class.std::initializer_list", align 8
|
||||
// CHECK:STDOUT: %this.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: %0 = getelementptr inbounds nuw { ptr, ptr }, ptr %list, i32 0, i32 0
|
||||
// CHECK:STDOUT: store ptr %list.coerce0, ptr %0, align 8
|
||||
// CHECK:STDOUT: %1 = getelementptr inbounds nuw { ptr, ptr }, ptr %list, i32 0, i32 1
|
||||
// CHECK:STDOUT: store ptr %list.coerce1, ptr %1, align 8
|
||||
// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !15
|
||||
// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
|
||||
// CHECK:STDOUT: define dso_local void @_ZN15nontrivial_dtorC1Ev.carbon_thunk_tuple(ptr noundef %return) #0 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !20
|
||||
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !20
|
||||
// CHECK:STDOUT: call void @_ZN15nontrivial_dtorC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %0)
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: mustprogress nounwind uwtable
|
||||
// CHECK:STDOUT: define linkonce_odr dso_local void @_ZN15nontrivial_dtorC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %this) unnamed_addr #2 comdat align 2 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %this.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !20
|
||||
// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: declare void @_CWithinLifetime.Main()
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define void @_CInitDirectly.Main() #3 !dbg !22 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %_.var = alloca [16 x i8], align 1, !dbg !25
|
||||
// CHECK:STDOUT: %.loc13_50.3.temp = alloca [3 x i32], align 4, !dbg !26
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !25
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc13_50.3.temp), !dbg !26
|
||||
// CHECK:STDOUT: %.loc13_50.4.array.index = getelementptr inbounds [3 x i32], ptr %.loc13_50.3.temp, i32 0, i64 0, !dbg !26
|
||||
// CHECK:STDOUT: %.loc13_50.7.array.index = getelementptr inbounds [3 x i32], ptr %.loc13_50.3.temp, i32 0, i64 1, !dbg !26
|
||||
// CHECK:STDOUT: %.loc13_50.10.array.index = getelementptr inbounds [3 x i32], ptr %.loc13_50.3.temp, i32 0, i64 2, !dbg !26
|
||||
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %.loc13_50.3.temp, ptr align 4 @array.loc13_50.13, i64 12, i1 false), !dbg !26
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.begin = getelementptr inbounds nuw [16 x i8], ptr %_.var, i32 0, i32 0, !dbg !25
|
||||
// CHECK:STDOUT: store ptr %.loc13_50.3.temp, ptr %initializer_list.initializer_list.call.init_list.begin, align 8, !dbg !25
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.end = getelementptr inbounds nuw [16 x i8], ptr %_.var, i32 0, i32 8, !dbg !25
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.array.end = getelementptr inbounds [3 x i32], ptr %.loc13_50.3.temp, i32 1, !dbg !25
|
||||
// CHECK:STDOUT: store ptr %initializer_list.initializer_list.call.array.end, ptr %initializer_list.initializer_list.call.init_list.end, align 8, !dbg !25
|
||||
// CHECK:STDOUT: call void @_CWithinLifetime.Main(), !dbg !27
|
||||
// CHECK:STDOUT: ret void, !dbg !28
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define void @_CInitVectorLike.Main() #3 !dbg !29 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %_.var = alloca {}, align 8, !dbg !30
|
||||
// CHECK:STDOUT: %.loc18_36.2.temp = alloca [16 x i8], align 1, !dbg !31
|
||||
// CHECK:STDOUT: %.loc18_36.4.temp = alloca [3 x i32], align 4, !dbg !31
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !30
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_36.2.temp), !dbg !31
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_36.4.temp), !dbg !31
|
||||
// CHECK:STDOUT: %.loc18_36.5.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_36.4.temp, i32 0, i64 0, !dbg !31
|
||||
// CHECK:STDOUT: %.loc18_36.8.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_36.4.temp, i32 0, i64 1, !dbg !31
|
||||
// CHECK:STDOUT: %.loc18_36.11.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_36.4.temp, i32 0, i64 2, !dbg !31
|
||||
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %.loc18_36.4.temp, ptr align 4 @array.loc13_50.13, i64 12, i1 false), !dbg !31
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.begin = getelementptr inbounds nuw [16 x i8], ptr %.loc18_36.2.temp, i32 0, i32 0, !dbg !31
|
||||
// CHECK:STDOUT: store ptr %.loc18_36.4.temp, ptr %initializer_list.initializer_list.call.init_list.begin, align 8, !dbg !31
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.end = getelementptr inbounds nuw [16 x i8], ptr %.loc18_36.2.temp, i32 0, i32 8, !dbg !31
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.array.end = getelementptr inbounds [3 x i32], ptr %.loc18_36.4.temp, i32 1, !dbg !31
|
||||
// CHECK:STDOUT: store ptr %initializer_list.initializer_list.call.array.end, ptr %initializer_list.initializer_list.call.init_list.end, align 8, !dbg !31
|
||||
// CHECK:STDOUT: call void @_ZN11vector_likeC1ESt16initializer_listIiE.carbon_thunk(ptr %.loc18_36.2.temp, ptr %_.var), !dbg !30
|
||||
// CHECK:STDOUT: call void @_CWithinLifetime.Main(), !dbg !32
|
||||
// CHECK:STDOUT: call void @_ZN11vector_likeD2Ev(ptr %_.var), !dbg !30
|
||||
// CHECK:STDOUT: ret void, !dbg !33
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: mustprogress nounwind uwtable
|
||||
// CHECK:STDOUT: define linkonce_odr dso_local void @_ZN11vector_likeD2Ev(ptr noundef nonnull align 1 dereferenceable(1) %this) unnamed_addr #2 comdat align 2 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %this.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !15
|
||||
// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define void @_CInitNontrivialDtor.Main() #3 !dbg !34 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %_.var = alloca [16 x i8], align 1, !dbg !35
|
||||
// CHECK:STDOUT: %.loc23_69.17.temp = alloca [3 x {}], align 8, !dbg !36
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !35
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc23_69.17.temp), !dbg !36
|
||||
// CHECK:STDOUT: %.loc23_69.18.array.index = getelementptr inbounds [3 x {}], ptr %.loc23_69.17.temp, i32 0, i64 0, !dbg !36
|
||||
// CHECK:STDOUT: call void @_ZN15nontrivial_dtorC1Ev.carbon_thunk_tuple(ptr %.loc23_69.18.array.index), !dbg !36
|
||||
// CHECK:STDOUT: %.loc23_69.16.array.index = getelementptr inbounds [3 x {}], ptr %.loc23_69.17.temp, i32 0, i64 1, !dbg !36
|
||||
// CHECK:STDOUT: call void @_ZN15nontrivial_dtorC1Ev.carbon_thunk_tuple(ptr %.loc23_69.16.array.index), !dbg !36
|
||||
// CHECK:STDOUT: %.loc23_69.15.array.index = getelementptr inbounds [3 x {}], ptr %.loc23_69.17.temp, i32 0, i64 2, !dbg !36
|
||||
// CHECK:STDOUT: call void @_ZN15nontrivial_dtorC1Ev.carbon_thunk_tuple(ptr %.loc23_69.15.array.index), !dbg !36
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.begin = getelementptr inbounds nuw [16 x i8], ptr %_.var, i32 0, i32 0, !dbg !35
|
||||
// CHECK:STDOUT: store ptr %.loc23_69.17.temp, ptr %initializer_list.initializer_list.call.init_list.begin, align 8, !dbg !35
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.end = getelementptr inbounds nuw [16 x i8], ptr %_.var, i32 0, i32 8, !dbg !35
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.array.end = getelementptr inbounds [3 x {}], ptr %.loc23_69.17.temp, i32 1, !dbg !35
|
||||
// CHECK:STDOUT: store ptr %initializer_list.initializer_list.call.array.end, ptr %initializer_list.initializer_list.call.init_list.end, align 8, !dbg !35
|
||||
// CHECK:STDOUT: call void @_CWithinLifetime.Main(), !dbg !37
|
||||
// CHECK:STDOUT: ret void, !dbg !38
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #4
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; uselistorder directives
|
||||
// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 6, 5, 4, 3, 2, 1, 0 }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: attributes #0 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
||||
// CHECK:STDOUT: attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT: attributes #2 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
||||
// CHECK:STDOUT: attributes #3 = { nounwind }
|
||||
// CHECK:STDOUT: attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4, !5}
|
||||
// CHECK:STDOUT: !llvm.dbg.cu = !{!6}
|
||||
// CHECK:STDOUT: !llvm.errno.tbaa = !{!8}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
|
||||
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
|
||||
// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 2}
|
||||
// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
|
||||
// CHECK:STDOUT: !5 = !{i32 7, !"uwtable", i32 2}
|
||||
// CHECK:STDOUT: !6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !7, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
||||
// CHECK:STDOUT: !7 = !DIFile(filename: "use_pointer_pointer.carbon", directory: "")
|
||||
// CHECK:STDOUT: !8 = !{!9, !9, i64 0}
|
||||
// CHECK:STDOUT: !9 = !{!"int", !10, i64 0}
|
||||
// CHECK:STDOUT: !10 = !{!"omnipotent char", !11, i64 0}
|
||||
// CHECK:STDOUT: !11 = !{!"Simple C++ TBAA"}
|
||||
// CHECK:STDOUT: !12 = !{!13, !13, i64 0}
|
||||
// CHECK:STDOUT: !13 = !{!"p1 _ZTSSt16initializer_listIiE", !14, i64 0}
|
||||
// CHECK:STDOUT: !14 = !{!"any pointer", !10, i64 0}
|
||||
// CHECK:STDOUT: !15 = !{!16, !16, i64 0}
|
||||
// CHECK:STDOUT: !16 = !{!"p1 _ZTS11vector_like", !14, i64 0}
|
||||
// CHECK:STDOUT: !17 = !{i64 0, i64 8, !18, i64 8, i64 8, !18}
|
||||
// CHECK:STDOUT: !18 = !{!19, !19, i64 0}
|
||||
// CHECK:STDOUT: !19 = !{!"p1 int", !14, i64 0}
|
||||
// CHECK:STDOUT: !20 = !{!21, !21, i64 0}
|
||||
// CHECK:STDOUT: !21 = !{!"p1 _ZTS15nontrivial_dtor", !14, i64 0}
|
||||
// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "InitDirectly", linkageName: "_CInitDirectly.Main", scope: null, file: !7, line: 12, type: !23, spFlags: DISPFlagDefinition, unit: !6)
|
||||
// CHECK:STDOUT: !23 = !DISubroutineType(types: !24)
|
||||
// CHECK:STDOUT: !24 = !{null}
|
||||
// CHECK:STDOUT: !25 = !DILocation(line: 13, column: 3, scope: !22)
|
||||
// CHECK:STDOUT: !26 = !DILocation(line: 13, column: 42, scope: !22)
|
||||
// CHECK:STDOUT: !27 = !DILocation(line: 14, column: 3, scope: !22)
|
||||
// CHECK:STDOUT: !28 = !DILocation(line: 12, column: 1, scope: !22)
|
||||
// CHECK:STDOUT: !29 = distinct !DISubprogram(name: "InitVectorLike", linkageName: "_CInitVectorLike.Main", scope: null, file: !7, line: 17, type: !23, spFlags: DISPFlagDefinition, unit: !6)
|
||||
// CHECK:STDOUT: !30 = !DILocation(line: 18, column: 3, scope: !29)
|
||||
// CHECK:STDOUT: !31 = !DILocation(line: 18, column: 28, scope: !29)
|
||||
// CHECK:STDOUT: !32 = !DILocation(line: 19, column: 3, scope: !29)
|
||||
// CHECK:STDOUT: !33 = !DILocation(line: 17, column: 1, scope: !29)
|
||||
// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "InitNontrivialDtor", linkageName: "_CInitNontrivialDtor.Main", scope: null, file: !7, line: 22, type: !23, spFlags: DISPFlagDefinition, unit: !6)
|
||||
// CHECK:STDOUT: !35 = !DILocation(line: 23, column: 3, scope: !34)
|
||||
// CHECK:STDOUT: !36 = !DILocation(line: 23, column: 58, scope: !34)
|
||||
// CHECK:STDOUT: !37 = !DILocation(line: 24, column: 3, scope: !34)
|
||||
// CHECK:STDOUT: !38 = !DILocation(line: 22, column: 1, scope: !34)
|
||||
// CHECK:STDOUT: ; ModuleID = 'use_pointer_size.carbon'
|
||||
// CHECK:STDOUT: source_filename = "use_pointer_size.carbon"
|
||||
// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
|
||||
// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: %"class.std::initializer_list" = type { ptr, i64 }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: $_ZN11vector_likeC2ESt16initializer_listIiE = comdat any
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: $_ZN15nontrivial_dtorC2Ev = comdat any
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: $_ZN11vector_likeD2Ev = comdat any
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: @array.loc13_50.13 = internal constant [3 x i32] [i32 1, i32 2, i32 3]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
|
||||
// CHECK:STDOUT: define dso_local void @_ZN11vector_likeC1ESt16initializer_listIiE.carbon_thunk(ptr noundef %list, ptr noundef %return) #0 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %list.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: %agg.tmp = alloca %"class.std::initializer_list", align 8
|
||||
// CHECK:STDOUT: store ptr %list, ptr %list.addr, align 8, !tbaa !12
|
||||
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !15
|
||||
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !15
|
||||
// CHECK:STDOUT: %1 = load ptr, ptr %list.addr, align 8, !tbaa !12
|
||||
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %agg.tmp, ptr align 8 %1, i64 16, i1 false), !tbaa.struct !17
|
||||
// CHECK:STDOUT: %2 = getelementptr inbounds nuw { ptr, i64 }, ptr %agg.tmp, i32 0, i32 0
|
||||
// CHECK:STDOUT: %3 = load ptr, ptr %2, align 8
|
||||
// CHECK:STDOUT: %4 = getelementptr inbounds nuw { ptr, i64 }, ptr %agg.tmp, i32 0, i32 1
|
||||
// CHECK:STDOUT: %5 = load i64, ptr %4, align 8
|
||||
// CHECK:STDOUT: call void @_ZN11vector_likeC2ESt16initializer_listIiE(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr %3, i64 %5)
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #1
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: mustprogress nounwind uwtable
|
||||
// CHECK:STDOUT: define linkonce_odr dso_local void @_ZN11vector_likeC2ESt16initializer_listIiE(ptr noundef nonnull align 1 dereferenceable(1) %this, ptr %list.coerce0, i64 %list.coerce1) unnamed_addr #2 comdat align 2 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %list = alloca %"class.std::initializer_list", align 8
|
||||
// CHECK:STDOUT: %this.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: %0 = getelementptr inbounds nuw { ptr, i64 }, ptr %list, i32 0, i32 0
|
||||
// CHECK:STDOUT: store ptr %list.coerce0, ptr %0, align 8
|
||||
// CHECK:STDOUT: %1 = getelementptr inbounds nuw { ptr, i64 }, ptr %list, i32 0, i32 1
|
||||
// CHECK:STDOUT: store i64 %list.coerce1, ptr %1, align 8
|
||||
// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !15
|
||||
// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
|
||||
// CHECK:STDOUT: define dso_local void @_ZN15nontrivial_dtorC1Ev.carbon_thunk_tuple(ptr noundef %return) #0 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %return.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !22
|
||||
// CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !22
|
||||
// CHECK:STDOUT: call void @_ZN15nontrivial_dtorC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %0)
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: mustprogress nounwind uwtable
|
||||
// CHECK:STDOUT: define linkonce_odr dso_local void @_ZN15nontrivial_dtorC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %this) unnamed_addr #2 comdat align 2 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %this.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !22
|
||||
// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: declare void @_CWithinLifetime.Main()
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define void @_CInitDirectly.Main() #3 !dbg !24 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %_.var = alloca [16 x i8], align 1, !dbg !27
|
||||
// CHECK:STDOUT: %.loc13_50.3.temp = alloca [3 x i32], align 4, !dbg !28
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !27
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc13_50.3.temp), !dbg !28
|
||||
// CHECK:STDOUT: %.loc13_50.4.array.index = getelementptr inbounds [3 x i32], ptr %.loc13_50.3.temp, i32 0, i64 0, !dbg !28
|
||||
// CHECK:STDOUT: %.loc13_50.7.array.index = getelementptr inbounds [3 x i32], ptr %.loc13_50.3.temp, i32 0, i64 1, !dbg !28
|
||||
// CHECK:STDOUT: %.loc13_50.10.array.index = getelementptr inbounds [3 x i32], ptr %.loc13_50.3.temp, i32 0, i64 2, !dbg !28
|
||||
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %.loc13_50.3.temp, ptr align 4 @array.loc13_50.13, i64 12, i1 false), !dbg !28
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.begin = getelementptr inbounds nuw [16 x i8], ptr %_.var, i32 0, i32 0, !dbg !27
|
||||
// CHECK:STDOUT: store ptr %.loc13_50.3.temp, ptr %initializer_list.initializer_list.call.init_list.begin, align 8, !dbg !27
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.size = getelementptr inbounds nuw [16 x i8], ptr %_.var, i32 0, i32 8, !dbg !27
|
||||
// CHECK:STDOUT: store i64 3, ptr %initializer_list.initializer_list.call.init_list.size, align 8, !dbg !27
|
||||
// CHECK:STDOUT: call void @_CWithinLifetime.Main(), !dbg !29
|
||||
// CHECK:STDOUT: ret void, !dbg !30
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define void @_CInitVectorLike.Main() #3 !dbg !31 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %_.var = alloca {}, align 8, !dbg !32
|
||||
// CHECK:STDOUT: %.loc18_36.2.temp = alloca [16 x i8], align 1, !dbg !33
|
||||
// CHECK:STDOUT: %.loc18_36.4.temp = alloca [3 x i32], align 4, !dbg !33
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !32
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_36.2.temp), !dbg !33
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_36.4.temp), !dbg !33
|
||||
// CHECK:STDOUT: %.loc18_36.5.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_36.4.temp, i32 0, i64 0, !dbg !33
|
||||
// CHECK:STDOUT: %.loc18_36.8.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_36.4.temp, i32 0, i64 1, !dbg !33
|
||||
// CHECK:STDOUT: %.loc18_36.11.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_36.4.temp, i32 0, i64 2, !dbg !33
|
||||
// CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %.loc18_36.4.temp, ptr align 4 @array.loc13_50.13, i64 12, i1 false), !dbg !33
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.begin = getelementptr inbounds nuw [16 x i8], ptr %.loc18_36.2.temp, i32 0, i32 0, !dbg !33
|
||||
// CHECK:STDOUT: store ptr %.loc18_36.4.temp, ptr %initializer_list.initializer_list.call.init_list.begin, align 8, !dbg !33
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.size = getelementptr inbounds nuw [16 x i8], ptr %.loc18_36.2.temp, i32 0, i32 8, !dbg !33
|
||||
// CHECK:STDOUT: store i64 3, ptr %initializer_list.initializer_list.call.init_list.size, align 8, !dbg !33
|
||||
// CHECK:STDOUT: call void @_ZN11vector_likeC1ESt16initializer_listIiE.carbon_thunk(ptr %.loc18_36.2.temp, ptr %_.var), !dbg !32
|
||||
// CHECK:STDOUT: call void @_CWithinLifetime.Main(), !dbg !34
|
||||
// CHECK:STDOUT: call void @_ZN11vector_likeD2Ev(ptr %_.var), !dbg !32
|
||||
// CHECK:STDOUT: ret void, !dbg !35
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: mustprogress nounwind uwtable
|
||||
// CHECK:STDOUT: define linkonce_odr dso_local void @_ZN11vector_likeD2Ev(ptr noundef nonnull align 1 dereferenceable(1) %this) unnamed_addr #2 comdat align 2 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %this.addr = alloca ptr, align 8
|
||||
// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8, !tbaa !15
|
||||
// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8
|
||||
// CHECK:STDOUT: ret void
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define void @_CInitNontrivialDtor.Main() #3 !dbg !36 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %_.var = alloca [16 x i8], align 1, !dbg !37
|
||||
// CHECK:STDOUT: %.loc23_69.17.temp = alloca [3 x {}], align 8, !dbg !38
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %_.var), !dbg !37
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc23_69.17.temp), !dbg !38
|
||||
// CHECK:STDOUT: %.loc23_69.18.array.index = getelementptr inbounds [3 x {}], ptr %.loc23_69.17.temp, i32 0, i64 0, !dbg !38
|
||||
// CHECK:STDOUT: call void @_ZN15nontrivial_dtorC1Ev.carbon_thunk_tuple(ptr %.loc23_69.18.array.index), !dbg !38
|
||||
// CHECK:STDOUT: %.loc23_69.16.array.index = getelementptr inbounds [3 x {}], ptr %.loc23_69.17.temp, i32 0, i64 1, !dbg !38
|
||||
// CHECK:STDOUT: call void @_ZN15nontrivial_dtorC1Ev.carbon_thunk_tuple(ptr %.loc23_69.16.array.index), !dbg !38
|
||||
// CHECK:STDOUT: %.loc23_69.15.array.index = getelementptr inbounds [3 x {}], ptr %.loc23_69.17.temp, i32 0, i64 2, !dbg !38
|
||||
// CHECK:STDOUT: call void @_ZN15nontrivial_dtorC1Ev.carbon_thunk_tuple(ptr %.loc23_69.15.array.index), !dbg !38
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.begin = getelementptr inbounds nuw [16 x i8], ptr %_.var, i32 0, i32 0, !dbg !37
|
||||
// CHECK:STDOUT: store ptr %.loc23_69.17.temp, ptr %initializer_list.initializer_list.call.init_list.begin, align 8, !dbg !37
|
||||
// CHECK:STDOUT: %initializer_list.initializer_list.call.init_list.size = getelementptr inbounds nuw [16 x i8], ptr %_.var, i32 0, i32 8, !dbg !37
|
||||
// CHECK:STDOUT: store i64 3, ptr %initializer_list.initializer_list.call.init_list.size, align 8, !dbg !37
|
||||
// CHECK:STDOUT: call void @_CWithinLifetime.Main(), !dbg !39
|
||||
// CHECK:STDOUT: ret void, !dbg !40
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #4
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; uselistorder directives
|
||||
// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 6, 5, 4, 3, 2, 1, 0 }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: attributes #0 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
||||
// CHECK:STDOUT: attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT: attributes #2 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
||||
// CHECK:STDOUT: attributes #3 = { nounwind }
|
||||
// CHECK:STDOUT: attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4, !5}
|
||||
// CHECK:STDOUT: !llvm.dbg.cu = !{!6}
|
||||
// CHECK:STDOUT: !llvm.errno.tbaa = !{!8}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
|
||||
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
|
||||
// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 2}
|
||||
// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
|
||||
// CHECK:STDOUT: !5 = !{i32 7, !"uwtable", i32 2}
|
||||
// CHECK:STDOUT: !6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !7, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
||||
// CHECK:STDOUT: !7 = !DIFile(filename: "use_pointer_size.carbon", directory: "")
|
||||
// CHECK:STDOUT: !8 = !{!9, !9, i64 0}
|
||||
// CHECK:STDOUT: !9 = !{!"int", !10, i64 0}
|
||||
// CHECK:STDOUT: !10 = !{!"omnipotent char", !11, i64 0}
|
||||
// CHECK:STDOUT: !11 = !{!"Simple C++ TBAA"}
|
||||
// CHECK:STDOUT: !12 = !{!13, !13, i64 0}
|
||||
// CHECK:STDOUT: !13 = !{!"p1 _ZTSSt16initializer_listIiE", !14, i64 0}
|
||||
// CHECK:STDOUT: !14 = !{!"any pointer", !10, i64 0}
|
||||
// CHECK:STDOUT: !15 = !{!16, !16, i64 0}
|
||||
// CHECK:STDOUT: !16 = !{!"p1 _ZTS11vector_like", !14, i64 0}
|
||||
// CHECK:STDOUT: !17 = !{i64 0, i64 8, !18, i64 8, i64 8, !20}
|
||||
// CHECK:STDOUT: !18 = !{!19, !19, i64 0}
|
||||
// CHECK:STDOUT: !19 = !{!"p1 int", !14, i64 0}
|
||||
// CHECK:STDOUT: !20 = !{!21, !21, i64 0}
|
||||
// CHECK:STDOUT: !21 = !{!"long", !10, i64 0}
|
||||
// CHECK:STDOUT: !22 = !{!23, !23, i64 0}
|
||||
// CHECK:STDOUT: !23 = !{!"p1 _ZTS15nontrivial_dtor", !14, i64 0}
|
||||
// CHECK:STDOUT: !24 = distinct !DISubprogram(name: "InitDirectly", linkageName: "_CInitDirectly.Main", scope: null, file: !7, line: 12, type: !25, spFlags: DISPFlagDefinition, unit: !6)
|
||||
// CHECK:STDOUT: !25 = !DISubroutineType(types: !26)
|
||||
// CHECK:STDOUT: !26 = !{null}
|
||||
// CHECK:STDOUT: !27 = !DILocation(line: 13, column: 3, scope: !24)
|
||||
// CHECK:STDOUT: !28 = !DILocation(line: 13, column: 42, scope: !24)
|
||||
// CHECK:STDOUT: !29 = !DILocation(line: 14, column: 3, scope: !24)
|
||||
// CHECK:STDOUT: !30 = !DILocation(line: 12, column: 1, scope: !24)
|
||||
// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "InitVectorLike", linkageName: "_CInitVectorLike.Main", scope: null, file: !7, line: 17, type: !25, spFlags: DISPFlagDefinition, unit: !6)
|
||||
// CHECK:STDOUT: !32 = !DILocation(line: 18, column: 3, scope: !31)
|
||||
// CHECK:STDOUT: !33 = !DILocation(line: 18, column: 28, scope: !31)
|
||||
// CHECK:STDOUT: !34 = !DILocation(line: 19, column: 3, scope: !31)
|
||||
// CHECK:STDOUT: !35 = !DILocation(line: 17, column: 1, scope: !31)
|
||||
// CHECK:STDOUT: !36 = distinct !DISubprogram(name: "InitNontrivialDtor", linkageName: "_CInitNontrivialDtor.Main", scope: null, file: !7, line: 22, type: !25, spFlags: DISPFlagDefinition, unit: !6)
|
||||
// CHECK:STDOUT: !37 = !DILocation(line: 23, column: 3, scope: !36)
|
||||
// CHECK:STDOUT: !38 = !DILocation(line: 23, column: 58, scope: !36)
|
||||
// CHECK:STDOUT: !39 = !DILocation(line: 24, column: 3, scope: !36)
|
||||
// CHECK:STDOUT: !40 = !DILocation(line: 22, column: 1, scope: !36)
|
||||
@@ -85,6 +85,7 @@ cc_library(
|
||||
"builtin_function_kind.cpp",
|
||||
"class.cpp",
|
||||
"constant.cpp",
|
||||
"cpp_initializer_list.cpp",
|
||||
"facet_type_info.cpp",
|
||||
"file.cpp",
|
||||
"function.cpp",
|
||||
@@ -106,6 +107,7 @@ cc_library(
|
||||
"constant.h",
|
||||
"copy_on_write_block.h",
|
||||
"cpp_global_var.h",
|
||||
"cpp_initializer_list.h",
|
||||
"cpp_overload_set.h",
|
||||
"entity_name.h",
|
||||
"entity_with_params_base.h",
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "toolchain/sem_ir/cpp_initializer_list.h"
|
||||
#include "toolchain/sem_ir/file.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
#include "toolchain/sem_ir/type_info.h"
|
||||
@@ -146,14 +147,24 @@ struct CharCompatible {
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that requires the type to be a sized integer type.
|
||||
struct AnySizedInt {
|
||||
// Constraint that requires the type to be an type of the specified kind.
|
||||
template <typename InstT>
|
||||
struct Any {
|
||||
static auto CheckType(const File& sem_ir, ValidateState& /*state*/,
|
||||
TypeId type_id) -> bool {
|
||||
return sem_ir.types().Is<IntType>(type_id);
|
||||
return sem_ir.types().Is<InstT>(type_id);
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that requires the type to be a sized integer type.
|
||||
using AnySizedInt = Any<IntType>;
|
||||
|
||||
// Constraint that requires the type to be a sized floating-point type.
|
||||
using AnySizedFloat = Any<FloatType>;
|
||||
|
||||
// Constraint that requires the type to be an array type.
|
||||
using AnyArray = Any<ArrayType>;
|
||||
|
||||
// Constraint that requires the type to be an integer type: either a sized
|
||||
// integer type or a literal.
|
||||
struct AnyInt {
|
||||
@@ -165,14 +176,6 @@ struct AnyInt {
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that requires the type to be a sized floating-point type.
|
||||
struct AnySizedFloat {
|
||||
static auto CheckType(const File& sem_ir, ValidateState& /*state*/,
|
||||
TypeId type_id) -> bool {
|
||||
return sem_ir.types().Is<FloatType>(type_id);
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that requires the type to be a float type: either a sized float
|
||||
// type or a literal.
|
||||
struct AnyFloat {
|
||||
@@ -222,6 +225,16 @@ struct CoreCharType {
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that requires the type to have a recognized layout, compatible
|
||||
// with `std::initializer_list<T>`.
|
||||
struct StdInitializerList {
|
||||
static auto CheckType(const File& sem_ir, ValidateState& /*state*/,
|
||||
TypeId type_id) -> bool {
|
||||
return GetStdInitializerListLayout(sem_ir, type_id).kind !=
|
||||
StdInitializerListLayout::None;
|
||||
}
|
||||
};
|
||||
|
||||
// Constraint that requires the type to be the type type.
|
||||
using Type = BuiltinType<TypeType::TypeInstId>;
|
||||
|
||||
@@ -734,6 +747,12 @@ constexpr BuiltinInfo PointerUnsafeConvert = {
|
||||
constexpr BuiltinInfo TypeAnd = {"type.and",
|
||||
ValidateSignature<auto(Type, Type)->Type>};
|
||||
|
||||
// "cpp.std.initializer_list.make": construct a std::initializer_list from an
|
||||
// array.
|
||||
constexpr BuiltinInfo CppStdInitializerListMake = {
|
||||
"cpp.std.initializer_list.make",
|
||||
ValidateSignature<auto(AnyArray)->StdInitializerList>};
|
||||
|
||||
} // namespace BuiltinFunctionInfo
|
||||
|
||||
CARBON_DEFINE_ENUM_CLASS_NAMES(BuiltinFunctionKind) {
|
||||
|
||||
@@ -133,4 +133,7 @@ CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(PointerUnsafeConvert)
|
||||
// Facet type combination.
|
||||
CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(TypeAnd)
|
||||
|
||||
// C++ interop builtins.
|
||||
CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(CppStdInitializerListMake)
|
||||
|
||||
#undef CARBON_SEM_IR_BUILTIN_FUNCTION_KIND
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "toolchain/sem_ir/cpp_initializer_list.h"
|
||||
|
||||
#include "toolchain/sem_ir/file.h"
|
||||
#include "toolchain/sem_ir/inst_categories.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
|
||||
namespace Carbon::SemIR {
|
||||
|
||||
auto GetStdInitializerListLayout(const File& sem_ir, TypeId type_id)
|
||||
-> StdInitializerListLayout {
|
||||
auto repr_id = sem_ir.types().GetObjectRepr(type_id);
|
||||
if (!repr_id.has_value()) {
|
||||
// An incomplete type doesn't have a recognized layout.
|
||||
return StdInitializerListLayout{};
|
||||
}
|
||||
|
||||
auto struct_type = sem_ir.types().TryGetAs<AnyStructType>(repr_id);
|
||||
if (!struct_type) {
|
||||
return StdInitializerListLayout{};
|
||||
}
|
||||
|
||||
auto fields = sem_ir.struct_type_fields().Get(struct_type->fields_id);
|
||||
if (fields.size() != 2) {
|
||||
return StdInitializerListLayout{};
|
||||
}
|
||||
|
||||
// The first field must be a pointer.
|
||||
auto field0_type_id = sem_ir.types().GetTransitiveUnqualifiedAdaptedType(
|
||||
sem_ir.types().GetTypeIdForTypeInstId(fields[0].type_inst_id));
|
||||
if (!sem_ir.types().Is<PointerType>(field0_type_id.first)) {
|
||||
return StdInitializerListLayout{};
|
||||
}
|
||||
|
||||
// The second field can be either a pointer or an integer.
|
||||
auto field1_type_id = sem_ir.types().GetTransitiveUnqualifiedAdaptedType(
|
||||
sem_ir.types().GetTypeIdForTypeInstId(fields[1].type_inst_id));
|
||||
if (sem_ir.types().Is<PointerType>(field1_type_id.first)) {
|
||||
return StdInitializerListLayout{
|
||||
.kind = StdInitializerListLayout::PointerPointer};
|
||||
}
|
||||
if (sem_ir.types().TryGetIntTypeInfo(field1_type_id.first)) {
|
||||
return StdInitializerListLayout{
|
||||
.kind = StdInitializerListLayout::PointerInt,
|
||||
.size_type_id = field1_type_id.first};
|
||||
}
|
||||
|
||||
return StdInitializerListLayout{};
|
||||
}
|
||||
|
||||
} // namespace Carbon::SemIR
|
||||
@@ -0,0 +1,38 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#ifndef CARBON_TOOLCHAIN_SEM_IR_CPP_INITIALIZER_LIST_H_
|
||||
#define CARBON_TOOLCHAIN_SEM_IR_CPP_INITIALIZER_LIST_H_
|
||||
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
|
||||
namespace Carbon::SemIR {
|
||||
|
||||
class File;
|
||||
|
||||
// The layout of `std::initializer_list` that we are dealing with.
|
||||
struct StdInitializerListLayout {
|
||||
enum Kind : int8_t {
|
||||
// Not a recognized layout.
|
||||
None,
|
||||
// `struct { T* begin; T* end; }`
|
||||
PointerPointer,
|
||||
// `struct { T* begin; size_t size; }`
|
||||
PointerInt,
|
||||
};
|
||||
Kind kind = Kind::None;
|
||||
// If the kind is PointerInt, the type of the size.
|
||||
TypeId size_type_id = TypeId::None;
|
||||
};
|
||||
|
||||
// Returns the kind of `std::initializer_list` that `type_id` represents, or
|
||||
// `None` if it is not a `std::initializer_list`. This does not verify that
|
||||
// `type_id` is actually a type named `std::initializer_list`, only that it has
|
||||
// a recognized set of fields that allows us to treat it as one.
|
||||
auto GetStdInitializerListLayout(const File& sem_ir, TypeId type_id)
|
||||
-> StdInitializerListLayout;
|
||||
|
||||
} // namespace Carbon::SemIR
|
||||
|
||||
#endif // CARBON_TOOLCHAIN_SEM_IR_CPP_INITIALIZER_LIST_H_
|
||||
@@ -1269,12 +1269,11 @@ struct OutParam {
|
||||
// A pattern that represents an output `Call` parameter. See `AnyParamPattern`
|
||||
// for member documentation.
|
||||
struct OutParamPattern {
|
||||
static constexpr auto Kind =
|
||||
InstKind::OutParamPattern.Define<Parse::ReturnTypeId>(
|
||||
{.ir_name = "out_param_pattern",
|
||||
.expr_category = ExprCategory::Pattern,
|
||||
.constant_kind = InstConstantKind::AlwaysUnique,
|
||||
.is_lowered = false});
|
||||
static constexpr auto Kind = InstKind::OutParamPattern.Define<Parse::NodeId>(
|
||||
{.ir_name = "out_param_pattern",
|
||||
.expr_category = ExprCategory::Pattern,
|
||||
.constant_kind = InstConstantKind::AlwaysUnique,
|
||||
.is_lowered = false});
|
||||
|
||||
TypeId type_id;
|
||||
InstId subpattern_id;
|
||||
@@ -1586,7 +1585,7 @@ struct ReturnSlot {
|
||||
// for input parameters.
|
||||
struct ReturnSlotPattern {
|
||||
static constexpr auto Kind =
|
||||
InstKind::ReturnSlotPattern.Define<Parse::ReturnTypeId>(
|
||||
InstKind::ReturnSlotPattern.Define<Parse::NodeId>(
|
||||
{.ir_name = "return_slot_pattern",
|
||||
.expr_category = ExprCategory::Pattern,
|
||||
.constant_kind = InstConstantKind::AlwaysUnique,
|
||||
|
||||
Reference in New Issue
Block a user