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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Qing Zhao <[email protected]>:

https://gcc.gnu.org/g:9b3c24577e75356efabcdfe0beaec2a4f0bc6686

commit r16-7934-g9b3c24577e75356efabcdfe0beaec2a4f0bc6686
Author: Qing Zhao <[email protected]>
Date:   Fri Mar 6 18:58:41 2026 +0000

    Fix [PR124230]

    For a pointer array reference that is annotated with counted_by attribute,
    such as:

      struct annotated {
        int *c __attribute__ ((counted_by (b)));
        int b;
      };

      struct annotated *p = setup (10);
      p->c[12] = 2; //out of bound access

    the IR for p->c[12] is:
      (.ACCESS_WITH_SIZE (p->c, &p->b, 0B, 4) + 48) = 2;

    The current routine get_index_from_offset in c-family/c-ubsan.cc cannot
    handle the integer constant offset "48" correctly.

    The fix is to enhance "get_index_from_offset" to correctly handle the
constant
    offset.

            PR c/124230

    gcc/c-family/ChangeLog:

            * c-ubsan.cc (get_index_from_offset): Handle the special case when
            the offset is an integer constant.

    gcc/testsuite/ChangeLog:

            * gcc.dg/ubsan/pointer-counted-by-bounds-124230-char.c: New test.
            * gcc.dg/ubsan/pointer-counted-by-bounds-124230-float.c: New test.
            * gcc.dg/ubsan/pointer-counted-by-bounds-124230-struct.c: New test.
            * gcc.dg/ubsan/pointer-counted-by-bounds-124230-union.c: New test.
            * gcc.dg/ubsan/pointer-counted-by-bounds-124230.c: New test.

Reply via email to