From 3db4fdda6197646ea255cffe4ef291c872d65fd8 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 24 May 2018 19:07:34 +0000 Subject: [PATCH] Add handling for GlobalAliases in ExecutionEngine::getConstantValue. Patch by Brad Moody. Thanks Brad! https://reviews.llvm.org/D42160 llvm-svn: 333217 --- lib/ExecutionEngine/ExecutionEngine.cpp | 3 +++ test/ExecutionEngine/Interpreter/alias.ll | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/ExecutionEngine/Interpreter/alias.ll diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index dae0ea89420..ae96c7f5955 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -903,6 +903,9 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { Result.IntVal = cast(C)->getValue(); break; case Type::PointerTyID: + while (auto *A = dyn_cast(C)) { + C = A->getAliasee(); + } if (isa(C)) Result.PointerVal = nullptr; else if (const Function *F = dyn_cast(C)) diff --git a/test/ExecutionEngine/Interpreter/alias.ll b/test/ExecutionEngine/Interpreter/alias.ll new file mode 100644 index 00000000000..4bfdd2ce060 --- /dev/null +++ b/test/ExecutionEngine/Interpreter/alias.ll @@ -0,0 +1,14 @@ +; RUN: %lli -force-interpreter %s + +define i32 @func() { +entry: + ret i32 0 +} + +@alias = alias i32 (), i32 ()* @func + +define i32 @main() { +entry: + %call = call i32 @alias() + ret i32 %call +}