[clang] [clang] Use constant rounding mode for floating literals (PR #90877)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri May 3 10:15:53 PDT 2024


================
@@ -79,3 +79,16 @@ float V7 = []() -> float {
   0x0.000001p0F);
 }();
 // CHECK: @V7 = {{.*}} float 1.000000e+00
+
+template<float V> struct L {
+  constexpr L() : value(V) {}
+  float value;
+};
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
----------------
erichkeane wrote:

>Does this test address your concern: https://github.com/spavloff/llvm-project/blob/aeb6074444513587924106081213335f73ba6eb0/clang/test/AST/ast-dump-fpfeatures.cpp#L124-L143 ?

That one does not.  I'm more looking for:
```
template<typename T, T f> void foo(){}
#pragma STDC FENV_ROUND FE_DOWNWARD
foo<float, 0.1f>();
#pragma STDC FENV_ROUND FE_UPWARD
foo<float, 0.1f>();
```

Then confirming that there are two separate instantiations of `foo`.

>>All instantiations of a function template use the rounding mode specified in the template definition. Otherwise we would have bad things like two instantiations in different translation units that use different rounding modes. 

Right, that was very much my concern, the ODR implications of that are scary.  So jsut the 1 test above, and I think _I_ am good about this, though having @jcranmer-intel and/or @zahiraam review would also be appreciated.

https://github.com/llvm/llvm-project/pull/90877


More information about the cfe-commits mailing list