https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71460
--- Comment #9 from Uroš Bizjak <ubizjak at gmail dot com> --- (In reply to jos...@codesourcery.com from comment #8) > It's not correct to use flag_signaling_nans for a fix. > flag_signaling_nans is only for cases where a bit-pattern for a signaling > NaN is interpreted as a floating-point value. It's not where a struct or > union element has floating-point type but is never interpreted as a value > of that type, just the whole aggregate copied. It's completely valid > without flag_signaling_nans to copy a struct that happens to have such a > bit pattern. Indeed. I have removed this condition, and the patch I'm testing is: --cut here-- diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index b807a9a..a719d62 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -10311,9 +10311,25 @@ static bool ix86_member_type_forces_blk (const_tree field, machine_mode mode) { /* Union with XFmode must be in BLKmode. */ - return (mode == XFmode - && (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE - || TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE)); + if (mode == XFmode + && (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE + || TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE)) + return true; + + /* Early exit for XFmode moves, they don't trap + on sNaNs and don't convert sNaNs into qNaNs. */ + if (mode == XFmode) + return false; + + /* DFmode and SFmode moves through X87 stack trap on sNaNs if traps + are turned on or convert sNaNs to qNaNs if traps are turned off. + This violates C11, 6.2.6.1p6, that specifically says that + "[t]he value of a structure or union object is never a trap + representation, even though the value of a member of the structure + or union object may be a trap representation." */ + + return (IS_STACK_MODE (mode) + && RECORD_OR_UNION_TYPE_P (DECL_FIELD_CONTEXT (field))); } rtx --cut here-- > Does the patch (without flag_signaling_nans) help with the bug 58416 case > or not? Using the patched compiler, I get: $ ~/gcc-build/gcc/xgcc -B ~/gcc-build/gcc/ -O2 -m32 -mfpmath=387 pr58416.C $ ./a.out magic=fff0000000000001 copy= fff0000000000001 ... which looks OK to me.