Skip to content

Commit

Permalink
[clang-cl] Increase /fp flag fidelity
Browse files Browse the repository at this point in the history
They were mapped as follows:
- /fp:except to --ftrapping-math
- /fp:except- to --fno-trapping-math
- /fp:strict to --fno-fast-math
- /fp:precise to --fno-fast-math

Let's map them as follows:
- /fp:except to --ffp-exception-behavior=strict
- /fp:except- to --ffp-exception-behavior=ignore
- /fp:strict to --ffp-model=strict
- /fp:precise to --ffp-model=ignore

I believe the changes to /fp:except are technically a no-op but it makes
the mapping a lot clearer. The changes for /fp:strict and /fp:precise are not
no-ops, they now match MSVC's behavior.

While we are here, also add support for /fp:contract by mapping it to
-ffp-contract=on.
  • Loading branch information
majnemer committed Aug 22, 2022
1 parent 27d3321 commit 3d89323
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 5 additions & 6 deletions clang/include/clang/Driver/Options.td
Expand Up @@ -6447,13 +6447,12 @@ def _SLASH_E : CLFlag<"E">, HelpText<"Preprocess to stdout">, Alias<E>;
def _SLASH_external_COLON_I : CLJoinedOrSeparate<"external:I">, Alias<isystem>,
HelpText<"Add directory to include search path with warnings suppressed">,
MetaVarName<"<dir>">;
def _SLASH_fp_except : CLFlag<"fp:except">, HelpText<"">, Alias<ftrapping_math>;
def _SLASH_fp_except_ : CLFlag<"fp:except-">,
HelpText<"">, Alias<fno_trapping_math>;
def _SLASH_fp_contract : CLFlag<"fp:contract">, HelpText<"">, Alias<ffp_contract>, AliasArgs<["on"]>;
def _SLASH_fp_except : CLFlag<"fp:except">, HelpText<"">, Alias<ffp_exception_behavior_EQ>, AliasArgs<["strict"]>;
def _SLASH_fp_except_ : CLFlag<"fp:except-">, HelpText<"">, Alias<ffp_exception_behavior_EQ>, AliasArgs<["ignore"]>;
def _SLASH_fp_fast : CLFlag<"fp:fast">, HelpText<"">, Alias<ffast_math>;
def _SLASH_fp_precise : CLFlag<"fp:precise">,
HelpText<"">, Alias<fno_fast_math>;
def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias<fno_fast_math>;
def _SLASH_fp_precise : CLFlag<"fp:precise">, HelpText<"">, Alias<ffp_model_EQ>, AliasArgs<["precise"]>;
def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias<ffp_model_EQ>, AliasArgs<["strict"]>;
def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
HelpText<"Enable AddressSanitizer">,
Alias<fsanitize_EQ>, AliasArgs<["address"]>;
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Driver/cl-options.c
Expand Up @@ -44,9 +44,11 @@

// RUN: %clang_cl /fp:fast /fp:except -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept %s
// fpexcept-NOT: -menable-unsafe-fp-math
// fpexcept: -ffp-exception-behavior=strict

// RUN: %clang_cl /fp:fast /fp:except /fp:except- -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept_ %s
// fpexcept_: -menable-unsafe-fp-math
// fpexcept_: -ffp-exception-behavior=ignore

// RUN: %clang_cl /fp:precise /fp:fast -### -- %s 2>&1 | FileCheck -check-prefix=fpfast %s
// fpfast: -menable-unsafe-fp-math
Expand All @@ -59,6 +61,10 @@
// RUN: %clang_cl /fp:fast /fp:strict -### -- %s 2>&1 | FileCheck -check-prefix=fpstrict %s
// fpstrict-NOT: -menable-unsafe-fp-math
// fpstrict-NOT: -ffast-math
// fpstrict: -ffp-contract=off

// RUN: %clang_cl /fp:strict /fp:contract -### -- %s 2>&1 | FileCheck -check-prefix=fpcontract %s
// fpcontract: -ffp-contract=on

// RUN: %clang_cl /fsanitize=address -### -- %s 2>&1 | FileCheck -check-prefix=fsanitize_address %s
// fsanitize_address: -fsanitize=address
Expand Down

0 comments on commit 3d89323

Please sign in to comment.