[Bug target/93934] Unnecessary fld of uninitialized float stack variable results in ub of valid C++ code
ubizjak at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Oct 14 08:42:26 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93934
--- Comment #18 from Uroš Bizjak <ubizjak at gmail dot com> ---
The following patch fixes the PR, see the comment inline:
--cut here--
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 6e2b7920d2b..b87490fe544 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -4094,6 +4094,15 @@ ix86_expand_fp_movcc (rtx operands[])
&& !TARGET_64BIT))
return false;
+ /* Disable SFmode and DFmode x87 FCMOV with trapping math
+ to prevent speculative load using FLDL/FLDS from uninitialized
+ memory location, which can contain sNaN value. FLDL/FLDS traps
+ on sNaN, see PR93934. */
+
+ if ((mode == SFmode || mode == DFmode)
+ && flag_trapping_math)
+ return false;
+
/* The floating point conditional move instructions don't directly
support conditions resulting from a signed integer comparison. */
--cut here--
More information about the Gcc-bugs
mailing list