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

--- Comment #4 from GCC 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:972f653cad2aedcfa901614566506c1c2e668766

commit r15-4729-g972f653cad2aedcfa901614566506c1c2e668766
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Oct 29 09:06:25 2024 +0100

    c: Add __builtin_stdc_rotate_{left,right} builtins [PR117030]

    I believe the new C2Y <stdbit.h> type-generic functions
    stdc_rotate_{left,right} have the same problems the other stdc_*
    type-generic functions had.  If we want to support arbitrary
    unsigned _BitInt(N), don't want to use statement expressions
    (so that one can actually use them in static variable initializers),
    don't want to evaluate the arguments multiple times and don't want
    to expand the arguments multiple times during preprocessing to avoid the
    old tgmath preprocessing bloat, we need a built-in for those.

    The following patch adds those.  And as we need to support rotations by 0
    and tree-ssa-forwprop.cc is only able to pattern recognize with
BIT_AND_EXPR
    for that case (i.e. for power of two widths), the patch just constructs
    LROTATE_EXPR/RROTATE_EXPR right away.  Negative second arguments are
    considered UB, while positive ones are modulo precision.

    2024-10-29  Jakub Jelinek  <ja...@redhat.com>

            PR c/117030
    gcc/
            * doc/extend.texi (__builtin_stdc_rotate_left,
            __builtin_stdc_rotate_right): Document.
    gcc/c-family/
            * c-common.cc (c_common_reswords): Add __builtin_stdc_rotate_left
            and __builtin_stdc_rotate_right.
            * c-ubsan.cc (ubsan_instrument_shift): For {L,R}ROTATE_EXPR
            just check if op1 is negative.
    gcc/c/
            * c-parser.cc: Include asan.h and c-family/c-ubsan.h.
            (c_parser_postfix_expression): Handle __builtin_stdc_rotate_left
            and __builtin_stdc_rotate_right.
            * c-fold.cc (c_fully_fold_internal): Handle LROTATE_EXPR and
            RROTATE_EXPR.
    gcc/testsuite/
            * gcc.dg/builtin-stdc-rotate-1.c: New test.
            * gcc.dg/builtin-stdc-rotate-2.c: New test.
            * gcc.dg/ubsan/builtin-stdc-rotate-1.c: New test.
            * gcc.dg/ubsan/builtin-stdc-rotate-2.c: New test.

Reply via email to