https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/218244

Add missing CIRGenFPOptionsRAII to be similar to OGCG

>From 4586959a0d13b28efe57551d61dd97b1b665de9f Mon Sep 17 00:00:00 2001
From: Amr Hesham <[email protected]>
Date: Sun, 23 Aug 2026 13:06:06 +0200
Subject: [PATCH] [CIR][NFC] Add missing CIRGenFPOptionsRAII

---
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 27 ++++++++++++++--------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index d2193dda37b6f..f6f22811e734e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -710,7 +710,7 @@ class ScalarExprEmitter : public 
StmtVisitor<ScalarExprEmitter, mlir::Value> {
         return {};
       }
     } else if (type->isRealFloatingType()) {
-      CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, e);
+      CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, e);
 
       if (type->isHalfType() &&
           !cgf.getContext().getLangOpts().NativeHalfType) {
@@ -1378,6 +1378,9 @@ class ScalarExprEmitter : public 
StmtVisitor<ScalarExprEmitter, mlir::Value> {
       mlir::Value lhs = Visit(e->getLHS());
       mlir::Value rhs = Visit(e->getRHS());
 
+      if (cir::isFPOrVectorOfFPType(lhs.getType()))
+        CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, e);
+
       auto cmpOpKind = cir::CmpOpKind::ne;
       mlir::Type resTy = cgf.convertType(e->getType());
       lhs = cir::VecCmpOp::create(builder, loc, resTy, cmpOpKind, lhs, 
zeroVec);
@@ -2159,7 +2162,7 @@ mlir::Value ScalarExprEmitter::emitMul(const BinOpInfo 
&ops) {
     cgf.cgm.errorNYI("unsigned int overflow sanitizer");
 
   if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
-    CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, ops.fpFeatures);
+    CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, ops.fpFeatures);
     return builder.createFMul(loc, ops.lhs, ops.rhs);
   }
 
@@ -2172,7 +2175,7 @@ mlir::Value ScalarExprEmitter::emitMul(const BinOpInfo 
&ops) {
 mlir::Value ScalarExprEmitter::emitDiv(const BinOpInfo &ops) {
   const mlir::Location loc = cgf.getLoc(ops.loc);
   if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
-    CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, ops.fpFeatures);
+    CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, ops.fpFeatures);
     return builder.createFDiv(loc, ops.lhs, ops.rhs);
   }
 
@@ -2185,7 +2188,7 @@ mlir::Value ScalarExprEmitter::emitDiv(const BinOpInfo 
&ops) {
 mlir::Value ScalarExprEmitter::emitRem(const BinOpInfo &ops) {
   const mlir::Location loc = cgf.getLoc(ops.loc);
   if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
-    CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, ops.fpFeatures);
+    CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, ops.fpFeatures);
     return builder.createFRem(loc, ops.lhs, ops.rhs);
   }
   return cir::RemOp::create(builder, loc, cgf.convertType(ops.fullType),
@@ -2323,7 +2326,7 @@ mlir::Value ScalarExprEmitter::emitAdd(const BinOpInfo 
&ops) {
     cgf.cgm.errorNYI("unsigned int overflow sanitizer");
 
   if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
-    CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, ops.fpFeatures);
+    CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, ops.fpFeatures);
     // Try to form an fmuladd.
     if (mlir::Value fmuladd = tryEmitFMulAdd(loc, ops, builder))
       return fmuladd;
@@ -2371,7 +2374,7 @@ mlir::Value ScalarExprEmitter::emitSub(const BinOpInfo 
&ops) {
       cgf.cgm.errorNYI("unsigned int overflow sanitizer");
 
     if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
-      CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, ops.fpFeatures);
+      CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, ops.fpFeatures);
       // Try to form an fmuladd.
       if (mlir::Value fmuladd =
               tryEmitFMulAdd(loc, ops, builder, /*isSub=*/true))
@@ -2471,7 +2474,7 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
   Expr *subExpr = ce->getSubExpr();
   QualType destTy = ce->getType();
   CastKind kind = ce->getCastKind();
-  CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, ce);
+  CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, ce);
 
   // These cases are generally not written to ignore the result of evaluating
   // their sub-expressions, so we clear this now.
@@ -2745,7 +2748,7 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
   case CK_FloatingCast:
   case CK_FixedPointToFloating:
   case CK_FloatingToFixedPoint: {
-    CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, ce);
+    CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, ce);
     return emitScalarConversion(Visit(subExpr), subExpr->getType(), destTy,
                                 ce->getExprLoc());
   }
@@ -2756,9 +2759,11 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
 
   case CK_PointerToBoolean:
     return emitPointerToBoolConversion(Visit(subExpr), subExpr->getType());
-  case CK_FloatingToBoolean:
+  case CK_FloatingToBoolean: {
+    CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, subExpr);
     return emitFloatToBoolConversion(Visit(subExpr),
                                      cgf.getLoc(subExpr->getExprLoc()));
+  }
   case CK_MemberPointerToBoolean: {
     mlir::Value memPtr = Visit(subExpr);
     return builder.createCast(cgf.getLoc(ce->getSourceRange()),
@@ -2787,6 +2792,8 @@ mlir::Value ScalarExprEmitter::VisitCallExpr(const 
CallExpr *e) {
   if (e->getCallReturnType(cgf.getContext())->isReferenceType())
     return emitLoadOfLValue(e);
 
+  CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, e);
+
   auto v = cgf.emitCallExpr(e).getValue();
   assert(!cir::MissingFeatures::emitLValueAlignmentAssumption());
   return v;
@@ -2900,6 +2907,8 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const 
UnaryOperator *e) {
     auto operVecTy = mlir::cast<cir::VectorType>(oper.getType());
     auto exprVecTy = 
mlir::cast<cir::VectorType>(cgf.convertType(e->getType()));
     mlir::Value zeroVec = builder.getNullValue(operVecTy, loc);
+    if (cir::isFPOrVectorOfFPType(oper.getType()))
+      CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, e);
     return cir::VecCmpOp::create(builder, loc, exprVecTy, cir::CmpOpKind::eq,
                                  oper, zeroVec);
   }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to