[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri May 13 00:09:22 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.343 -> 1.344
---
Log message:

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


---
Diffs of the changes:  (+14 -0)

 InstructionCombining.cpp |   14 ++++++++++++++
 1 files changed, 14 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.343 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.344
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.343	Sun May  8 23:58:36 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Fri May 13 02:09:09 2005
@@ -4115,6 +4115,20 @@
 
   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






More information about the llvm-commits mailing list