<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/86304>86304</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Casts are incorrect in the presence of FLT_EVAL_METHOD
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
AaronBallman
</td>
</tr>
</table>
<pre>
C23 6.5.5p7 says: "If the value of the expression is represented with greater range or precision than required by the type named by the cast (6.3.1.8), then the cast specifies a conversion even if the type of the expression is the same as the named type and removes any extra range and precision."
(This wording also exists in C99 but was a footnote then.)
It seems that `#pragma clang fp eval_method` does not properly implement this. Consider:
```
#pragma clang fp eval_method(double)
_Static_assert((float)(123.0F * 2.0F) == (float)246.0F, "");
```
The AST dump for this is:
```
TranslationUnitDecl
`-StaticAssertDecl <line:2:2, col:60> col:2
|-ImplicitCastExpr <col:17, col:50> '_Bool' <IntegralToBoolean> FPEvalMethod=1
| `-BinaryOperator <col:17, col:50> 'int' '==' FPEvalMethod=1
| |-ImplicitCastExpr <col:17, col:38> 'double' <FloatingCast> FPEvalMethod=1
| | `-CStyleCastExpr <col:17, col:38> 'float' <FloatingCast> FPEvalMethod=1
| | `-ParenExpr <col:24, col:38> 'double'
| | `-BinaryOperator <col:25, col:34> 'double' '*' FPEvalMethod=1
| | |-ImplicitCastExpr <col:25> 'double' <FloatingCast> FPEvalMethod=1
| | | `-FloatingLiteral <col:25> 'float' 1.230000e+02
| | `-ImplicitCastExpr <col:34> 'double' <FloatingCast> FPEvalMethod=1
| | `-FloatingLiteral <col:34> 'float' 2.000000e+00
| `-ImplicitCastExpr <col:43, col:50> 'double' <FloatingCast> FPEvalMethod=1
| `-CStyleCastExpr <col:43, col:50> 'float' <NoOp> FPEvalMethod=1
| `-FloatingLiteral <col:50> 'float' 2.460000e+02
`-StringLiteral <col:58> 'NULL TYPE' lvalue ""
```
(https://godbolt.org/z/MGsdc4hzM)
Note that the C-style cast to `float` exists in the AST but is immediately undone by the implicit cast back to `double` due to the evaluation method. I believe the implicit casts are incorrect.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVt9z4jYQ_mvEy0488gqweeCBQGgzk9zdzHGd6VNG2AuolSVXEiTcX9-R7JD0wpHrtYwB69f37bcraVd6r7aGaMpG12y0GMh92Fk3nUlnzbXUupFmsLb1cTpHAeNslI3aArw8eiZmwBBvNxB2BAep9wS2a9BT68h7ZQ0oD45ii0ygGh5V2MHWkQzkwEmzJbAOWkeVStPDThpw9NdeOaphfUxw4dgSGNm89FTSB2BYjjOR5VnJcMJwHkfMy7BvqVIbRR4kVNYcyCUGOpABtXkBPmtz7PGyIZDde8ee5ktTg6PGHiKyOQI9BSd7LXHsJCZjiIwvGJ_1v1iudsrDo3W1MluQ2lugJ-WDB2VgPpnAeh_gUUaLN9YGYwMlUVkU-ArpNoAnaqJpMgAbc4aidXLbSKi0NFvYtEAHqR8aCjtbszGH2pIHYwO0zrbk9BFU02pqyAQIO-UzmFvjVU2OiWd7x7x_UhPeIcGytvu1ppOt8PA5yKCqB-k9ucCwZFhutJUhxavMUWR8CQxngBlfMpwAEwsmFvBqHg7HaWwe91p6JkxcnzVwtSOYfV5BvW9a2FiXdIHy3xO0ctJ4LYOy5otRYUGVPs276kyfJcvjCDAx18oQEzNMX5xDZTUTszFn4qZ_7-MNwIr51W3TalWpMJc-3Dy1LkJ00_LiZfkoLWdYPFxbqxkWcdqtCbR1Uq9s7CRp4pzlp5uD1Pedt8Uif8UV98DVtTLSHT-25GSw77EpExIXFp3PY-MSwb-RJMqe5HlDJE3LGFFltnHte3JeRM0_h6OmH-TrN81P0kEi_CQdmX9y4fCStnNAcDEgOHqFN3zrKywYzn4oINB9LocGR_9POE5cSdzz-jsVyEl9hu4UjTxDwTnnxPCa43eBx_yCiHN--nkRcFnCiewkATPOTxL4N7AXDR-KM6fvP4iAi8fiLNvrY_HBfmx_h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