[libc-commits] [libc] [libc] Keep the compiler from folding the inputs of floating point tests (PR #236613)

via libc-commits libc-commits at lists.llvm.org
Thu Nov 5 14:49:39 PST 2026


================
@@ -175,6 +176,23 @@ CFPMatcher<T, C> getMatcherComplex(T expectedValue) {
   return CFPMatcher<T, C>(expectedValue);
 }
 
+// Returns its argument as a value the compiler cannot see through. A call on a
+// constant that is inlined, as it is under LTO, is otherwise folded at compile
+// time, which skips the exception flags, the rounding mode and the flush or
+// denormals-are-zero mode that tests of floating point functions are there to
+// check.
+template <typename T> LIBC_INLINE T opaque(T value) {
+#ifdef LIBC_COMPILER_IS_MSVC
+  // MSVC has no inline assembly on every target; a volatile object cannot be
+  // folded either.
+  volatile T copy = value;
----------------
lntue wrote:

+1 on just use volatile for all configs.

https://github.com/llvm/llvm-project/pull/236613


More information about the libc-commits mailing list