void visitReturnInst(ReturnInst &I);
void visitLoadInst(LoadInst &I);
void visitStoreInst(StoreInst &I);
+ void visitLShr(BinaryOperator &I);
+ void visitAShr(BinaryOperator &I);
+ void visitShl(BinaryOperator &I);
void visitSDiv(BinaryOperator &I);
void visitUDiv(BinaryOperator &I);
void visitSRem(BinaryOperator &I);
void visitAllocaInst(AllocaInst &I);
void visitVAArgInst(VAArgInst &I);
void visitIndirectBrInst(IndirectBrInst &I);
+ void visitExtractElementInst(ExtractElementInst &I);
+ void visitInsertElementInst(InsertElementInst &I);
public:
Module *Mod;
I.getOperand(0)->getType());
}
+void Lint::visitLShr(BinaryOperator &I) {
+ if (ConstantInt *CI =
+ dyn_cast<ConstantInt>(I.getOperand(1)->stripPointerCasts()))
+ Assert1(CI->getValue().ult(cast<IntegerType>(I.getType())->getBitWidth()),
+ "Shift count out of range", &I);
+}
+
+void Lint::visitAShr(BinaryOperator &I) {
+ if (ConstantInt *CI =
+ dyn_cast<ConstantInt>(I.getOperand(1)->stripPointerCasts()))
+ Assert1(CI->getValue().ult(cast<IntegerType>(I.getType())->getBitWidth()),
+ "Shift count out of range", &I);
+}
+
+void Lint::visitShl(BinaryOperator &I) {
+ if (ConstantInt *CI =
+ dyn_cast<ConstantInt>(I.getOperand(1)->stripPointerCasts()))
+ Assert1(CI->getValue().ult(cast<IntegerType>(I.getType())->getBitWidth()),
+ "Shift count out of range", &I);
+}
+
static bool isZero(Value *V, TargetData *TD) {
unsigned BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
APInt Mask = APInt::getAllOnesValue(BitWidth),
visitMemoryReference(I, I.getAddress(), 0, 0);
}
+void Lint::visitExtractElementInst(ExtractElementInst &I) {
+ if (ConstantInt *CI =
+ dyn_cast<ConstantInt>(I.getIndexOperand()->stripPointerCasts()))
+ Assert1(CI->getValue().ult(I.getVectorOperandType()->getNumElements()),
+ "extractelement index out of range", &I);
+}
+
+void Lint::visitInsertElementInst(InsertElementInst &I) {
+ if (ConstantInt *CI =
+ dyn_cast<ConstantInt>(I.getOperand(2)->stripPointerCasts()))
+ Assert1(CI->getValue().ult(I.getType()->getNumElements()),
+ "insertelement index out of range", &I);
+}
+
//===----------------------------------------------------------------------===//
// Implement the public interfaces to this file...
//===----------------------------------------------------------------------===//
store i32 0, i32* null
; CHECK: Null pointer dereference
%t = load i32* null
+; CHECK: Undef pointer dereference
+ store i32 0, i32* undef
+; CHECK: Undef pointer dereference
+ %u = load i32* undef
; CHECK: Memory reference address is misaligned
%x = inttoptr i32 1 to i32*
load i32* %x, align 4
%sr = srem i32 2, 0
; CHECK: Division by zero
%ur = urem i32 2, 0
+; CHECK: extractelement index out of range
+ %ee = extractelement <4 x i32> zeroinitializer, i32 4
+; CHECK: insertelement index out of range
+ %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
+; CHECK: Shift count out of range
+ %r = lshr i32 0, 32
+; CHECK: Shift count out of range
+ %q = ashr i32 0, 32
+; CHECK: Shift count out of range
+ %l = shl i32 0, 32
br label %next
next: