Skip to content

Commit

Permalink
[SDAG] Don't allow implicit trunc in getConstant()
Browse files Browse the repository at this point in the history
Assert that the passed value is a valid unsigned integer value
for the specified type.

For signed values getSignedConstant() / getSignedTargetConstant()
should be used instead.
  • Loading branch information
nikic committed Nov 25, 2024
1 parent 3699931 commit 45be4ce
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,13 +1638,7 @@ SDValue SelectionDAG::getBoolConstant(bool V, const SDLoc &DL, EVT VT,
SDValue SelectionDAG::getConstant(uint64_t Val, const SDLoc &DL, EVT VT,
bool isT, bool isO) {
EVT EltVT = VT.getScalarType();
assert((EltVT.getSizeInBits() >= 64 ||
(uint64_t)((int64_t)Val >> EltVT.getSizeInBits()) + 1 < 2) &&
"getConstant with a uint64_t value that doesn't fit in the type!");
// TODO: Avoid implicit trunc?
// See https://github.com/llvm/llvm-project/issues/112510.
return getConstant(APInt(EltVT.getSizeInBits(), Val, /*isSigned=*/false,
/*implicitTrunc=*/true),
return getConstant(APInt(EltVT.getSizeInBits(), Val, /*isSigned=*/false),
DL, VT, isT, isO);
}

Expand Down

0 comments on commit 45be4ce

Please sign in to comment.