Index: lib/ExecutionEngine/ExecutionEngine.cpp =================================================================== --- lib/ExecutionEngine/ExecutionEngine.cpp +++ lib/ExecutionEngine/ExecutionEngine.cpp @@ -26,6 +26,7 @@ #include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/Use.h" #include "llvm/IR/ValueHandle.h" #include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" @@ -37,8 +38,10 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" +#include #include #include +#include using namespace llvm; #define DEBUG_TYPE "jit" @@ -902,6 +905,29 @@ case Type::IntegerTyID: Result.IntVal = cast(C)->getValue(); break; + case Type::StructTyID: + case Type::ArrayTyID: { + if (!isa(C)) { + std::transform( + C->op_begin(), C->op_end(), std::back_inserter(Result.AggregateVal), + [this](const Use &E) { return getConstantValue(cast(E)); }); + break; + } + + auto *CDS = dyn_cast(C); + auto *CAZ = dyn_cast(C); + assert((CDS || CAZ) && "Unsupported ConstantData subclass"); + + unsigned NumElems = CDS ? CDS->getNumElements() : CAZ->getNumElements(); + + for (unsigned ENum = 0; ENum < NumElems; ++ENum) { + Constant *E = + CDS ? CDS->getElementAsConstant(ENum) : CAZ->getElementValue(ENum); + + Result.AggregateVal.push_back(getConstantValue(E)); + } + break; + } case Type::PointerTyID: while (auto *A = dyn_cast(C)) { C = A->getAliasee(); Index: test/ExecutionEngine/Interpreter/constant-aggzero.ll =================================================================== --- /dev/null +++ test/ExecutionEngine/Interpreter/constant-aggzero.ll @@ -0,0 +1,11 @@ +; RUN: %lli -force-interpreter %s + +define { i32, i32 } @f() { + ret { i32, i32 } { i32 0, i32 0 } +} + +define i32 @main() { + %s = call { i32, i32 } @f() + %t = extractvalue { i32, i32 } %s, 0 + ret i32 %t +} Index: test/ExecutionEngine/Interpreter/constant-array.ll =================================================================== --- /dev/null +++ test/ExecutionEngine/Interpreter/constant-array.ll @@ -0,0 +1,11 @@ +; RUN: %lli -force-interpreter %s + +define [2 x i32] @f() { + ret [2 x i32] [i32 0, i32 1] +} + +define i32 @main() { + %a = call [2 x i32] @f() + %t = extractvalue [2 x i32] %a, 0 + ret i32 %t +} Index: test/ExecutionEngine/Interpreter/constant-struct.ll =================================================================== --- /dev/null +++ test/ExecutionEngine/Interpreter/constant-struct.ll @@ -0,0 +1,11 @@ +; RUN: %lli -force-interpreter %s + +define { i32, i32 } @f() { + ret { i32, i32 } { i32 0, i32 1 } +} + +define i32 @main() { + %s = call { i32, i32 } @f() + %t = extractvalue { i32, i32 } %s, 0 + ret i32 %t +}