diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 30d231e2c61de..baaef022ccc68 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -346,8 +346,8 @@ class ScalarExprEmitter : public StmtVisitor { assert(!cir::MissingFeatures::fpConstraints()); castKind = cir::CastKind::float_to_int; } else if (mlir::isa(dstTy)) { - cgf.getCIRGenModule().errorNYI("floating point casts"); - return cgf.createDummyValue(src.getLoc(), dstType); + // TODO: split this to createFPExt/createFPTrunc + return builder.createFloatingCast(src, fullDstTy); } else { llvm_unreachable("Internal error: Cast to unexpected type"); } diff --git a/clang/test/CIR/CodeGen/cast.cpp b/clang/test/CIR/CodeGen/cast.cpp index a7c11b1939ba5..84f55242a6118 100644 --- a/clang/test/CIR/CodeGen/cast.cpp +++ b/clang/test/CIR/CodeGen/cast.cpp @@ -73,6 +73,14 @@ int cStyleCasts_0(unsigned x1, int x2, float x3, short x4, double x5) { // LLVM: %{{[0-9]+}} = fcmp une float %{{[0-9]+}}, 0.000000e+00 // LLVM: %{{[0-9]+}} = zext i1 %{{[0-9]+}} to i8 + double d2 = f; // float to double + // CIR: %{{[0-9]+}} = cir.cast(floating, %{{[0-9]+}} : !cir.float), !cir.double + // LLVM: %{{[0-9]+}} = fpext float %{{[0-9]+}} to double + + f = d2; // double to float + // CIR: %{{[0-9]+}} = cir.cast(floating, %{{[0-9]+}} : !cir.double), !cir.float + // LLVM: %{{[0-9]+}} = fptrunc double %{{[0-9]+}} to float + return 0; }