From: Chris Lattner Date: Fri, 13 May 2005 07:09:09 +0000 (+0000) Subject: calling a function with the wrong CC is undefined, turn it into an unreachable X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=08b22ecc8870b3657d94ebf7d1f91d9fd5d47744;p=oota-llvm.git calling a function with the wrong CC is undefined, turn it into an unreachable instruction. This is useful for catching optimizers that don't preserve calling conventions git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21928 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 27b87425adc..2077b329160 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4115,6 +4115,20 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) { Value *Callee = CS.getCalledValue(); + if (Function *CalleeF = dyn_cast(Callee)) + if (CalleeF->getCallingConv() != CS.getCallingConv()) { + Instruction *OldCall = CS.getInstruction(); + // If the call and callee calling conventions don't match, this call must + // be unreachable, as the call is undefined. + new StoreInst(ConstantBool::True, + UndefValue::get(PointerType::get(Type::BoolTy)), OldCall); + if (!OldCall->use_empty()) + OldCall->replaceAllUsesWith(UndefValue::get(OldCall->getType())); + if (isa(OldCall)) // Not worth removing an invoke here. + return EraseInstFromFunction(*OldCall); + return 0; + } + if (isa(Callee) || isa(Callee)) { // This instruction is not reachable, just remove it. We insert a store to // undef so that we know that this code is not reachable, despite the fact