From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 53DC73857C5A; Sat, 4 Mar 2023 09:15:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53DC73857C5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677921318; bh=yNZ4yY17ADuQsNS/xurzRAqjBE2geo09BAEWU9kJLbY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZR4djqb2oFB1tpNOa9btHrlWacpdVIC0DpR8iClJmBC21iAsavsaLq31C4yEzOmuG tgMH/hFyQ8a5EaKP3QDYaU1rv8HgM6Dyuri+C/2q4v/wj1holohjPiDyd8AxkmF1KY 3dkRX9whCeLJgdW+ksUoro0Xln62gZyYHzqx8mOU= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107846] [13 Regression] error: result of '8000 << 8' requires 22 bits to represent, but 'short int' only has 16 bits Date: Sat, 04 Mar 2023 09:15:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 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=3D107846 --- Comment #11 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:db1405ddf566fe6129328229579b3f98a574b34c commit r13-6474-gdb1405ddf566fe6129328229579b3f98a574b34c Author: Jakub Jelinek Date: Sat Mar 4 10:14:33 2023 +0100 c-family: Account for integral promotions of left shifts for -Wshift-overflow warning [PR107846] The r13-1100-gacb1e6f43dc2bbedd124 change added match.pd narrowing of left shifts, and while I believe the C++ FE calls the warning on unfolded trees, the C FE folds them and so left shifts where integral promotion happened and so were done in int type will be usually narrowed back to char/signed char/unsigned char/short/unsigned short left shifts if the shift count is constant and fits into the precision of the var being shifted. One possibility would be to restrict the match.pd optimization to GIMPLE only, another don't fold in C FE before this warning (well, we need to fold the shift count operand to constant if possible), the following pa= tch just takes integral promotion into account in the warning code. 2023-03-04 Jakub Jelinek PR c/107846 * c-warn.cc: Include langhooks.h. (maybe_warn_shift_overflow): Set type0 to what TREE_TYPE (op0) promotes to rather than TREE_TYPE (op0) itself, if TREE_TYPE (o= p0) is narrower than type0 and unsigned, use wi::min_precision with UNSIGNED and fold_convert op0 to type0 before emitting the warn= ing. * gcc.dg/pr107846.c: New test.=