Fix typos noticed by Benjamin Kramer.

Also make the checks stronger and test that we reject ranges that overlap
a previous wrapped range.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157749 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2012-05-31 16:04:26 +00:00
parent c8e340da82
commit a1b95f53cc
3 changed files with 60 additions and 17 deletions

View File

@ -3054,8 +3054,8 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
<li>The range should not represent the full or empty set. That is, <li>The range should not represent the full or empty set. That is,
<tt>a!=b</tt>. </li> <tt>a!=b</tt>. </li>
</ul> </ul>
<p> In addiion, the pairs must be in signed order of the lower bound and <p> In addition, the pairs must be in signed order of the lower bound and
they must be non contigous.</p> they must be non-contiguous.</p>
<p>Examples:</p> <p>Examples:</p>
<div class="doc_code"> <div class="doc_code">

View File

@ -68,6 +68,7 @@
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
@ -1362,6 +1363,10 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
visitInstruction(GEP); visitInstruction(GEP);
} }
static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
}
void Verifier::visitLoadInst(LoadInst &LI) { void Verifier::visitLoadInst(LoadInst &LI) {
PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType()); PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
Assert1(PTy, "Load operand must be a pointer.", &LI); Assert1(PTy, "Load operand must be a pointer.", &LI);
@ -1384,7 +1389,7 @@ void Verifier::visitLoadInst(LoadInst &LI) {
unsigned NumRanges = NumOperands / 2; unsigned NumRanges = NumOperands / 2;
Assert1(NumRanges >= 1, "It should have at least one range!", Range); Assert1(NumRanges >= 1, "It should have at least one range!", Range);
APInt LastHigh; ConstantRange LastRange(1); // Dummy initial value
for (unsigned i = 0; i < NumRanges; ++i) { for (unsigned i = 0; i < NumRanges; ++i) {
ConstantInt *Low = dyn_cast<ConstantInt>(Range->getOperand(2*i)); ConstantInt *Low = dyn_cast<ConstantInt>(Range->getOperand(2*i));
Assert1(Low, "The lower limit must be an integer!", Low); Assert1(Low, "The lower limit must be an integer!", Low);
@ -1396,18 +1401,32 @@ void Verifier::visitLoadInst(LoadInst &LI) {
APInt HighV = High->getValue(); APInt HighV = High->getValue();
APInt LowV = Low->getValue(); APInt LowV = Low->getValue();
Assert1(HighV != LowV, "Range must not be empty!", Range); ConstantRange CurRange(LowV, HighV);
Assert1(!CurRange.isEmptySet() && !CurRange.isFullSet(),
"Range must not be empty!", Range);
if (i != 0) { if (i != 0) {
Assert1(Low->getValue().sgt(LastHigh), Assert1(CurRange.intersectWith(LastRange).isEmptySet(),
"Intervals are overlapping, contiguous or not in order", Range); "Intervals are overlapping", Range);
if (i == NumRanges - 1 && HighV.slt(LowV)) { Assert1(LowV.sgt(LastRange.getLower()), "Intervals are not in order",
APInt First = dyn_cast<ConstantInt>(Range->getOperand(0))->getValue(); Range);
Assert1(First.sgt(HighV), Assert1(!isContiguous(CurRange, LastRange), "Intervals are contiguous",
"First and last intervals are contiguous or overlap", Range); Range);
}
} }
LastHigh = High->getValue(); LastRange = ConstantRange(LowV, HighV);
} }
if (NumRanges > 2) {
APInt FirstLow =
dyn_cast<ConstantInt>(Range->getOperand(0))->getValue();
APInt FirstHigh =
dyn_cast<ConstantInt>(Range->getOperand(1))->getValue();
ConstantRange FirstRange(FirstLow, FirstHigh);
Assert1(FirstRange.intersectWith(LastRange).isEmptySet(),
"Intervals are overlapping", Range);
Assert1(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",
Range);
}
} }
visitInstruction(LI); visitInstruction(LI);

View File

@ -83,7 +83,7 @@ entry:
ret i8 %y ret i8 %y
} }
!9 = metadata !{i8 0, i8 2, i8 1, i8 3} !9 = metadata !{i8 0, i8 2, i8 1, i8 3}
; CHECK: Intervals are overlapping, contiguous or not in order ; CHECK: Intervals are overlapping
define i8 @f11(i8* %x) { define i8 @f11(i8* %x) {
entry: entry:
@ -91,7 +91,7 @@ entry:
ret i8 %y ret i8 %y
} }
!10 = metadata !{i8 0, i8 2, i8 2, i8 3} !10 = metadata !{i8 0, i8 2, i8 2, i8 3}
; CHECK: Intervals are overlapping, contiguous or not in order ; CHECK: Intervals are contiguous
define i8 @f12(i8* %x) { define i8 @f12(i8* %x) {
entry: entry:
@ -99,7 +99,7 @@ entry:
ret i8 %y ret i8 %y
} }
!11 = metadata !{i8 1, i8 2, i8 -1, i8 0} !11 = metadata !{i8 1, i8 2, i8 -1, i8 0}
; CHECK: Intervals are overlapping, contiguous or not in order ; CHECK: Intervals are not in order
define i8 @f13(i8* %x) { define i8 @f13(i8* %x) {
entry: entry:
@ -107,7 +107,7 @@ entry:
ret i8 %y ret i8 %y
} }
!12 = metadata !{i8 1, i8 3, i8 5, i8 1} !12 = metadata !{i8 1, i8 3, i8 5, i8 1}
; CHECK: First and last intervals are contiguous or overlap ; CHECK: Intervals are contiguous
define i8 @f14(i8* %x) { define i8 @f14(i8* %x) {
entry: entry:
@ -115,4 +115,28 @@ entry:
ret i8 %y ret i8 %y
} }
!13 = metadata !{i8 1, i8 3, i8 5, i8 2} !13 = metadata !{i8 1, i8 3, i8 5, i8 2}
; CHECK: First and last intervals are contiguous or overlap ; CHECK: Intervals are overlapping
define i8 @f15(i8* %x) {
entry:
%y = load i8* %x, align 1, !range !14
ret i8 %y
}
!14 = metadata !{i8 10, i8 1, i8 12, i8 13}
; CHECK: Intervals are overlapping
define i8 @f16(i8* %x) {
entry:
%y = load i8* %x, align 1, !range !16
ret i8 %y
}
!16 = metadata !{i8 1, i8 3, i8 4, i8 5, i8 6, i8 2}
; CHECK: Intervals are overlapping
define i8 @f17(i8* %x) {
entry:
%y = load i8* %x, align 1, !range !17
ret i8 %y
}
!17 = metadata !{i8 1, i8 3, i8 4, i8 5, i8 6, i8 1}
; CHECK: Intervals are contiguous