1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[Evaluator] Examine alias when evaluating function call

This fixes PR38120

llvm-svn: 336702
This commit is contained in:
Eugene Leviant 2018-07-10 16:34:23 +00:00
parent 6b5342cb2e
commit 2b4e7c18a5
2 changed files with 19 additions and 3 deletions

View File

@ -24,6 +24,7 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InstrTypes.h"
@ -217,16 +218,26 @@ Constant *Evaluator::ComputeLoadResult(Constant *P) {
return nullptr; // don't know how to evaluate.
}
static Function *getFunction(Constant *C) {
if (auto *Fn = dyn_cast<Function>(C))
return Fn;
if (auto *Alias = dyn_cast<GlobalAlias>(C))
if (auto *Fn = dyn_cast<Function>(Alias->getAliasee()))
return Fn;
return nullptr;
}
Function *
Evaluator::getCalleeWithFormalArgs(CallSite &CS,
SmallVector<Constant *, 8> &Formals) {
auto *V = CS.getCalledValue();
if (auto *Fn = dyn_cast<Function>(getVal(V)))
if (auto *Fn = getFunction(getVal(V)))
return getFormalParams(CS, Fn, Formals) ? Fn : nullptr;
auto *CE = dyn_cast<ConstantExpr>(V);
if (!CE || CE->getOpcode() != Instruction::BitCast ||
!getFormalParams(CS, cast<Function>(CE->getOperand(0)), Formals))
!getFormalParams(CS, getFunction(CE->getOperand(0)), Formals))
return nullptr;
return dyn_cast<Function>(
@ -235,6 +246,9 @@ Evaluator::getCalleeWithFormalArgs(CallSite &CS,
bool Evaluator::getFormalParams(CallSite &CS, Function *F,
SmallVector<Constant *, 8> &Formals) {
if (!F)
return false;
auto *FTy = F->getFunctionType();
if (FTy->getNumParams() > CS.getNumArgOperands()) {
LLVM_DEBUG(dbgs() << "Too few arguments for function.\n");

View File

@ -28,10 +28,12 @@ target triple = "x86_64-apple-macosx10.12.0"
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_main.cpp, i8* null }]
define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
call void @_ZN1SC1Ev(%struct.S* @_s)
call void @_ZN1SC1Ev_alias(%struct.S* @_s)
ret void
}
@_ZN1SC1Ev_alias = linkonce_odr unnamed_addr alias void (%struct.S*), void (%struct.S*)* @_ZN1SC1Ev
define linkonce_odr void @_ZN1SC1Ev(%struct.S*) unnamed_addr align 2 {
%2 = alloca %struct.S*, align 8
store %struct.S* %0, %struct.S** %2, align 8