From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A8436385E001; Sun, 29 Mar 2020 14:23:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8436385E001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1585491785; bh=eBgrTCebI7OOB9DuWHMGMrgO6FSVWE3FkbEfDSY4L7s=; h=From:To:Subject:Date:From; b=GjFXmTLZP1x0BccRSIUuM4x5kwxjgTSr8sMZAVhp4VeaHBzsiu94yzfHB56atnSTe X/D7np6Ll39xr27SnR8ehFiKV/qUUo5lwJKIKup5TSmiuZderxIzJmQQXrXkjPdwjf HFk690h5oUM7nxM3ocUSz/yYgYLDOfR756QeizUk= From: "petro.karashchenko at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/94387] New: Excess read instructions are generated in case of writing to fields of volatile + packed type (structure) Date: Sun, 29 Mar 2020 14:23:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 9.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: petro.karashchenko at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: 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: Sun, 29 Mar 2020 14:23:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94387 Bug ID: 94387 Summary: Excess read instructions are generated in case of writing to fields of volatile + packed type (structure) Product: gcc Version: 9.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: petro.karashchenko at gmail dot com Target Milestone: --- Created attachment 48140 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48140&action=3Dedit preprocessed file Excess read instructions are generated when access members of volatile + pa= cked types (structures): test.c: ---------- #include typedef volatile struct type1_s { uint32_t a1; uint8_t a2; uint8_t a3; uint8_t a4; uint8_t a5; } __attribute__((packed)) type1_t; typedef volatile struct { uint32_t b1; uint32_t b2; } __attribute__((packed)) type2_t; typedef volatile struct type3_s { type1_t h1; volatile union { uint8_t b[24]; type2_t c1; } __attribute__((packed)) h2; } __attribute__((packed)) type3_t; typedef volatile struct type4_s { uint32_t x1; uint8_t x2; uint16_t x3; uint8_t x4; uint8_t x5; uint8_t x6; } __attribute__((packed)) type4_t; static void my_func2(type3_t *p0, type4_t *p1) ; int my_func1(uint8_t *p0, uint8_t *p1) { type3_t *i =3D (type3_t *)p0; type4_t *o =3D (type4_t *)p1; my_func2(i, o); return 0; } static void my_func2(type3_t *p0, type4_t *p1) { p1->x1 =3D 0xFFFFFF01; p1->x6 =3D 1; p1->x2 =3D 2; p1->x4 =3D p0->h1.a3; p1->x5 =3D p0->h1.a4; p1->x3 =3D 0; } ---------- arceb-elf32-gcc -save-temps -Wall -Wextra -c -mcpu=3Darc600 -mtune=3Darc600 -mbig-endian -mmul64 test.c -Os ---------- Disassembly: .global my_func1 .type my_func1, @function my_func1: ldb_s r2,[r1] mov r2,-1 ;6 stb_s r2,[r1] ldb_s r3,[r1,1] stb_s r2,[r1,1] ldb_s r3,[r1,2] stb_s r2,[r1,2] ldb_s r2,[r1,3] mov_s r3,1 ;0 stb_s r3,[r1,3] stb_s r3,[r1,9] mov_s r3,2 stb_s r3,[r1,4] ldb_s r3,[r0,5] mov_s r2,0 ;0 stb_s r3,[r1,7] ldb_s r0,[r0,6] stb_s r0,[r1,8] ldb_s r0,[r1,5] stb_s r2,[r1,5] ldb_s r0,[r1,6] stb_s r2,[r1,6] mov_s r0,0 ;0 j_s [blink] .size my_func1, .-my_func1 ---------- Expected disassembly: .global my_func1 .type my_func1, @function my_func1: mov r2,-1 ;6 stb_s r2,[r1] stb_s r2,[r1,1] stb_s r2,[r1,2] mov_s r3,1 ;0 stb_s r3,[r1,3] stb_s r3,[r1,9] mov_s r3,2 stb_s r3,[r1,4] ldb_s r3,[r0,5] mov_s r2,0 ;0 stb_s r3,[r1,7] ldb_s r0,[r0,6] stb_s r0,[r1,8] stb_s r2,[r1,5] stb_s r2,[r1,6] mov_s r0,0 ;0 j_s [blink] .size my_func1, .-my_func1 ---------- I have checked same code compilation with: arm-none-eabi-gcc -save-temps -Wall -Wextra -c -mcpu=3Darm7tdmi -mthumb tes= t.c -Os The result is pretty much the same, so it is not architecture dependent bug= .=