<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69717>69717</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Problems with float_control pragma stack in Clang 17.x
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
regression
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
spavloff
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tru
</td>
</tr>
</table>
<pre>
When working on integrating Clang 17 in our engine we noticed that we were getting some errors when we used `#pragma float_control`, specifically the last `pop` resulted in the following error:
```
pipeline\packages\graphics\GraphicCore\src\graphic\tools\meshtools.cpp(2362,9): error: #pragma float_control(pop, ...) failed: stack empty [-Werror,-Wignored-pragmas]
2362 | #pragma float_control(pop)
| ^
1 error generated.
```
I first thought this was a new warning so I dumped the preprocessed files to see if there was an "imbalance", here is the result:
```
16:#pragma float_control(precise, on, push)
76314:#pragma float_control( push )
76341:#pragma float_control( pop )
306286:#pragma float_control(precise, off, push)
306297:#pragma float_control(pop)
306392:#pragma float_control(precise, off, push)
306403:#pragma float_control(pop)
744987:#pragma float_control(pop)
```
As you see they are balanced.
I added some debug information in `Sema::ActOnPragmaFloatControl` and noticed that the stack gets randomly reset between calls:
```
float_control(push|set)
stack: 1
float_control(push)
stack: 1
float_control(pop)
stack: 0
float_control(push|set)
stack: 1
float_control(pop)
stack: 0
float_control(push|set)
stack: 1
float_control(pop)
stack: 0
float_control(pop)
```
I noticed that there were some changes by @spavloff in Clang 17 around these and then traced down the following two commits:
https://github.com/llvm/llvm-project/commit/0baf85c331090fbe2d2b42214ed0664d55feb0b5
https://github.com/llvm/llvm-project/commit/cc006acdd6d7280a85c63fe375a4c9d1738e3fcd
If I revert these two the stack is behaving as **I** expect it to behave.
I have tried to make a smaller reproducer, but there is probably something missing because just doing several push/pops nested in a single C++ with some headers doesn't reproduce the problem. So it's probably down to something I am missing with the set of patches.
So I need to understand if this is something wrong with our code or a bug in clang.
I have tested both 17.0.3 and HEAD with the same issues.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVktz4ygQ_jX40hUVQi_r4IPjjHdz2qmawxy3ELQkJghUgOLxv98COXEyj0y2Zg_rculF0_3x9Uc33Hs1GMQdqW4JY37mj9r2PWGMVHcbvoTRul1wy6az8rz7PKKBk3UPygxgDSgTcHA8xNeD5maAvAFlwC4O0AzKIJwQjA1KoIQw8hDfT-gQBgxpmrcTAjpnnYdTco-weJRAakpYMTs-TBx6bXn4W1gTnNVp5AB-RqF6JbjWZwgjguY-xGmznUlNwaFfdEAZAcXh3mptTzFmCkeKPaF3hD5da3r5p9dZzaiVQVIdZi4e-ICeVIfB8XlUIj7-sT4erIs23onrMKkOwVodrSb0Y3rOxDwTtmVFzQg7tIS1pNg_A4GfrZRt42LYAbIsI6yFniuNMs7wgYsHwGkOZyDV7c3n1Rc73HxWg7EO5c3q0ZPqbl0TxOhAmsOvwrUX-_RL9tWH9VO-QoYBDToeUGY_ZG-93kOvnA8QRrsMY7wrDyfugYPBE5y4M6sC4B7kMs1JIgizw9lZgT6qoFcaPQQLHhFUHw0crk4MEMbU1HHNjcCoWHaANKx8crQK4O0853Uc_zkdDoXyGD1bE6_z4sdngpq6yMs35yd7eDmhzH8xwc5X-4LWbPt-hHHffgMxemibtz28SHlB66JlvxmwpMW7AzZl2W7fj--HOtt7ONslKSSMeAbuEC6qkBm8ViSXEuVadCR2ywDK9NZNPKhUzmL5-IQTj4CK_V6Ev8zHhOoYQR2e6w9wI1_XtSi4dU8OGDw4bqSd9DmKEAN0GE6IBmKx8m8r8rvlR3abg8fwzEKKE4tA_saUdxu_oPfZ9j_E8j9y_ysh3X-XUnfpVkkwYuRmQA_dGUhJn1plVM1z7-POLiaVMY9JIyG2tOB4dCrt6dtOFE4WhJ0mFb5VxRjCnL6xI2HHQYVx6TJhJ8KOWj8-3W5mZ7-gCIQdVzeEHWnH-20liiKnLe07ZJJ1JWN5iZLWdSmrqseOdtXvxh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