aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath
diff options
context:
space:
mode:
authorQing Zhao <qing.zhao@oracle.com>2025-08-14 20:25:55 +0000
committerQing Zhao <qing.zhao@oracle.com>2025-08-15 15:28:10 +0000
commit9e7f8568f751013266d2d1c4c0023ac7618f1b24 (patch)
tree6738a58e1eb3f2ada094eacac38485c67a0b78a1 /libjava/classpath
parentc49bbcad60c016677bdb807580f0a33ee93cb987 (diff)
downloadgcc-9e7f8568f751013266d2d1c4c0023ac7618f1b24.zip
gcc-9e7f8568f751013266d2d1c4c0023ac7618f1b24.tar.gz
gcc-9e7f8568f751013266d2d1c4c0023ac7618f1b24.tar.bz2
Use the counted_by attribute of pointers in array bound checker.
Current array bound checker only instruments ARRAY_REF, and the INDEX information is the 2nd operand of the ARRAY_REF. When extending the array bound checker to pointer references with counted_by attributes, the hardest part is to get the INDEX of the corresponding array ref from the offset computation expression of the pointer ref. I.e. Given an OFFSET expression, and the ELEMENT_SIZE, get the index expression from the OFFSET. For example: OFFSET: ((long unsigned int) m * (long unsigned int) SAVE_EXPR <n>) * 4 ELEMENT_SIZE: (sizetype) SAVE_EXPR <n> * 4 get the index as (long unsigned int) m. gcc/c-family/ChangeLog: * c-gimplify.cc (is_address_with_access_with_size): New function. (ubsan_walk_array_refs_r): Instrument an INDIRECT_REF whose base address is .ACCESS_WITH_SIZE or an address computation whose base address is .ACCESS_WITH_SIZE. * c-ubsan.cc (ubsan_instrument_bounds_pointer_address): New function. (struct factor_t): New structure. (get_factors_from_mul_expr): New function. (get_index_from_offset): New function. (get_index_from_pointer_addr_expr): New function. (is_instrumentable_pointer_array_address): New function. (ubsan_array_ref_instrumented_p): Change prototype. Handle MEM_REF in addtional to ARRAY_REF. (ubsan_maybe_instrument_array_ref): Handle MEM_REF in addtional to ARRAY_REF. gcc/testsuite/ChangeLog: * gcc.dg/ubsan/pointer-counted-by-bounds-2.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-3.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-4.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-5.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds.c: New test.
Diffstat (limited to 'libjava/classpath')
0 files changed, 0 insertions, 0 deletions