Add support for character literals in macros (#6419)

Adding support for macros with character literals.

Part of #6303
This commit is contained in:
Ivana Ivanovska
2025-11-24 13:54:17 +00:00
committed by GitHub
parent 093700b274
commit 7be6538aec
3 changed files with 138 additions and 1 deletions
+7
View File
@@ -2298,6 +2298,13 @@ static auto MapConstant(Context& context, SemIR::LocId loc_id,
MakeImportedLocIdAndInst<SemIR::FloatValue>(
context, imported_loc_id,
{.type_id = type_id, .float_id = float_id}));
} else if (auto* character_literal =
dyn_cast<clang::CharacterLiteral>(expr)) {
inst_id = AddInstInNoBlock(
context, MakeImportedLocIdAndInst<SemIR::CharLiteralValue>(
context, imported_loc_id,
{.type_id = type_id,
.value = SemIR::CharId(character_literal->getValue())}));
} else {
context.TODO(loc_id, llvm::formatv(
"Unsupported: C++ constant expression type: '{0}'",
+2 -1
View File
@@ -61,7 +61,8 @@ auto TryEvaluateMacroToConstant(Context& context, SemIR::LocId loc_id,
return nullptr;
}
if (isa<clang::StringLiteral>(result_expr)) {
if (isa<clang::StringLiteral>(result_expr) ||
isa<clang::CharacterLiteral>(result_expr)) {
return result_expr;
}