[llvm] r232144 - Teach TBAA analysis to report errors on cyclic TBAA metadata rather than hanging.

Owen Anderson resistor at mac.com
Fri Mar 13 00:09:33 PDT 2015


Author: resistor
Date: Fri Mar 13 02:09:33 2015
New Revision: 232144

URL: http://llvm.org/viewvc/llvm-project?rev=232144&view=rev
Log:
Teach TBAA analysis to report errors on cyclic TBAA metadata rather than hanging.

Added:
    llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll
Modified:
    llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp?rev=232144&r1=232143&r2=232144&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp Fri Mar 13 02:09:33 2015
@@ -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(MDNod
     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;
   }

Added: llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll?rev=232144&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll (added)
+++ llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/cyclic.ll Fri Mar 13 02:09:33 2015
@@ -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}





More information about the llvm-commits mailing list