forked from OSchip/llvm-project
Emit unsupported error when parsing a DenseElementAttr with an integer type of greater than 64 bits.
DenseElementAttr currently does not support value bitwidths of > 64. This can result in asan failures and crashes when trying to invoke DenseElementsAttr::writeBits/DenseElementsAttr::readBits. PiperOrigin-RevId: 229241125
This commit is contained in:
parent
e0594ce732
commit
06b0bd9651
|
@ -170,6 +170,8 @@ ArrayRef<char> DenseElementsAttr::getRawData() const {
|
|||
/// starting from `rawData`.
|
||||
void DenseElementsAttr::writeBits(char *data, size_t bitPos, size_t bitWidth,
|
||||
uint64_t value) {
|
||||
assert(bitWidth <= 64 && "expected bitWidth to be within 64-bits");
|
||||
|
||||
// Read the destination bytes which will be written to.
|
||||
uint64_t dst = 0;
|
||||
auto dstData = reinterpret_cast<char *>(&dst);
|
||||
|
@ -195,6 +197,8 @@ void DenseElementsAttr::writeBits(char *data, size_t bitPos, size_t bitWidth,
|
|||
/// and put them in the lowest bits.
|
||||
uint64_t DenseElementsAttr::readBits(const char *rawData, size_t bitPos,
|
||||
size_t bitsWidth) {
|
||||
assert(bitsWidth <= 64 && "expected bitWidth to be within 64-bits");
|
||||
|
||||
uint64_t dst = 0;
|
||||
auto dstData = reinterpret_cast<char *>(&dst);
|
||||
auto endPos = bitPos + bitsWidth;
|
||||
|
|
|
@ -766,6 +766,12 @@ TensorLiteralParser::parseElementOrList(llvm::SmallVectorImpl<int> &dims) {
|
|||
if (value.getMinSignedBits() > bitWidth)
|
||||
return p.emitError("tensor literal element has more bits than that "
|
||||
"specified in the type");
|
||||
|
||||
// FIXME: Handle larger than 64-bit types more gracefully.
|
||||
if (bitWidth > 64)
|
||||
return p.emitError("tensor literal element with more than 64-bits is "
|
||||
"not currently supported");
|
||||
|
||||
addToStorage(value.getSExtValue());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -750,6 +750,15 @@ func @elementsattr_toolarge2() -> () {
|
|||
|
||||
// -----
|
||||
|
||||
// FIXME: Handle larger than 64-bit types more gracefully.
|
||||
func @elementsattr_larger_than_64_bits() -> () {
|
||||
^bb0:
|
||||
"fooi67"(){bar: dense<vector<1x1x1xi67>, [[[-5]]]>} : () -> () // expected-error {{tensor literal element with more than 64-bits is not currently supported}}
|
||||
return
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
func @elementsattr_malformed_opaque() -> () {
|
||||
^bb0:
|
||||
"foo"(){bar: opaque<tensor<1xi8>, "0xQZz123">} : () -> () // expected-error {{opaque string only contains hex digits}}
|
||||
|
|
Loading…
Reference in New Issue