From 09bf6d322d79381de780871f26cdffc26d7dacf4 Mon Sep 17 00:00:00 2001 From: Julian Büning Date: Sat, 21 Jul 2018 23:01:54 +0200 Subject: ModuleUtil: improve and test valueIsOnlyCalled * handle BlockAddress (which is not a valid function pointer) * there is no instruction with opcode 0 * add test for functionality --- lib/Module/ModuleUtil.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib/Module') diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index deb5a3e2..5ca0a55b 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -312,9 +312,7 @@ static bool valueIsOnlyCalled(const Value *v) { #else for (auto user : v->users()) { #endif - if (const Instruction *instr = dyn_cast(user)) { - if (instr->getOpcode()==0) continue; // XXX function numbering inst - + if (const auto *instr = dyn_cast(user)) { // Make sure the instruction is a call or invoke. CallSite cs(const_cast(instr)); if (!cs) return false; @@ -323,16 +321,17 @@ static bool valueIsOnlyCalled(const Value *v) { // not an argument. if (cs.hasArgument(v)) return false; - } else if (const llvm::ConstantExpr *ce = - dyn_cast(user)) { - if (ce->getOpcode()==Instruction::BitCast) + } else if (const auto *ce = dyn_cast(user)) { + if (ce->getOpcode() == Instruction::BitCast) if (valueIsOnlyCalled(ce)) continue; return false; - } else if (const GlobalAlias *ga = dyn_cast(user)) { - // XXX what about v is bitcast of aliasee? - if (v==ga->getAliasee() && !valueIsOnlyCalled(ga)) + } else if (const auto *ga = dyn_cast(user)) { + if (v == ga->getAliasee() && !valueIsOnlyCalled(ga)) return false; + } else if (isa(user)) { + // only valid as operand to indirectbr or comparison against null + continue; } else { return false; } -- cgit 1.4.1