[all-commits] [llvm/llvm-project] 706e89: Fix interaction of pragma FENV_ACCESS with other p...

Serge Pavlov via All-commits all-commits at lists.llvm.org
Wed Jun 22 01:15:42 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 706e89db97d3dea63dac1ee2c5a26cb2af9651a2
      https://github.com/llvm/llvm-project/commit/706e89db97d3dea63dac1ee2c5a26cb2af9651a2
  Author: Serge Pavlov <sepavloff at gmail.com>
  Date:   2022-06-22 (Wed, 22 Jun 2022)

  Changed paths:
    M clang/include/clang/Basic/FPOptions.def
    M clang/include/clang/Basic/LangOptions.def
    M clang/include/clang/Basic/LangOptions.h
    M clang/include/clang/Driver/Options.td
    M clang/include/clang/Sema/Sema.h
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/CodeGen/CGCall.cpp
    M clang/lib/CodeGen/CodeGenFunction.cpp
    M clang/lib/Frontend/CompilerInstance.cpp
    M clang/lib/Parse/ParsePragma.cpp
    M clang/lib/Sema/SemaAttr.cpp
    M clang/test/AST/ast-dump-fpfeatures.cpp
    M clang/test/CodeGen/pragma-fenv_access.c

  Log Message:
  -----------
  Fix interaction of pragma FENV_ACCESS with other pragmas

Previously `#pragma STDC FENV_ACCESS ON` always set dynamic rounding
mode and strict exception handling. It is not correct in the presence
of other pragmas that also modify rounding mode and exception handling.
For example, the effect of previous pragma FENV_ROUND could be
cancelled, which is not conformant with the C standard. Also
`#pragma STDC FENV_ACCESS OFF` turned off only FEnvAccess flag, leaving
rounding mode and exception handling unchanged, which is incorrect in
general case.

Concrete rounding and exception mode depend on a combination of several
factors like various pragmas and command-line options. During the review
of this patch an idea was proposed that the semantic actions associated
with such pragmas should only set appropriate flags. Actual rounding
mode and exception handling should be calculated taking into account the
state of all relevant options. In such implementation the pragma
FENV_ACCESS should not override properties set by other pragmas but
should set them if such setting is absent.

To implement this approach the following main changes are made:

- Field `FPRoundingMode` is removed from `LangOptions`. Actually there
  are no options that set it to arbitrary rounding mode, the choice was
  only `dynamic` or `tonearest`. Instead, a new boolean flag
  `RoundingMath` is added, with the same meaning as the corresponding
  command-line option.

- Type `FPExceptionModeKind` now has possible value `FPE_Default`. It
  does not represent any particular exception mode but indicates that
  such mode was not set and default value should be used. It allows to
  distinguish the case:

    {
        #pragma STDC FENV_ACCESS ON
	...
    }

  where the pragma must set FPE_Strict, from the case:

    {
        #pragma clang fp exceptions(ignore)
        #pragma STDC FENV_ACCESS ON
        ...
    }

  where exception mode should remain `FPE_Ignore`.

  - Class `FPOptions` has now methods `getRoundingMode` and
  `getExceptionMode`, which calculates the respective properties from
  other specified FP properties.

  - Class `LangOptions` has now methods `getDefaultRoundingMode` and
  `getDefaultExceptionMode`, which calculates default modes from the
  specified options and should be used instead of `getRoundingMode` and
  `getFPExceptionMode` of the same class.

Differential Revision: https://reviews.llvm.org/D126364




More information about the All-commits mailing list