<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/84648>84648</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `ConditionalOperator` needs to take into account `FPOptionsOverride` set by `#pragma float_control`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          echesakov
      </td>
    </tr>
</table>

<pre>
    When I compile function `foo`

```c
#pragma float_control(precise, on)

float foo(float* x) {
  return x[0] == x[1] ? x[1] : x[0];
}
```

with `clang -O2 -ffast-math -S -o - -emit-llvm foo.c`:

```llvm
define nofpclass(nan inf) float @foo(ptr nocapture noundef readonly %x) local_unnamed_addr #0 {
entry:
  %0 = load float, ptr %x, align 4, !tbaa !5
  ret float %0
}
```

the body of the function is, effectively, folded to

```c
float foo(float* x) {
  return x[0];
}
```

However, the transformation is incorrect under `#pragma float_control(precise, on)` for the following cases:
- `x[0]` is `0.0f` and `x[1]` is `-0.0f`
- `x[0]` is `-0.0f` and `x[1]` is `0.0f`

The value returned from `foo` for both cases is zero with the opposite sign.

In order to resolve this:

1. `ConditionalOperator` in AST should be able to store `FPOptionsOverride` set by `#pragma float_control` in the surrounding context.
2. When CodeGen calls `VisitAbstractConditionalOperator` the stored `FPOptionsOverride` should set `CurFPFeatures` of the `CodeGenFunction`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVU2P2zYQ_TX0ZSCDoiR_HHRw1nCb0wZI0B4DihxZbGiOQFLebH99MZKzuwm627QFDEm0Zh7fezMc6ZTcOSC2onknmuNKT3mg2KIZMOkvdF11ZB_b3wcM8B4MXUbnEfopmOwogNjInkhspJBHIQ-360YuP3Nbq2qM-nzR0HvS-bOhkCN5oXZjROMSCnUHFITav0SZY4HR1W5-FuoAX4Xag9i-W0IAIuYpBvgqmndSNEcQ1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