aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
diff options
context:
space:
mode:
authorDudeldu <mustermann.informatik@gmail.com>2023-10-20 15:27:11 +0200
committerGitHub <noreply@github.com>2023-10-20 15:27:11 +0200
commit75d6f508f86026a0eb938ff9df5afc7a1dcf6ec3 (patch)
tree28f1b5bfe8bb60879430a13a3abe58da6c88697c /llvm/lib/ExecutionEngine/ExecutionEngine.cpp
parent97e06a0d83a55ff67e5fd0c7328233c44415de33 (diff)
downloadllvm-75d6f508f86026a0eb938ff9df5afc7a1dcf6ec3.zip
llvm-75d6f508f86026a0eb938ff9df5afc7a1dcf6ec3.tar.gz
llvm-75d6f508f86026a0eb938ff9df5afc7a1dcf6ec3.tar.bz2
[Interpreter] Add initialization of array members (#66172)
Currently, the interpreter does not initialize `undef` constants of aggregate types correctly (with respect to arrays). The initialization of the array elements is skipped although it is valid to directly write to them. Instructions like `insertvalue {i32, [4 x i32]} undef, i32 1, 1, 2` therefore lead to a crash. This is fixed by initializing array values just as fixed-size vectors or structs.
Diffstat (limited to 'llvm/lib/ExecutionEngine/ExecutionEngine.cpp')
-rw-r--r--llvm/lib/ExecutionEngine/ExecutionEngine.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
index 9e81cca..0d4f983 100644
--- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -618,7 +618,18 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
case Type::ScalableVectorTyID:
report_fatal_error(
"Scalable vector support not yet implemented in ExecutionEngine");
- case Type::FixedVectorTyID:
+ case Type::ArrayTyID: {
+ auto *ArrTy = cast<ArrayType>(C->getType());
+ Type *ElemTy = ArrTy->getElementType();
+ unsigned int elemNum = ArrTy->getNumElements();
+ Result.AggregateVal.resize(elemNum);
+ if (ElemTy->isIntegerTy())
+ for (unsigned int i = 0; i < elemNum; ++i)
+ Result.AggregateVal[i].IntVal =
+ APInt(ElemTy->getPrimitiveSizeInBits(), 0);
+ break;
+ }
+ case Type::FixedVectorTyID: {
// if the whole vector is 'undef' just reserve memory for the value.
auto *VTy = cast<FixedVectorType>(C->getType());
Type *ElemTy = VTy->getElementType();
@@ -629,6 +640,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
Result.AggregateVal[i].IntVal =
APInt(ElemTy->getPrimitiveSizeInBits(), 0);
break;
+ }
}
return Result;
}