diff options
| author | Chris Lattner <sabre@nondot.org> | 2005-05-13 07:09:09 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2005-05-13 07:09:09 +0000 | 
| commit | 61d9d81770a6baf58f64a76246e8e1ce8e86a5e8 (patch) | |
| tree | 07c88a6fb08a5f7f8f56f6ec329b732e8d4e1642 /llvm/lib/Transforms | |
| parent | 91caf1d039cc77aeff9d6f0076c681c8368df13b (diff) | |
| download | bcm5719-llvm-61d9d81770a6baf58f64a76246e8e1ce8e86a5e8.tar.gz bcm5719-llvm-61d9d81770a6baf58f64a76246e8e1ce8e86a5e8.zip | |
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
llvm-svn: 21928
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 14 | 
1 files changed, 14 insertions, 0 deletions
| diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 27b87425adc..2077b329160 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4115,6 +4115,20 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {    Value *Callee = CS.getCalledValue(); +  if (Function *CalleeF = dyn_cast<Function>(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<CallInst>(OldCall))   // Not worth removing an invoke here. +        return EraseInstFromFunction(*OldCall); +      return 0; +    } +    if (isa<ConstantPointerNull>(Callee) || isa<UndefValue>(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 | 

