From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 668BC3858413; Tue, 16 Aug 2022 11:15:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 668BC3858413 From: "rearnsha at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/106635] AARCH64 STUR instruction causes bus error Date: Tue, 16 Aug 2022 11:15:54 +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: 11.2.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rearnsha at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: resolution bug_status 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: Tue, 16 Aug 2022 11:15:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106635 Richard Earnshaw changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|WAITING |RESOLVED --- Comment #5 from Richard Earnshaw --- Your original code contains (after stripping out the volatile): u32 temp_32 =3D (u32)status_data_base_addr; *dst++ =3D temp_32; data_length++; if(sizeof(addr_t) =3D=3D 8) { *dst++ =3D (u32)(((u64)status_data_base_addr)>>32); data_length++; } Which of course on a 64-bit machine simplifies to=20 u32 temp_32 =3D (u32)status_data_base_addr; *dst++ =3D temp_32; data_length++; *dst++ =3D (u32)(((u64)status_data_base_addr)>>32); data_length++; And which the compiler then further simplifies to=20 *([unaligned]u64*)dst =3D status_data_base_addr; data_length +=3D 2; dst +=3D 2; If the location that dst points to is in normal, cachable, memory, then this will be fine. But if you're writing to non-cachable memory, then you might= get a trap. the correct fix is to mark dst as volatile in this case. void CWLCollectReadRegData(volatile u32* dst,u16 reg_start, u32 reg_length,= u32* total_length, addr_t status_data_base_addr)=