[llvm] [APInt] Assert correct values in APInt constructor (PR #80309)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 05:09:54 PST 2024
================
@@ -106,11 +106,26 @@ class [[nodiscard]] APInt {
/// \param numBits the bit width of the constructed APInt
/// \param val the initial value of the APInt
/// \param isSigned how to treat signedness of val
- APInt(unsigned numBits, uint64_t val, bool isSigned = false)
+ /// \param implicitTrunc allow implicit truncation of non-zero/sign bits of
+ /// val beyond the range of numBits
+ APInt(unsigned numBits, uint64_t val, bool isSigned = false,
+ bool implicitTrunc = false)
: BitWidth(numBits) {
+ if (!implicitTrunc) {
+ if (BitWidth == 0) {
+ assert(val == 0 && "Value must be zero for 0-bit APInt");
----------------
RKSimon wrote:
Is it worth putting the if-else conditions inside the assert directly?
https://github.com/llvm/llvm-project/pull/80309
More information about the llvm-commits
mailing list