-
Notifications
You must be signed in to change notification settings - Fork 168
Closed
Description
Reproducer:
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
unsigned char table[10][3] =
{
{1,0},
{7,6,5},
};
the interesting part is, if we change the first dimension 10
to any number lower, it won't crash.
The crash information comes from:
clangir/clang/lib/CIR/Lowering/LoweringHelpers.cpp
Lines 124 to 125 in 2ca12fe
return mlir::DenseElementsAttr::get(mlir::RankedTensorType::get(dims, type), | |
llvm::ArrayRef(values)); |
where the MLIR will assert the size of values
will be the same with tensor. The shape of the tensor is correct. However, we will insert values to values
in
clangir/clang/lib/CIR/Lowering/LoweringHelpers.cpp
Lines 79 to 115 in 2ca12fe
template <typename AttrTy, typename StorageTy> | |
void convertToDenseElementsAttrImpl(mlir::cir::ConstArrayAttr attr, | |
llvm::SmallVectorImpl<StorageTy> &values) { | |
if (auto stringAttr = mlir::dyn_cast<mlir::StringAttr>(attr.getElts())) { | |
if (auto arrayType = mlir::dyn_cast<mlir::cir::ArrayType>(attr.getType())) { | |
for (auto element : stringAttr) { | |
auto intAttr = mlir::cir::IntAttr::get(arrayType.getEltType(), element); | |
values.push_back(mlir::dyn_cast<AttrTy>(intAttr).getValue()); | |
} | |
return; | |
} | |
} | |
auto arrayAttr = mlir::cast<mlir::ArrayAttr>(attr.getElts()); | |
for (auto eltAttr : arrayAttr) { | |
if (auto valueAttr = mlir::dyn_cast<AttrTy>(eltAttr)) { | |
values.push_back(valueAttr.getValue()); | |
} else if (auto subArrayAttr = | |
mlir::dyn_cast<mlir::cir::ConstArrayAttr>(eltAttr)) { | |
convertToDenseElementsAttrImpl<AttrTy>(subArrayAttr, values); | |
if (mlir::dyn_cast<mlir::StringAttr>(subArrayAttr.getElts())) | |
fillTrailingZeros(subArrayAttr, values); | |
} else if (auto zeroAttr = mlir::dyn_cast<mlir::cir::ZeroAttr>(eltAttr)) { | |
unsigned numStoredZeros = 0; | |
auto nestTy = | |
getNestedTypeAndElemQuantity(zeroAttr.getType(), numStoredZeros); | |
values.insert(values.end(), numStoredZeros, | |
getZeroInitFromType<StorageTy>(nestTy)); | |
} else { | |
llvm_unreachable("unknown element in ConstArrayAttr"); | |
} | |
} | |
// Only fill in trailing zeros at the local cir.array level where the element | |
// type isn't another array (for the mult-dim case). | |
fillTrailingZeros(attr, values); | |
} |
values
with enough elements.
I think we should resize values
in the first place and assign values to the corresponding slot.
Metadata
Metadata
Assignees
Labels
No labels