From 212afb9fd9c24e9f2e32d77deb7c456bee49193f Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 26 Jan 2018 10:36:50 +0000 Subject: [PATCH] [CallSiteSplitting] Fix infinite loop when recording conditions. Fix infinite loop when recording conditions by correctly marking basic blocks as visited. Fixes https://bugs.llvm.org/show_bug.cgi?id=36105 llvm-svn: 323515 --- .../Transforms/Scalar/CallSiteSplitting.cpp | 3 ++- .../callsite-no-splitting.ll | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp b/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp index 3243731f07db..76358a040d9b 100644 --- a/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp +++ b/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp @@ -140,10 +140,11 @@ static void recordConditions(CallSite CS, BasicBlock *Pred, recordCondition(CS, Pred, CS.getInstruction()->getParent(), Conditions); BasicBlock *From = Pred; BasicBlock *To = Pred; - SmallPtrSet Visited = {From}; + SmallPtrSet Visited; while (!Visited.count(From->getSinglePredecessor()) && (From = From->getSinglePredecessor())) { recordCondition(CS, From, To, Conditions); + Visited.insert(From); To = From; } } diff --git a/llvm/test/Transforms/CallSiteSplitting/callsite-no-splitting.ll b/llvm/test/Transforms/CallSiteSplitting/callsite-no-splitting.ll index ca41bd6fc5e1..25b4cb23be60 100644 --- a/llvm/test/Transforms/CallSiteSplitting/callsite-no-splitting.ll +++ b/llvm/test/Transforms/CallSiteSplitting/callsite-no-splitting.ll @@ -16,3 +16,27 @@ Tail: %r = call i32 @callee(i32* %a, i32 %v, i32 %p) ret i32 %r } + +define void @fn1(i16 %p1) { +entry: + ret void +} + +define void @fn2() { + ret void + +; Unreachable code below + +for.inc: ; preds = %for.inc + br i1 undef, label %for.end6, label %for.inc + +for.end6: ; preds = %for.inc + br i1 undef, label %lor.rhs, label %lor.end + +lor.rhs: ; preds = %for.end6 + br label %lor.end + +lor.end: ; preds = %for.end6, %lor.rhs + call void @fn1(i16 0) + ret void +}