diff options
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/IPConstantPropagation.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp index 8d51c6a27ab..7dc4d9ee9e3 100644 --- a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -66,6 +66,13 @@ static bool PropagateConstantsIntoArguments(Function &F) { if (!ACS) return false; + // Mismatched argument count is undefined behavior. Simply bail out to avoid + // handling of such situations below (avoiding asserts/crashes). + unsigned NumActualArgs = ACS.getNumArgOperands(); + if (F.isVarArg() ? ArgumentConstants.size() > NumActualArgs + : ArgumentConstants.size() != NumActualArgs) + return false; + // Check out all of the potentially constant arguments. Note that we don't // inspect varargs here. Function::arg_iterator Arg = F.arg_begin(); @@ -78,6 +85,11 @@ static bool PropagateConstantsIntoArguments(Function &F) { Value *V = ACS.getCallArgOperand(i); Constant *C = dyn_cast_or_null<Constant>(V); + // Mismatched argument type is undefined behavior. Simply bail out to avoid + // handling of such situations below (avoiding asserts/crashes). + if (C && Arg->getType() != C->getType()) + return false; + // We can only propagate thread independent values through callbacks. // This is different to direct/indirect call sites because for them we // know the thread executing the caller and callee is the same. For |