[all-commits] [llvm/llvm-project] 9063da: [flang][flang-rt] Add -ffpe-trap= to set the initi...
Vineet Kumar via All-commits
all-commits at lists.llvm.org
Wed Aug 5 05:27:13 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 9063da54488c147b5fd9c51128dcb8682632dd1c
https://github.com/llvm/llvm-project/commit/9063da54488c147b5fd9c51128dcb8682632dd1c
Author: Vineet Kumar <173554+vntkmr at users.noreply.github.com>
Date: 2026-08-05 (Wed, 05 Aug 2026)
Changed paths:
M clang/include/clang/Options/FlangOptions.td
M clang/lib/Driver/ToolChains/Flang.cpp
M clang/test/Driver/gfortran.f90
M flang-rt/lib/runtime/exceptions.cpp
A flang-rt/test/Driver/fpe-trap-exec-denormal.f90
A flang-rt/test/Driver/fpe-trap-exec-divzero.f90
A flang-rt/test/Driver/fpe-trap-exec-inexact.f90
A flang-rt/test/Driver/fpe-trap-exec-overflow.f90
A flang-rt/test/Driver/fpe-trap-exec-underflow.f90
A flang-rt/test/Driver/fpe-trap-exec.f90
M flang/docs/ReleaseNotes.md
M flang/include/flang/Lower/LoweringOptions.def
M flang/include/flang/Optimizer/Builder/Runtime/Main.h
M flang/include/flang/Runtime/exceptions.h
M flang/include/flang/Support/LangOptions.def
M flang/include/flang/Support/LangOptions.h
M flang/lib/Frontend/CompilerInvocation.cpp
M flang/lib/Lower/Bridge.cpp
M flang/lib/Optimizer/Builder/Runtime/Main.cpp
A flang/test/Driver/fpe-trap.f90
A flang/test/Lower/fpe-trap-nonmain.f90
A flang/test/Lower/fpe-trap.f90
Log Message:
-----------
[flang][flang-rt] Add -ffpe-trap= to set the initial FP exception halting mode (#208828)
Implement the gfortran-style `-ffpe-trap=<list>` option, which sets the
initial floating-point exception halting mode for the main program unit.
The Fortran 2023 standard (17.6) permits the initial halting mode to be
processor defined, so honoring this at program start is conforming.
`<list>` is a comma-separated set of exception mnemonics: `invalid`,
`zero`, `overflow`, `underflow`, and `inexact`, corresponding to the
IEEE_FLAG_TYPE values IEEE_INVALID, IEEE_DIVIDE_BY_ZERO, IEEE_OVERFLOW,
IEEE_UNDERFLOW, and IEEE_INEXACT. As a non-standard, gfortran-compatible
extension, `denormal` halts on the x86 denormal-operand exception. An
empty list or the value `none` disables halting, and the last
`-ffpe-trap=` on the command line wins (allowing an earlier request to
be overridden).
Changes by component:
- clang/Driver: give `-ffpe-trap=` FlangOption/FC1Option visibility and
a one-line HelpText plus a detailed DocBrief (moved into f_Group);
forward the flag to -fc1. Emit a target-based warning when halting
control is unavailable (non-x86 and non-Linux targets), and a
denormal-specific warning on non-x86 targets. The check is intentionally
conservative and only ever under-warns; the runtime remains
authoritative.
- flang/Frontend: parse the list into a LangOptions bitmask
(FPExceptionTrapKind), error on unknown mnemonics, and propagate the
mask to the lowering options.
- flang/Lower: genMain() injects a call to _FortranAEnableFPETraps into
the main program unit only (after ProgramStart, before _QQmain), so the
mode persists across procedures as required by F2023 17.6.
- flang-rt: add EnableFPETraps(), which enables halting only for the
exceptions whose halting control is supported on the target
(IEEE_SUPPORT_HALTING, F2023 17.11.40); it is a no-op elsewhere.
Testing:
- Driver tests for forwarding, "none"/empty, last-wins, bad-argument
errors, and the unsupported-target / denormal warnings.
- FIR lowering tests for the emitted call and constant mask, including a
negative test that a non-main compilation unit emits no call.
- flang-rt execution tests that verify each exception (invalid, zero,
overflow, underflow, inexact, denormal) actually terminates the program
with SIGFPE, plus a selectivity test that an unrelated enabled trap does
not halt. The denormal execution test is gated to x86.
These changes were generated with the assistance of AI tooling and have
been reviewed, tested, and validated by the author.
Resolves #198657
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list