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

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 22 20:05:04 PDT 2020


rsmith 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}}
----------------
mibintc wrote:
> 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)
Are you sync'd past commit rG08c8d5bc51c512e605840b8003fcf38c86d0fc96? We had a bug that would incorrectly treat the initializer of `frac` as being in a constant context until pretty recently.

This testcase:

```
int main() {
  const float f = 1.0 / 3.0;
  enum { e = (int)(f * 3) };
}
```

... produces an error under `-frounding-math` but works without `-frounding-math` with recent trunk.


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