From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5DDF73858D1E; Wed, 17 Aug 2022 02:26:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DDF73858D1E From: "xgchenshy at 126 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/106635] AARCH64 STUR instruction causes bus error Date: Wed, 17 Aug 2022 02:26:12 +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: xgchenshy at 126 dot com 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: 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, 17 Aug 2022 02:26:12 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106635 --- Comment #6 from Xiaoguang --- (In reply to Richard Earnshaw from comment #5) > Your original code contains (after stripping out the volatile): > u32 temp_32 =3D (u32)status_data_base_addr; > *dst++ =3D temp_32; > data_length++; >=20=20 > if(sizeof(addr_t) =3D=3D 8) { > *dst++ =3D (u32)(((u64)status_data_base_addr)>>32); > data_length++; > } >=20 > Which of course on a 64-bit machine simplifies to=20 >=20 > u32 temp_32 =3D (u32)status_data_base_addr; > *dst++ =3D temp_32; > data_length++; >=20=20 > *dst++ =3D (u32)(((u64)status_data_base_addr)>>32); > data_length++; >=20 > And which the compiler then further simplifies to=20 >=20 > *([unaligned]u64*)dst =3D status_data_base_addr; > data_length +=3D 2; > dst +=3D 2; >=20 > If the location that dst points to is in normal, cachable, memory, then t= his > will be fine. But if you're writing to non-cachable memory, then you mig= ht > get a trap. Thanks Very much for the explaination, Can you tell me why unaligned access only works in normal cachable memory? where does this constraint come from= ?=20 >=20 > the correct fix is to mark dst as volatile in this case. >=20 > void CWLCollectReadRegData(volatile u32* dst,u16 reg_start, u32 > reg_length,u32* > total_length, addr_t status_data_base_addr)=