[all-commits] [llvm/llvm-project] 20667d: [clang][CodeGen] Fix shift-exponent ubsan check fo...

Björn Pettersson via All-commits all-commits at lists.llvm.org
Thu Apr 18 23:12:02 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 20667dbec30354723d6467b833a081db998eb70a
      https://github.com/llvm/llvm-project/commit/20667dbec30354723d6467b833a081db998eb70a
  Author: Björn Pettersson <bjorn.a.pettersson at ericsson.com>
  Date:   2024-04-19 (Fri, 19 Apr 2024)

  Changed paths:
    M clang/lib/CodeGen/CGExprScalar.cpp
    M clang/test/CodeGen/ubsan-shift-bitint.c

  Log Message:
  -----------
  [clang][CodeGen] Fix shift-exponent ubsan check for signed _BitInt (#88004)

Commit 5f87957fefb21d454f2f (pull-requst #80515) corrected some codegen
problems related to _BitInt types being used as shift exponents. But it
did not fix it properly for the special case when the shift count
operand is a signed _BitInt.

The basic problem is the same as the one solved for unsigned _BitInt. As
we use an unsigned comparison to see if the shift exponent is
out-of-bounds, then we need to find an unsigned maximum allowed shift
amount to use in the check. Normally the shift amount is limited by
bitwidth of the LHS of the shift. However, when the RHS type is small in
relation to the LHS then we need to use a value that fits inside the
bitwidth of the RHS instead.

The earlier fix simply used the unsigned maximum when deterining the max
shift amount based on the RHS type. It did however not take into
consideration that the RHS type could have a signed representation. In
such situations we need to use the signed maximum instead. Otherwise we
do not recognize a negative shift exponent as UB.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list