Teach TBAA analysis to report errors on cyclic TBAA metadata rather than hanging.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232144 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2015-03-13 07:09:33 +00:00
parent 39fcd2305a
commit c20535dff6
2 changed files with 35 additions and 4 deletions

View File

@ -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;
}