From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E8B0D3858D33; Thu, 14 Mar 2024 00:10:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8B0D3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710375029; bh=xLmRA5kMgP1PKZfjKOTAd3hAwGDyGWyFZ/mgJHLyrCc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JK5mTqSsqo37I0YAFiDxKCnibbRANTnoov5YO+PnGzr7ktvZkjmNc2YrmslLc9Ev5 mSk036JPAs9PQfNnBJq0DwlFq/nKG1Uv1S2STU7j+LhPoQMA5w4m4+zSw4r/v7nZ5R cLY/3UlKlwe9rnP6IorSWn6/gJHjvrkPQf6YApVI= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libgcc/114327] `-CST % 1` is wrong for _BitInt() Date: Thu, 14 Mar 2024 00:10:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libgcc X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW 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: 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=3D114327 --- Comment #2 from Andrew Pinski --- For (ignore the strict aliasing issue): ``` typedef signed _BitInt(256) B; [[gnu::noinline]] B foo (signed char c, B b) { return b % c; } int main (void) { B x =3D foo (1, -3); // -3 % 1 -> 0 // if (x) // __builtin_abort(); signed long *t =3D (signed long *)&x; for(int i =3D 0;i < sizeof(B)/sizeof(long); i++ ) { __builtin_printf("%lx\n", t[i]); } return 0; } ``` We get: ``` 0 ffffffffffffffff ffffffffffffffff ffffffffffffffff ``` Which makes it seem like we are doing the sign extend when the value was the result was 0. Even: > B x =3D foo (3, -3); // -3 % 3 -> 0 Gives the wrong similar result.=