Skip to content

[CIR] Handle character literal values #144141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
builder.getAttr<cir::FPAttr>(type, e->getValue()));
}

mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {
mlir::Type ty = cgf.convertType(e->getType());
auto init = cir::IntAttr::get(ty, e->getValue());
return builder.create<cir::ConstantOp>(cgf.getLoc(e->getExprLoc()), init);
}

mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
return builder.getBool(e->getValue(), cgf.getLoc(e->getExprLoc()));
}
Expand Down
14 changes: 14 additions & 0 deletions clang/test/CIR/CodeGen/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,17 @@ size_type max_size(void) {
// CHECK: %6 = cir.load{{.*}} %0 : !cir.ptr<!u64i>, !u64i
// CHECK: cir.return %6 : !u64i
// CHECK: }

void test_char_literal() {
char c;
c = 'X';
}

// CIR: cir.func @test_char_literal
// CIR: cir.const #cir.int<88>

// LLVM: define void @test_char_literal()
// LLVM: store i8 88, ptr %{{.*}}, align 1

// OGCG: define{{.*}} void @test_char_literal()
// OGCG: store i8 88, ptr %{{.*}}, align 1
Loading