From 9029cb836304cd2848f589dc79373d9b67eb48e0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 16 Jan 2009 20:17:02 +0000 Subject: [PATCH] don't assert and die on out of range (undefined) shifts. This fixes PR3334. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62352 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/Interpreter/Execution.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 872a40b6aea..f10360903f4 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -927,7 +927,11 @@ void Interpreter::visitShl(BinaryOperator &I) { GenericValue Src1 = getOperandValue(I.getOperand(0), SF); GenericValue Src2 = getOperandValue(I.getOperand(1), SF); GenericValue Dest; - Dest.IntVal = Src1.IntVal.shl(Src2.IntVal.getZExtValue()); + if (Src2.IntVal.getZExtValue() < Src1.IntVal.getBitWidth()) + Dest.IntVal = Src1.IntVal.shl(Src2.IntVal.getZExtValue()); + else + Dest.IntVal = Src1.IntVal; + SetValue(&I, Dest, SF); } @@ -936,7 +940,11 @@ void Interpreter::visitLShr(BinaryOperator &I) { GenericValue Src1 = getOperandValue(I.getOperand(0), SF); GenericValue Src2 = getOperandValue(I.getOperand(1), SF); GenericValue Dest; - Dest.IntVal = Src1.IntVal.lshr(Src2.IntVal.getZExtValue()); + if (Src2.IntVal.getZExtValue() < Src1.IntVal.getBitWidth()) + Dest.IntVal = Src1.IntVal.lshr(Src2.IntVal.getZExtValue()); + else + Dest.IntVal = Src1.IntVal; + SetValue(&I, Dest, SF); } @@ -944,8 +952,12 @@ void Interpreter::visitAShr(BinaryOperator &I) { ExecutionContext &SF = ECStack.back(); GenericValue Src1 = getOperandValue(I.getOperand(0), SF); GenericValue Src2 = getOperandValue(I.getOperand(1), SF); - GenericValue Dest; - Dest.IntVal = Src1.IntVal.ashr(Src2.IntVal.getZExtValue()); + GenericValue Dest; + if (Src2.IntVal.getZExtValue() < Src1.IntVal.getBitWidth()) + Dest.IntVal = Src1.IntVal.ashr(Src2.IntVal.getZExtValue()); + else + Dest.IntVal = Src1.IntVal; + SetValue(&I, Dest, SF); } -- 2.34.1