[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 9f6b13e5cc, where an empty 'Str' would cause the function to never exit.
Also fixed usage in polly.
This commit is contained in:
Alexandre Ganea 2020-01-01 17:23:06 -05:00
parent 6656e961c0
commit 92b68c1937
3 changed files with 4 additions and 2 deletions

View File

@ -372,7 +372,7 @@ void StringRef::split(SmallVectorImpl<StringRef> &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)) {

View File

@ -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"));

View File

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