[llvm] 75d6f50 - [Interpreter] Add initialization of array members (#66172)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 06:27:15 PDT 2023
Author: Dudeldu
Date: 2023-10-20T15:27:11+02:00
New Revision: 75d6f508f86026a0eb938ff9df5afc7a1dcf6ec3
URL: https://github.com/llvm/llvm-project/commit/75d6f508f86026a0eb938ff9df5afc7a1dcf6ec3
DIFF: https://github.com/llvm/llvm-project/commit/75d6f508f86026a0eb938ff9df5afc7a1dcf6ec3.diff
LOG: [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.
Added:
Modified:
llvm/lib/ExecutionEngine/ExecutionEngine.cpp
llvm/test/ExecutionEngine/2010-01-15-UndefValue.ll
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
index 9e81cca0b103aa4..0d4f9835f0fcd4d 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;
}
diff --git a/llvm/test/ExecutionEngine/2010-01-15-UndefValue.ll b/llvm/test/ExecutionEngine/2010-01-15-UndefValue.ll
index c208490f1be6b4c..5376fa232962ee3 100644
--- a/llvm/test/ExecutionEngine/2010-01-15-UndefValue.ll
+++ b/llvm/test/ExecutionEngine/2010-01-15-UndefValue.ll
@@ -4,5 +4,6 @@ define i32 @main() {
%a = add i32 0, undef
%b = fadd float 0.0, undef
%c = fadd double 0.0, undef
+ %d = insertvalue {i32, [4 x i32]} undef, i32 1, 1, 2
ret i32 0
}
More information about the llvm-commits
mailing list