[flang-commits] [clang] [flang] [llvm] [flang][flang-rt] Add -ffpe-trap= to set the initial FP exception halting mode (PR #208828)
Tarun Prabhu via flang-commits
flang-commits at lists.llvm.org
Wed Jul 22 07:33:04 PDT 2026
================
@@ -1485,6 +1485,46 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
opts.FastRealMod = false;
}
+ // Only the last -ffpe-trap= on the command line is effective. The list is a
+ // comma-separated set of exception mnemonics. The mnemonics "invalid",
+ // "zero", "overflow", "underflow", and "inexact" correspond to the Fortran
+ // 2023 IEEE_FLAG_TYPE values IEEE_INVALID, IEEE_DIVIDE_BY_ZERO,
+ // IEEE_OVERFLOW, IEEE_UNDERFLOW, and IEEE_INEXACT (F2023 17.2). The mnemonic
+ // "denormal" is a non-standard, gfortran-compatible extension (subnormal is
+ // an IEEE_FEATURES feature, not an exception flag). The mnemonic "none", as
+ // well as an empty list, requests no halting, allowing a later -ffpe-trap= to
+ // override an earlier one.
+ if (const llvm::opt::Arg *a =
+ args.getLastArg(clang::options::OPT_ffpe_trap_EQ)) {
+ using LangOptions = Fortran::common::LangOptions;
+ llvm::StringRef val = a->getValue();
+ unsigned traps = 0;
+ llvm::SmallVector<llvm::StringRef> trapList;
+ val.split(trapList, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+ for (llvm::StringRef trap : trapList) {
+ if (trap == "none") {
+ // Reset to no halting; a later mnemonic can re-enable.
+ traps = 0;
+ continue;
+ }
+ unsigned bit = llvm::StringSwitch<unsigned>(trap)
----------------
tarunprabhu wrote:
nit: Could we rename this to something other than "bit"? I understand that the result is a bitmask, but the term "flag" seems more appropriate given the context of a driver. But this is just me viciously nit-picking.
https://github.com/llvm/llvm-project/pull/208828
More information about the flang-commits
mailing list