[libc-commits] [libc] 674c6f4 - [libc] Fix add_sub for Emulated Types (#217344)

via libc-commits libc-commits at lists.llvm.org
Thu Aug 20 08:54:52 PDT 2026


Author: Zorojuro
Date: 2026-08-20T15:54:47Z
New Revision: 674c6f4ed07d33b135716d37bf5694985063818a

URL: https://github.com/llvm/llvm-project/commit/674c6f4ed07d33b135716d37bf5694985063818a
DIFF: https://github.com/llvm/llvm-project/commit/674c6f4ed07d33b135716d37bf5694985063818a.diff

LOG: [libc] Fix add_sub for Emulated Types (#217344)

Co-authored-by: OverMighty <its.overmighty at gmail.com>

Added: 
    

Modified: 
    libc/src/__support/FPUtil/generic/add_sub.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/generic/add_sub.h b/libc/src/__support/FPUtil/generic/add_sub.h
index 7f6a6a97877ee..47ffe5f2f6298 100644
--- a/libc/src/__support/FPUtil/generic/add_sub.h
+++ b/libc/src/__support/FPUtil/generic/add_sub.h
@@ -120,10 +120,13 @@ add_or_sub(InType x, InType y) {
 #ifdef LIBC_USE_CONSTEXPR
         InType tmp = y;
 #else
+        // This prevents it from declaring InType as volatile for emulated types
+        using InTypeTemp = cpp::conditional_t<cpp::is_class_v<InType>, InType,
+                                              volatile InType>;
+        InTypeTemp tmp = y;
         // volatile prevents Clang from converting tmp to OutType and then
         // immediately back to InType before negating it, resulting in double
         // rounding.
-        volatile InType tmp = y;
 #endif // LIBC_USE_CONSTEXPR
         if constexpr (IsSub)
           tmp = -tmp;


        


More information about the libc-commits mailing list