[PATCH] D88498: [FPEnv] Evaluate initializers in constant rounding mode

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 29 09:02:41 PDT 2020


sepavloff created this revision.
sepavloff added reviewers: rsmith, rjmccall, mibintc.
Herald added a project: clang.
sepavloff requested review of this revision.

Previously initializers were evaluated using rounding mode currently
specified by Sema. If at the same time FP exception behavior was set
to `strict`, compiler failed to compile the following C code:

  struct S { float f; };
  static struct S x = {0.63};

This happened because setting strict behavior set rounding mode to
`dymanic`. In this case the value of initializer depends on the current
rounding mode and it cannot be evaluated in compile time.

Initializers for some objects must be constants. On the other hand using
`dynamic` as rounding mode make no sense. Even in C++ if the initializer
is evaluated dynamically, it happens before execution of `main`, so
there is no possibility to set rounding mode for such initializers. So
if rounding mode is `dynamic` when an initializer is evaluated in some
cases, compiler replaces it with default `tonearest` rounding.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88498

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/test/AST/const-fpfeatures-diag.c
  clang/test/AST/const-fpfeatures-strict.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88498.295011.patch
Type: text/x-patch
Size: 5810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200929/83dfefbc/attachment-0001.bin>


More information about the cfe-commits mailing list