[clang] [CIR][NFC] Upstream support for FP environments and RAII options (PR #179121)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 17 09:54:51 PST 2026


================
@@ -956,6 +957,22 @@ LValue CIRGenFunction::makeNaturalAlignAddrLValue(mlir::Value val,
   return makeAddrLValue(addr, ty, baseInfo);
 }
 
+// Map the LangOption for exception behavior into the corresponding enum in
+// the IR.
+static llvm::fp::ExceptionBehavior
+toConstrainedExceptMd(LangOptions::FPExceptionModeKind kind) {
+  switch (kind) {
+  case LangOptions::FPE_Ignore:
+    return llvm::fp::ebIgnore;
+  case LangOptions::FPE_MayTrap:
+    return llvm::fp::ebMayTrap;
+  case LangOptions::FPE_Strict:
+    return llvm::fp::ebStrict;
+  default:
+    llvm_unreachable("unsupported FP exception behavior");
+  }
----------------
andykaylor wrote:

```suggestion
  case LangOptions::FPE_Default:
    llvm_unreachable("expected explicitly initialized exception behavior");
  }
  
  llvm_unreachable("unsupported FP exception behavior");
```
This would be an improvement over the classic codegen handling. We prefer fully covered switches when using enum types so that we are forced to add handling if new enum kinds are added. This also lets us distinguish between the case where the exception behavior option hasn't been properly initialized (`FPE_Default`) and the case where the value became corrupted (anything else).

https://github.com/llvm/llvm-project/pull/179121


More information about the cfe-commits mailing list