aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse-impl.h
diff options
context:
space:
mode:
authorKishan Parmar <kishan@linux.ibm.com>2025-07-31 17:05:02 +0530
committerKishan Parmar <kishan@linux.ibm.com>2025-07-31 17:05:02 +0530
commit647bd0a02789f17ab6e092fff60839d28fd635dc (patch)
tree6872ef7033d06da5799df2e6614922d0f9a54312 /gcc/rust/parse/rust-parse-impl.h
parent51c03570b3e65029fd4ac5d5ace5bddadec7ba9b (diff)
downloadgcc-647bd0a02789f17ab6e092fff60839d28fd635dc.zip
gcc-647bd0a02789f17ab6e092fff60839d28fd635dc.tar.gz
gcc-647bd0a02789f17ab6e092fff60839d28fd635dc.tar.bz2
rs6000: Avoid undefined behavior caused by overflow and invalid shifts
While building GCC with --with-build-config=bootstrap-ubsan on powerpc64le-unknown-linux-gnu, multiple UBSAN runtime errors were encountered in rs6000.cc and rs6000.md due to undefined behavior involving left shifts on negative values and shift exponents equal to or exceeding the type width. The issue was in bit pattern recognition code (in can_be_rotated_to_negative_lis and can_be_built_by_li_and_rldic), where signed values were shifted without handling negative inputs or guarding against shift counts equal to the type width, causing UB. The fix ensures shifts and rotations are done unsigned HOST_WIDE_INT, and casting back only where needed (like for arithmetic right shifts) with proper guards to prevent shift-by-64. 2025-07-31 Kishan Parmar <kishan@linux.ibm.com> gcc: PR target/118890 * config/rs6000/rs6000.cc (can_be_rotated_to_negative_lis): Avoid left shift of negative value and guard shift count. (can_be_built_by_li_and_rldic): Likewise. (rs6000_emit_set_long_const): Likewise. * config/rs6000/rs6000.md (splitter for plus into two 16-bit parts): Fix UB from overflow in addition.
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
0 files changed, 0 insertions, 0 deletions