mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Support bool template params (#6808)
https://github.com/carbon-language/carbon-lang/issues/6717
This commit is contained in:
@@ -177,17 +177,27 @@ static auto ConvertArgToTemplateArg(
|
||||
context.constant_values().GetConstantInstId(converted_inst_id);
|
||||
if (const_inst_id.has_value()) {
|
||||
if (param_type->isIntegerType()) {
|
||||
const bool is_signed = param_type->isSignedIntegerOrEnumerationType();
|
||||
if (auto int_value =
|
||||
context.insts().TryGetAs<SemIR::IntValue>(const_inst_id)) {
|
||||
const auto& ap_int = context.ints().Get(int_value->int_id);
|
||||
const bool is_unsigned =
|
||||
!param_type->isSignedIntegerOrEnumerationType();
|
||||
auto aps_int =
|
||||
llvm::APSInt(ap_int, is_unsigned)
|
||||
llvm::APSInt(ap_int, !is_signed)
|
||||
.extOrTrunc(context.ast_context().getIntWidth(param_type));
|
||||
clang::TemplateArgument template_arg(context.ast_context(), aps_int,
|
||||
param_type);
|
||||
return clang::TemplateArgumentLoc(template_arg, template_loc);
|
||||
} else if (auto bool_value =
|
||||
context.insts().TryGetAs<SemIR::BoolLiteral>(
|
||||
const_inst_id)) {
|
||||
llvm::APInt ap_int(context.ast_context().getIntWidth(param_type),
|
||||
bool_value->value.ToBool(), is_signed);
|
||||
auto aps_int =
|
||||
llvm::APSInt(ap_int, !is_signed)
|
||||
.extOrTrunc(context.ast_context().getIntWidth(param_type));
|
||||
auto template_arg = clang::TemplateArgument(context.ast_context(),
|
||||
aps_int, param_type);
|
||||
return clang::TemplateArgumentLoc(template_arg, template_loc);
|
||||
}
|
||||
} else if (param_type->isFloatingType()) {
|
||||
if (auto float_value =
|
||||
|
||||
Reference in New Issue
Block a user