[llvm-commits] [llvm] r100825 - in /llvm/trunk: lib/Analysis/Lint.cpp test/Other/lint.ll
Dan Gohman
gohman at apple.com
Thu Apr 8 16:05:57 PDT 2010
Author: djg
Date: Thu Apr 8 18:05:57 2010
New Revision: 100825
URL: http://llvm.org/viewvc/llvm-project?rev=100825&view=rev
Log:
Add a few more lint checks.
Modified:
llvm/trunk/lib/Analysis/Lint.cpp
llvm/trunk/test/Other/lint.ll
Modified: llvm/trunk/lib/Analysis/Lint.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Lint.cpp?rev=100825&r1=100824&r2=100825&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Lint.cpp (original)
+++ llvm/trunk/lib/Analysis/Lint.cpp Thu Apr 8 18:05:57 2010
@@ -63,6 +63,9 @@
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);
@@ -70,6 +73,8 @@
void visitAllocaInst(AllocaInst &I);
void visitVAArgInst(VAArgInst &I);
void visitIndirectBrInst(IndirectBrInst &I);
+ void visitExtractElementInst(ExtractElementInst &I);
+ void visitInsertElementInst(InsertElementInst &I);
public:
Module *Mod;
@@ -295,6 +300,27 @@
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),
@@ -334,6 +360,20 @@
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...
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/test/Other/lint.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/lint.ll?rev=100825&r1=100824&r2=100825&view=diff
==============================================================================
--- llvm/trunk/test/Other/lint.ll (original)
+++ llvm/trunk/test/Other/lint.ll Thu Apr 8 18:05:57 2010
@@ -10,6 +10,10 @@
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
@@ -21,6 +25,16 @@
%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:
More information about the llvm-commits
mailing list