mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
Add a few more lint checks.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100825 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e056781323
commit
dd98c4d185
@ -63,6 +63,9 @@ namespace {
|
||||
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 @@ namespace {
|
||||
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 @@ void Lint::visitStoreInst(StoreInst &I) {
|
||||
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 @@ void Lint::visitIndirectBrInst(IndirectBrInst &I) {
|
||||
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...
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -10,6 +10,10 @@ define i32 @foo() noreturn {
|
||||
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 @@ define i32 @foo() noreturn {
|
||||
%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:
|
||||
|
Loading…
Reference in New Issue
Block a user