[clang] ab30df4 - [CIR] Upstream floating point literal expressions (#129304)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 3 10:22:47 PST 2025
Author: Amr Hesham
Date: 2025-03-03T19:22:44+01:00
New Revision: ab30df470af91427abf03f99f7f3517129464ca9
URL: https://github.com/llvm/llvm-project/commit/ab30df470af91427abf03f99f7f3517129464ca9
DIFF: https://github.com/llvm/llvm-project/commit/ab30df470af91427abf03f99f7f3517129464ca9.diff
LOG: [CIR] Upstream floating point literal expressions (#129304)
This change adds support for floating point literal expressions
Added:
Modified:
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
clang/test/CIR/func-simple.cpp
Removed:
################################################################################
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 90a2fd2a5d806..32fab85cd3db4 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -74,6 +74,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>(
diff --git a/clang/test/CIR/func-simple.cpp b/clang/test/CIR/func-simple.cpp
index 3947055e300a0..d37ccc7229f22 100644
--- a/clang/test/CIR/func-simple.cpp
+++ b/clang/test/CIR/func-simple.cpp
@@ -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: }
More information about the cfe-commits
mailing list