[all-commits] [llvm/llvm-project] 0352ee: [CodeGenPrepare] Avoid out-of-bounds shift

Björn Pettersson via All-commits all-commits at lists.llvm.org
Thu Feb 3 12:14:02 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0352ee1a225ae3a54f8cda9ead710498a60ff09a
      https://github.com/llvm/llvm-project/commit/0352ee1a225ae3a54f8cda9ead710498a60ff09a
  Author: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
  Date:   2022-02-03 (Thu, 03 Feb 2022)

  Changed paths:
    M llvm/lib/CodeGen/CodeGenPrepare.cpp
    A llvm/test/CodeGen/X86/codegen-prepare-oob-shl.ll

  Log Message:
  -----------
  [CodeGenPrepare] Avoid out-of-bounds shift

AddressingModeMatcher::matchOperationAddr may attempt to shift a
variable by the same amount of steps as found in the IR in a SHL
instruction. This was done without considering that there could be
undefined behavior in the IR, so the shift performed when compiling
could end up having undefined behavior as well.

This patch avoid UB in the codegenprepare by making sure that we
limit the shift amount used, in a similar way as already being done
in CodeGenPrepare::optimizeLoadExt.

Differential Revision: https://reviews.llvm.org/D118602




More information about the All-commits mailing list