[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
================
@@ -0,0 +1,65 @@
+! Test that -ffpe-trap= is forwarded from the Flang driver to the frontend.
+
+! RUN: %flang -ffpe-trap=invalid,zero,overflow -fsyntax-only -### %s 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-FORWARD %s
+! CHECK-FORWARD: -fc1
+! CHECK-FORWARD-SAME: -ffpe-trap=invalid,zero,overflow
+
+! Test all supported exception types
+! RUN: %flang -ffpe-trap=invalid,zero,overflow,underflow,inexact,denormal -fsyntax-only -### %s 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-ALL %s
+! CHECK-ALL: -fc1
+! CHECK-ALL-SAME: -ffpe-trap=invalid,zero,overflow,underflow,inexact,denormal
+
+! Test a single exception type
+! RUN: %flang -ffpe-trap=invalid -fsyntax-only -### %s 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-SINGLE %s
+! CHECK-SINGLE: -fc1
+! CHECK-SINGLE-SAME: -ffpe-trap=invalid
+
+! Only the last -ffpe-trap= is forwarded to the frontend.
+! RUN: %flang -ffpe-trap=invalid -ffpe-trap=overflow -fsyntax-only -### %s 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-LAST %s
+! CHECK-LAST: -fc1
+! CHECK-LAST-SAME: -ffpe-trap=overflow
+! CHECK-LAST-NOT: -ffpe-trap=invalid
+
+! "none" and an empty list are accepted and disable halting.
+! RUN: %flang_fc1 -ffpe-trap=none -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-OK --allow-empty %s
+! RUN: %flang_fc1 -ffpe-trap= -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-OK --allow-empty %s
+! RUN: %flang_fc1 -ffpe-trap=invalid,none -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-OK --allow-empty %s
+! CHECK-OK-NOT: error:
+
+! On a target without floating-point halting support, the driver warns and still
+! forwards the option (the runtime ignores it at execution time).
+! RUN: %flang --target=powerpc64-ibm-aix -ffpe-trap=invalid -fsyntax-only -### %s 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-WARN %s
+! CHECK-WARN: warning: ignoring '-ffpe-trap=invalid' option as it is not currently supported for target 'powerpc64-ibm-aix'
+! CHECK-WARN: -ffpe-trap=invalid
----------------
tarunprabhu wrote:
If this is intended to check that option is passed to `-fc1`, this might be better
```suggestion
! CHECK-WARN: -fc1
! CHECK-WARN-SAME: -ffpe-trap=invalid
```
https://github.com/llvm/llvm-project/pull/208828
More information about the flang-commits
mailing list