From 92b68c1937cd065a2fc44d18c1099de7da19b356 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Wed, 1 Jan 2020 17:23:06 -0500 Subject: [PATCH] [polly][Support] Un-break polly tests Previously, the polly unit tests were stuck in a infinite loop. There was an edge case in StringRef::count() introduced by 9f6b13e5cce96066d7262d224c971d93c2724795, where an empty 'Str' would cause the function to never exit. Also fixed usage in polly. --- llvm/lib/Support/StringRef.cpp | 2 +- llvm/unittests/ADT/StringRefTest.cpp | 1 + polly/lib/Analysis/ScopDetection.cpp | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index d7fa99dbde27..393504cf01b0 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/lib/Support/StringRef.cpp @@ -372,7 +372,7 @@ void StringRef::split(SmallVectorImpl &A, char Separator, size_t StringRef::count(StringRef Str) const { size_t Count = 0; size_t N = Str.size(); - if (N > Length) + if (!N || N > Length) return 0; for (size_t i = 0, e = Length - N + 1; i < e;) { if (substr(i, N).equals(Str)) { diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp index cbb2a30ff17a..9cb24bfdb4db 100644 --- a/llvm/unittests/ADT/StringRefTest.cpp +++ b/llvm/unittests/ADT/StringRefTest.cpp @@ -509,6 +509,7 @@ TEST(StringRefTest, Count) { EXPECT_EQ(1U, Str.count("hello")); EXPECT_EQ(1U, Str.count("ello")); EXPECT_EQ(0U, Str.count("zz")); + EXPECT_EQ(0U, Str.count("")); StringRef OverlappingAbba("abbabba"); EXPECT_EQ(1U, OverlappingAbba.count("abba")); diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index cf6ba75648df..59176d2a0ae9 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -1653,7 +1653,8 @@ bool ScopDetection::isValidRegion(DetectionContext &Context) const { CurRegion.getExit(), DbgLoc); } - if (!CurRegion.getEntry()->getName().count(OnlyRegion)) { + if (!OnlyRegion.empty() && + !CurRegion.getEntry()->getName().count(OnlyRegion)) { LLVM_DEBUG({ dbgs() << "Region entry does not match -polly-region-only"; dbgs() << "\n";