From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4BEB5385840B; Wed, 13 Oct 2021 17:54:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BEB5385840B From: "vajdaz at protonmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/93934] Unnecessary fld of uninitialized float stack variable results in ub of valid C++ code Date: Wed, 13 Oct 2021 17:54:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 7.4.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: vajdaz at protonmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Oct 2021 17:54:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D93934 --- Comment #15 from Zoltan Vajda --- In my special case, I have an embedded realtime application with a lot of FP atithmetic on Intel 32 bit architecture (huge and complex legacy codebase).= FPU exceptions are enabled, so loading an SNaN results in an exception. This is intended, and we will don't want to change this configuration. In this cont= ext the generated ASM code does result in an fld of an uninitialized local variable, where looking on the C++ code such an access should not be possib= le. If the content of the uninitialized local variable happens to be a SNaN by accident (chances are very small, but not zero), an FPU exception happens. = And again, based on the C++ code no FPU exception should be possible (assuming = d is not an SNaN). Here is a synthetic example that triggers the exception by "placing a bomb"= on the stack. https://gcc.godbolt.org/z/aooex6dcT Function place_bomb() has an effect on what happens in func(). That should = not be the case! This is all valid C++ code. This may now accidentally happen in our application. The behavior is unpredictable, because it depends on what previous function calls left on t= he stack. If you change "-march=3Di686" to "-march=3Di386" in the example linked abov= e, everything goes fine.=