From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 29AC43858C54; Mon, 6 Nov 2023 19:54:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29AC43858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1699300451; bh=1hqdBTDKQlPj6P2Qi86t3IvIgamC7WDBkZoayZRtm6U=; h=From:To:Subject:Date:From; b=GLkIjAtU0tBQUnPgMx8uxXTeZOaeMwtlta1qMzTrtjHG93DLU3rumZJbsS2ON0KZK CGnucipFbwGCCkiJ+6HpRNDRE9RK8qOf9ZU8kBJSxK/6jc4Zmy74sHtB6nILnopKsd UCl1iND4HK3+xCCrlJWgtvlMuGKaFNMHt/nyLWWU= From: "vincent.riviere at freesbee dot fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/112413] New: Wrong switch jump table offset Date: Mon, 06 Nov 2023 19:54:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent.riviere at freesbee dot fr 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 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112413 Bug ID: 112413 Summary: Wrong switch jump table offset Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: vincent.riviere at freesbee dot fr Target Milestone: --- In some circumstances, gcc produces bad code for switch instruction. Main goal of the testcase is to force gcc to produce a jump table. $ cat swi.c int g; void f(int i) { switch (i) { case 0: g =3D 6082; break; case 1: g =3D 9332; break; case 2: g =3D 5642; break; case 3: g =3D 1423; break; case 4: g =3D 2152; break; case 5: g =3D 6779; break; case 6: g =3D 7074; break; case 7: g =3D 8280; break; } } $ m68k-linux-gcc -Os -S -o - swi.c -mlong-jump-table-offsets -malign-int #NO_APP .file "swi.c" .text .align 2 .globl f .type f, @function f: move.l 4(%sp),%d0 moveq #7,%d1 cmp.l %d0,%d1 jcs .L1 lsl.l #2,%d0 move.l .L4(%pc,%d0.l),%d0 jmp %pc@(2,%d0:l) .balignw 4,0x284c |Potential bug here .L4: .long .L11-.L4 .long .L10-.L4 .long .L9-.L4 .long .L8-.L4 .long .L7-.L4 .long .L6-.L4 .long .L5-.L4 .long .L3-.L4 .L11: move.l #6082,g .L1: rts .L10: move.l #9332,g jra .L1 ... As the jmp may not be aligned on a multiple of 4, the .balignw directive may introduce a 2-byte filler, causing jmp to use a wrong offset. Same happens with m68k-elf-gcc.=