From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B74C7388C015; Sat, 27 Jun 2020 10:42:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B74C7388C015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1593254554; bh=cXYoGJkzMlA6YIPX9yvF2+blVnhQqGwIYrq2iLJ+DVw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=m+uJOyRG9ZvZw1L2QS80GatoB9q0RRxCy8HABIgnU3skrU0s9o6cRmGJi0vgZx+KQ fAXdxe0vIjxG91n+DrmUS7wTEDNrCH8OJeLKU+bBCt31GJshKQT4zOxR0kBAfqt7SC EuviJPfn8dZcB710Fi3V1VVeDGH9BkySmlPorQPw= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/95903] gcc 10: wrong code with -fwrapv Date: Sat, 27 Jun 2020 10:42:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub 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: Sat, 27 Jun 2020 10:42:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95903 --- Comment #10 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:37995960984ea2222346dd9d168d332cd6f7adf0 commit r11-1685-g37995960984ea2222346dd9d168d332cd6f7adf0 Author: Jakub Jelinek Date: Sat Jun 27 12:38:23 2020 +0200 c-family: Use TYPE_OVERFLOW_UNDEFINED instead of !TYPE_UNSIGNED in pointer_sum [PR95903] For lp64 targets and int off ... ptr[off + 1] is lowered in pointer_sum to *(ptr + ((sizetype) off + (sizetype) 1)). That is fine when signed integer wrapping is undefined (and is not done already if off has unsigned type), but changes behavior for -fwrapv, wh= ere overflow is well defined. Runtime test could be: int main () { char *p =3D __builtin_malloc (0x100000000UL); if (!p) return 0; char *q =3D p + 0x80000000UL; int o =3D __INT_MAX__; q[o + 1] =3D 1; if (q[-__INT_MAX__ - 1] !=3D 1) __builtin_abort (); return 0; } with -fwrapv or so, not included in the testsuite because it requires 4= GB allocation (with some other test it would be enough to have something slightly above 2GB, but still...). 2020-06-27 Jakub Jelinek PR middle-end/95903 gcc/c-family/ * c-common.c (pointer_int_sum): Use TYPE_OVERFLOW_UNDEFINED ins= tead of !TYPE_UNSIGNED check to see if we can apply distributive law and handle smaller precision intop operands separately. gcc/testsuite/ * c-c++-common/pr95903.c: New test.=