Skip to content

[CIR] Upstream floating point literal expressions #129304

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 2 commits into from
Mar 3, 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
9 changes: 9 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
builder.getAttr<cir::IntAttr>(type, e->getValue()));
}

mlir::Value VisitFloatingLiteral(const FloatingLiteral *e) {
mlir::Type type = cgf.convertType(e->getType());
assert(mlir::isa<cir::CIRFPTypeInterface>(type) &&
"expect floating-point type");
return builder.create<cir::ConstantOp>(
cgf.getLoc(e->getExprLoc()), type,
builder.getAttr<cir::FPAttr>(type, e->getValue()));
}

mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
mlir::Type type = cgf.convertType(e->getType());
return builder.create<cir::ConstantOp>(
Expand Down
12 changes: 12 additions & 0 deletions clang/test/CIR/func-simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ bool boolfunc() { return true; }
// CHECK: %0 = cir.const #true
// CHECK: cir.return %0 : !cir.bool
// CHECK: }

float floatfunc() { return 42.42f; }
// CHECK: cir.func @floatfunc() -> !cir.float {
// CHECK: %0 = cir.const #cir.fp<4.242
// CHECK: cir.return %0 : !cir.float
// CHECK: }

double doublefunc() { return 42.42; }
// CHECK: cir.func @doublefunc() -> !cir.double {
// CHECK: %0 = cir.const #cir.fp<4.242
// CHECK: cir.return %0 : !cir.double
// CHECK: }