Skip to content

Commit ab30df4

Browse files
authored
[CIR] Upstream floating point literal expressions (#129304)
This change adds support for floating point literal expressions
1 parent af464c6 commit ab30df4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
7474
builder.getAttr<cir::IntAttr>(type, e->getValue()));
7575
}
7676

77+
mlir::Value VisitFloatingLiteral(const FloatingLiteral *e) {
78+
mlir::Type type = cgf.convertType(e->getType());
79+
assert(mlir::isa<cir::CIRFPTypeInterface>(type) &&
80+
"expect floating-point type");
81+
return builder.create<cir::ConstantOp>(
82+
cgf.getLoc(e->getExprLoc()), type,
83+
builder.getAttr<cir::FPAttr>(type, e->getValue()));
84+
}
85+
7786
mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
7887
mlir::Type type = cgf.convertType(e->getType());
7988
return builder.create<cir::ConstantOp>(

clang/test/CIR/func-simple.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,15 @@ bool boolfunc() { return true; }
5757
// CHECK: %0 = cir.const #true
5858
// CHECK: cir.return %0 : !cir.bool
5959
// CHECK: }
60+
61+
float floatfunc() { return 42.42f; }
62+
// CHECK: cir.func @floatfunc() -> !cir.float {
63+
// CHECK: %0 = cir.const #cir.fp<4.242
64+
// CHECK: cir.return %0 : !cir.float
65+
// CHECK: }
66+
67+
double doublefunc() { return 42.42; }
68+
// CHECK: cir.func @doublefunc() -> !cir.double {
69+
// CHECK: %0 = cir.const #cir.fp<4.242
70+
// CHECK: cir.return %0 : !cir.double
71+
// CHECK: }

0 commit comments

Comments
 (0)