[PATCH] D121122: Set FLT_EVAL_METHOD to -1 when fast-math is enabled.

Zahira Ammarguellat via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 7 07:46:06 PST 2022


zahiraam created this revision.
zahiraam added reviewers: andrew.w.kaylor, aaron.ballman, thakis, rjmccall, fhahn.
Herald added a project: All.
zahiraam requested review of this revision.
Herald added a project: clang.

Currently the control of the eval-method is mixed with fast-math.  FLT_EVAL_METHOD tells the user the precision at which, temporary results
are evaluated but when fast-math is enabled, the numeric values are not     guaranteed to match the source semantics, so the eval-method is
meaningless.
For example, the expression `x + y + z` has as source semantics `(x + y) + z`. FLT_EVAL_METHOD is telling the user at which precision `(x + y)`
is evaluated. With fast-math enable the compiler may choose to evaluate the expression as `(y + z) + x`.

The correct behavior is to set the FLT_EVAL_METHOD to `-1`, to tell the user that the precision of the intermediate values is unknow. 
This patch is doing that.

This patch is also fixing a crash when the `pragma clang fp  eval-method` is given the wrong value (should be source, double, extended).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121122

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/test/CodeGen/eval-method-fast-math.c
  clang/test/Sema/fp-eval-pragma.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121122.413479.patch
Type: text/x-patch
Size: 6417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220307/2f91eb49/attachment.bin>


More information about the cfe-commits mailing list