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

    <tr>
        <th>Summary</th>
        <td>
            [libc] unused function `clear_x87_exceptions`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc
      </td>
    </tr>

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

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

<pre>
    While working on the i386 port and debugging an issue with my fenv_t support, I noticed that we're never issuing a `fnclex` instruction.

It looks like 9474ddc3ac8637596f87dd796864353317622672 removed the only call to `clearX87Exceptions`, which was later renamed to `clear_x87_exceptions` in 1c92911e9e1d503c0dfc4367da7f15d0dff50587.

I don't strictly know if `fnclex` is necessary.

Bionic's i386 impl is based on freebsd seems to do so in `fesetexceptflag`, `feholdexcept`, and `feclearexcept` before each `fldenv`.
Bionic's x86_64 impl is based on netbsd and seems to only do so in `feholdexcept`.

musl's i386 and x86_64 impls seems to only do so for `feclearexcept`.

It's not clear to me that it is even necessary? Perhaps the unused function should simply be deleted? Otherwise:

```diff
diff --git a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
index b77178ea69ea..3f227ef75459 100644
--- a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
@@ -122,7 +122,7 @@ LIBC_INLINE uint16_t get_x87_status_word() {
 }
 
 LIBC_INLINE void clear_x87_exceptions() {
-  __asm__ __volatile__("fnclex" : : :);
+ asm("fnclex");
 }
 
 LIBC_INLINE uint32_t get_mxcsr() {
@@ -207,6 +207,7 @@ LIBC_INLINE int clear_except(int excepts) {
 internal::get_x87_state_descriptor(state);
   state.status_word &=
 static_cast<uint16_t>(~internal::get_status_value_for_except(excepts));
+ internal::clear_x87_exceptions();
 internal::write_x87_state_descriptor(state);
 
   uint32_t mxcsr = internal::get_mxcsr();
@@ -230,6 +231,7 @@ LIBC_INLINE int set_except(int excepts) {
   internal::X87StateDescriptor state;
 internal::get_x87_state_descriptor(state);
   state.status_word |= status_value;
+  internal::clear_x87_exceptions();
 internal::write_x87_state_descriptor(state);
 
   uint32_t mxcsr = internal::get_mxcsr();
```
would do what freebsd does.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVkuP46oS_jVkU0pkg22cRRad7o7U0mjuSFdXd3YWNuWY0xgiwEn35vz2I-y8u2c0mlkdKQ9MFcX3wIDwXm0N4orka5I_zcQQOutWRjWvEr0YtFHo_Ky28n31_05phIN1r8pswRoIHYJiZQE76wIII0FiPWy3MSwMKO8HhIMKHfTv0KLZVwH8sIvZhD7CCxgbVIMSQicCHJBQ7hAM7tGNg8c6QIqkNY3GN1IkoIwPbmiCsmZBkieSPEy_LwG0ta8etHpFWGY8k7JhoikLxvNl0ZZcSr4syiJjOWMpLygtOAWHvd2PABCs0e_QCK0h2Dhpo1G47yV_fmtwFyf0pEgi7kOnmg4OwoMWAR04NKKPRS7DqreSV3g9EJSBtFnSZZriElOZJ6xJZNtkrOBS8DbNZSLbNk_ykt8yA2kNoTyAD041Qb_Dq7EHUO2dMh4MNui9cO83BdbKGtUQyv1klup3OmbXwqOMNrYOsfYSPGLvIwtpwdsIOE6AHsPEpNVie5RgDHRWyyly7I0rYIyMGpxDUGNrHQKKphvjWqLZkyJZfAD4VhZVkX2EaDBEhHGCM8rRr1uoN4huROgHry8SxDpXU_lPi7bWfcbmbtmNRY0NMGbFEj1O61mFSAH3aC7GELaBb-g6sfPjmhvMEBm2gxmXNPjODlqCj6jeoUaQqDGgjOP-Ezp0B-WRsIdrDFH88SNV205dsQXz-VYFEIRutKobQjfexd-qOr-Cm823_wWlCd1MYsSeZ7N_6Xd60UH9uyMnDMpIfIOa85SXKIolisWCtZRybHme5UtIk6TIsil5Pp__PtKjDHQ9ff4UOMkSkiUwTykl9JEDoet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