From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 519C83857C40; Fri, 21 Oct 2022 05:21:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 519C83857C40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666329710; bh=UN1JIH15vFNES79P/66fZY+/nwhEVs1tYiEikWSrhUY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=i52xU2b6m8+Ks0PZMTtCM7dzc6kaVi92lSh6HJnC02dcC0YekrylJ8y1yWUnZdlEg SlpilcyQTy94y297EjfgkatisBdUrkZSv3xKYy6jTRHgPn1N4vjOavUfN1OVeq4wU9 ihYPp4SLDLTOJ881mTg+hYaa3ctwI/tFm8HoHV7I= From: "yy172179 at 163 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/107339] RISC V -mstrict-align Date: Fri, 21 Oct 2022 05:21:42 +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: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yy172179 at 163 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107339 --- Comment #2 from yy --- (In reply to Andrew Pinski from comment #1) > The code is broken. >=20 > uint32_t here is aligned to 32bits and you access it via that type. >=20 >=20 > this is the correct fix: >=20 >=20 > typedef uint32_t uint32_t_ua __attribute__((aligned(1))); >=20 > void tttt (misalign_t* t){ >=20 > printf("%x\n",(*(const uint32_t_ua *)&t->rseq[0])); > printf("%x\n",(*(const uint32_t_ua *)&t->rseq[1])); > } (In reply to Andrew Pinski from comment #1) > The code is broken. >=20 > uint32_t here is aligned to 32bits and you access it via that type. >=20 >=20 > this is the correct fix: >=20 >=20 > typedef uint32_t uint32_t_ua __attribute__((aligned(1))); >=20 > void tttt (misalign_t* t){ >=20 > printf("%x\n",(*(const uint32_t_ua *)&t->rseq[0])); > printf("%x\n",(*(const uint32_t_ua *)&t->rseq[1])); > } Maybe I didn't make the problem clear. To add, I think the non aligned addr= ess "lw" will be converted to "lbu" to access this address indirectly. Change t= he above code parameters to the structure, and the situation I think is correct will occur. #include typedef struct __attribute__((packed)) misalign { uint8_t rseq[16]; uint8_t type; uint8_t cnt; } misalign_t; void tttt (misalign_t t){ printf("%x\n",(*(const uint32_t*)&t.rseq[0])); printf("%x\n",(*(const uint32_t*)&t.rseq[1])); } int main() { misalign_t abc; misalign_t *test=3D&abc; tttt(abc); while(1);=20 }=