[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
Thu Mar 10 13:10:09 PST 2022


zahiraam added inline comments.


================
Comment at: clang/test/CodeGen/eval-method-fast-math.c:83
+#pragma float_control(pop)
+
+int getFPEvalMethod() {
----------------
aaron.ballman wrote:
> What should happen in a case like this?
> ```
> int whatever(float a, float b, float c) {
>   #pragma float_control(precise, off)
>   res = a + b + c;
>   int val = __FLT_EVAL_METHOD__;
>   #pragma float_control(precise, on)
>   return __FLT_EVAL_METHOD__;
> }
> ```
> I would expect that `int val` would hold `-1` and the return statement would return `0`?
This test case is failing with this error (at the second pragma):

  t1.cpp:9:11: error: '#pragma float_control' can only appear at file scope or at
      the start of a compound statement
  #pragma float_control(precise, off)
          ^
  1 error generated.

Tried this:

  int whatever(float a, float b, float c) {
  #pragma float_control(precise, off)
  res = a + b + c;
  int val =__FLT_EVAL_METHOD__;
  {
  #pragma float_control(precise, on)
  return __FLT_EVAL_METHOD__;
  }
}

This generated these last IR instructions:
  store float %add1, float* @"?res@@3MA", align 4
  store i32 -1, i32* %val, align 4
  ret i32 -1

Not sure if this is correct. I guess the first pragma (off) didn't popped, so it's still on?  But inside the scope of the second pragma the first pragma shouldn't be visible? Not sure what should happen here. 


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

https://reviews.llvm.org/D121122



More information about the cfe-commits mailing list