llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clangir @llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) <details> <summary>Changes</summary> This change adds support for floating point literal expressions --- Full diff: https://github.com/llvm/llvm-project/pull/129304.diff 2 Files Affected: - (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+9) - (modified) clang/test/CIR/func-simple.cpp (+12) ``````````diff 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: } `````````` </details> https://github.com/llvm/llvm-project/pull/129304 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits