summaryrefslogtreecommitdiff
path: root/lib/VMCore/Verifier.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-05-31 16:04:26 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-05-31 16:04:26 +0000
commita1b95f53cc29b82fa7628affc9d01a08c620f5fd (patch)
treea1a193afd2813528549d9cb7e7e4d9b3f7933342 /lib/VMCore/Verifier.cpp
parentc8e340da823e8ff10b947429ef99e34ffc3067d8 (diff)
downloadllvm-a1b95f53cc29b82fa7628affc9d01a08c620f5fd.tar.gz
llvm-a1b95f53cc29b82fa7628affc9d01a08c620f5fd.tar.bz2
llvm-a1b95f53cc29b82fa7628affc9d01a08c620f5fd.tar.xz
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
Diffstat (limited to 'lib/VMCore/Verifier.cpp')
-rw-r--r--lib/VMCore/Verifier.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index fdffd11f09..e093c52f99 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -68,6 +68,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@@ -1362,6 +1363,10 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &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) {
PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
Assert1(PTy, "Load operand must be a pointer.", &LI);
@@ -1384,7 +1389,7 @@ void Verifier::visitLoadInst(LoadInst &LI) {
unsigned NumRanges = NumOperands / 2;
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) {
ConstantInt *Low = dyn_cast<ConstantInt>(Range->getOperand(2*i));
Assert1(Low, "The lower limit must be an integer!", Low);
@@ -1396,18 +1401,32 @@ void Verifier::visitLoadInst(LoadInst &LI) {
APInt HighV = High->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) {
- Assert1(Low->getValue().sgt(LastHigh),
- "Intervals are overlapping, contiguous or not in order", Range);
- if (i == NumRanges - 1 && HighV.slt(LowV)) {
- APInt First = dyn_cast<ConstantInt>(Range->getOperand(0))->getValue();
- Assert1(First.sgt(HighV),
- "First and last intervals are contiguous or overlap", Range);
- }
+ Assert1(CurRange.intersectWith(LastRange).isEmptySet(),
+ "Intervals are overlapping", Range);
+ Assert1(LowV.sgt(LastRange.getLower()), "Intervals are not in order",
+ Range);
+ Assert1(!isContiguous(CurRange, LastRange), "Intervals are contiguous",
+ 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);