Skip to content

Commit 92b68c1

Browse files
committed
[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 9f6b13e, where an empty 'Str' would cause the function to never exit. Also fixed usage in polly.
1 parent 6656e96 commit 92b68c1

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

llvm/lib/Support/StringRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ void StringRef::split(SmallVectorImpl<StringRef> &A, char Separator,
372372
size_t StringRef::count(StringRef Str) const {
373373
size_t Count = 0;
374374
size_t N = Str.size();
375-
if (N > Length)
375+
if (!N || N > Length)
376376
return 0;
377377
for (size_t i = 0, e = Length - N + 1; i < e;) {
378378
if (substr(i, N).equals(Str)) {

llvm/unittests/ADT/StringRefTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ TEST(StringRefTest, Count) {
509509
EXPECT_EQ(1U, Str.count("hello"));
510510
EXPECT_EQ(1U, Str.count("ello"));
511511
EXPECT_EQ(0U, Str.count("zz"));
512+
EXPECT_EQ(0U, Str.count(""));
512513

513514
StringRef OverlappingAbba("abbabba");
514515
EXPECT_EQ(1U, OverlappingAbba.count("abba"));

polly/lib/Analysis/ScopDetection.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,8 @@ bool ScopDetection::isValidRegion(DetectionContext &Context) const {
16531653
CurRegion.getExit(), DbgLoc);
16541654
}
16551655

1656-
if (!CurRegion.getEntry()->getName().count(OnlyRegion)) {
1656+
if (!OnlyRegion.empty() &&
1657+
!CurRegion.getEntry()->getName().count(OnlyRegion)) {
16571658
LLVM_DEBUG({
16581659
dbgs() << "Region entry does not match -polly-region-only";
16591660
dbgs() << "\n";

0 commit comments

Comments
 (0)