https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107846

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:db1405ddf566fe6129328229579b3f98a574b34c

commit r13-6474-gdb1405ddf566fe6129328229579b3f98a574b34c
Author: Jakub Jelinek <ja...@redhat.com>
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 patch
    just takes integral promotion into account in the warning code.

    2023-03-04  Jakub Jelinek  <ja...@redhat.com>

            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 (op0)
            is narrower than type0 and unsigned, use wi::min_precision with
            UNSIGNED and fold_convert op0 to type0 before emitting the warning.

            * gcc.dg/pr107846.c: New test.
  • [Bug c/107846] [13 Regression] ... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to