[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress

Melanie Blower via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 22 14:43:07 PDT 2020


mibintc added inline comments.


================
Comment at: clang/test/Parser/pragma-fenv_access.c:28
+#if defined(CPP) & defined(STRICT)
+//not-expected-error at +3 {{constexpr variable 'frac' must be initialized by a constant expression}}
+//not-expected-note at +2 {{compile time floating point arithmetic suppressed in strict evaluation modes}}
----------------
rsmith wrote:
> mibintc wrote:
> > @rsmith no diagnostic, is this OK?
> Under the new approach from D89360, I would expect no diagnostic with `CONST` defined as `constexpr`, because the initializer is then manifestly constant-evaluated, so should be evaluated in the constant rounding mode.
> 
> With `CONST` defined as merely `const`, I'd expect that we emit a constrained floating-point operation using the runtime rounding mode here. You can test that we don't constant-evaluate the value of a (non-`constexpr`) `const float` variable by using this hack (with `CONST` defined as `const`):
> 
> ```
> enum {
>   e1 = (int)one, e3 = (int)three, e4 = (int)four, e_four_quarters = (int)(frac_ok * 4)
> };
> static_assert(e1 == 1  && e3 == 3 && e4 == 4 && e_four_quarters == 1, "");
> enum {
>   e_three_thirds = (int)(frac * 3) // expected-error {{not an integral constant expression}}
> };
> ```
> 
> (The hack here is that we permit constant folding in the values of enumerators, and we allow constant folding to look at the evaluated values of `const float` variables. This should not be allowed for `frac`, because attempting to evaluate its initializer should fail.)
I'm not seeing the expected-error for e_three_thirds = (int)(frac * 3)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87528/new/

https://reviews.llvm.org/D87528



More information about the cfe-commits mailing list