[all-commits] [llvm/llvm-project] 559681: [APInt] provide a safe API for zext value and sext...

Peter Rong via All-commits all-commits at lists.llvm.org
Thu Dec 15 10:06:39 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 55968109d1f9c8655d30928b9fde9993e341c97f
      https://github.com/llvm/llvm-project/commit/55968109d1f9c8655d30928b9fde9993e341c97f
  Author: Peter Rong <PeterRong96 at gmail.com>
  Date:   2022-12-15 (Thu, 15 Dec 2022)

  Changed paths:
    M llvm/include/llvm/ADT/APInt.h
    M llvm/unittests/ADT/APIntTest.cpp

  Log Message:
  -----------
  [APInt] provide a safe API for zext value and sext value.

Currently, APInt::getSExtValue and getZExtValue crashes on values with more than 64 bits.
Users may accidently crash the compiler with this setting when the integer may be i128.
As shown in https://github.com/llvm/llvm-project/issues/59316

In this patch we provide a trySExtValue and tryZExtValue to return an Optional, the user
needs to explictly unwrap it and condsier the possibility where there my no value in it.

Reviewed By: RKSimon

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




More information about the All-commits mailing list