summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2015-03-13 07:09:33 +0000
committerOwen Anderson <resistor@mac.com>2015-03-13 07:09:33 +0000
commit41a185c521ad48cbaccb8c0c37eb249755e540ba (patch)
tree584326a4f4ada99675e02124ba52b50cfb587d18
parent08f46e1de67f333b10f4e299b4eccccc84ca6697 (diff)
downloadbcm5719-llvm-41a185c521ad48cbaccb8c0c37eb249755e540ba.tar.gz
bcm5719-llvm-41a185c521ad48cbaccb8c0c37eb249755e540ba.zip
Teach TBAA analysis to report errors on cyclic TBAA metadata rather than hanging.
llvm-svn: 232144
-rw-r--r--llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp13
-rw-r--r--llvm/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll26
2 files changed, 35 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
index 1ed2653bee9..115872584cb 100644
--- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -129,6 +129,7 @@
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/ADT/SetVector.h"
using namespace llvm;
// A handy option for disabling TBAA functionality. The same effect can also be
@@ -578,18 +579,22 @@ MDNode *MDNode::getMostGenericTBAA(MDNode *A, MDNode *B) {
if (!B) return nullptr;
}
- SmallVector<MDNode *, 4> PathA;
+ SmallSetVector<MDNode *, 4> PathA;
MDNode *T = A;
while (T) {
- PathA.push_back(T);
+ if (PathA.count(T))
+ report_fatal_error("Cycle found in TBAA metadata.");
+ PathA.insert(T);
T = T->getNumOperands() >= 2 ? cast_or_null<MDNode>(T->getOperand(1))
: nullptr;
}
- SmallVector<MDNode *, 4> PathB;
+ SmallSetVector<MDNode *, 4> PathB;
T = B;
while (T) {
- PathB.push_back(T);
+ if (PathB.count(T))
+ report_fatal_error("Cycle found in TBAA metadata.");
+ PathB.insert(T);
T = T->getNumOperands() >= 2 ? cast_or_null<MDNode>(T->getOperand(1))
: nullptr;
}
diff --git a/llvm/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll b/llvm/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll
new file mode 100644
index 00000000000..a88e26c5cd5
--- /dev/null
+++ b/llvm/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll
@@ -0,0 +1,26 @@
+; RUN: not opt -instcombine < %s 2>&1 | FileCheck %s
+; CHECK: Cycle found in TBAA metadata.
+
+define void @test6(i32* %gi) #0 {
+entry:
+ store i32 42, i32* %gi, align 4, !tbaa !0
+ br label %for.cond
+
+for.cond: ; preds = %for.body, %entry
+ br i1 undef, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ store i32 undef, i32* %gi, align 4, !tbaa !2
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ ret void
+}
+
+attributes #0 = { nounwind ssp uwtable }
+
+!0 = !{!1, !1, i64 0}
+!1 = !{!"Simple C/C++ TBAA"}
+!2 = distinct !{!3, !2, i64 0}
+!3 = !{!"int", !4}
+!4 = !{!"omnipotent ", !1}
OpenPOWER on IntegriCloud