https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/129304
>From d13f2d0d40987302243efad7304a1a006fdb2dde Mon Sep 17 00:00:00 2001 From: AmrDeveloper <am...@programmer.net> Date: Fri, 28 Feb 2025 21:42:36 +0100 Subject: [PATCH 1/2] [CIR] Upstream floating point literal expressions --- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 9 +++++++++ clang/test/CIR/func-simple.cpp | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 24a959108f73b..1b2861ddcedb5 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -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>( diff --git a/clang/test/CIR/func-simple.cpp b/clang/test/CIR/func-simple.cpp index 3947055e300a0..5927d90a2e548 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.242000e+01> : !cir.float +// 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.242000e+01> : !cir.double +// CHECK: cir.return %0 : !cir.double +// CHECK: } >From a1409b1b1b73249a4baa98435f0c6fd7d15be5c8 Mon Sep 17 00:00:00 2001 From: AmrDeveloper <am...@programmer.net> Date: Sat, 1 Mar 2025 11:56:56 +0100 Subject: [PATCH 2/2] Simplify the test to check the first part of the floating point only --- clang/test/CIR/func-simple.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/CIR/func-simple.cpp b/clang/test/CIR/func-simple.cpp index 5927d90a2e548..d37ccc7229f22 100644 --- a/clang/test/CIR/func-simple.cpp +++ b/clang/test/CIR/func-simple.cpp @@ -60,12 +60,12 @@ bool boolfunc() { return true; } float floatfunc() { return 42.42f; } // CHECK: cir.func @floatfunc() -> !cir.float { -// CHECK: %0 = cir.const #cir.fp<4.242000e+01> : !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.242000e+01> : !cir.double +// CHECK: %0 = cir.const #cir.fp<4.242 // CHECK: cir.return %0 : !cir.double // CHECK: } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits