Index: lib/Support/GlobPattern.cpp =================================================================== --- lib/Support/GlobPattern.cpp +++ lib/Support/GlobPattern.cpp @@ -151,7 +151,9 @@ // If Pats[0] is '*', try to match Pats[1..] against all possible // tail strings of S to see at least one pattern succeeds. if (Pats[0].size() == 0) { - Pats = Pats.slice(1); + // '**' is efficiency the same as '*', skip them to optimize. + while (!Pats.empty() && Pats.front().empty()) + Pats = Pats.slice(1); if (Pats.empty()) // Fast path. If a pattern is '*', it matches anything. return true; Index: unittests/Support/GlobPatternTest.cpp =================================================================== --- unittests/Support/GlobPatternTest.cpp +++ unittests/Support/GlobPatternTest.cpp @@ -76,4 +76,15 @@ EXPECT_TRUE((bool)Pat2); EXPECT_TRUE(Pat2->match("\xFF")); } + +// Check this test does not take ages to complete. +TEST_F(GlobPatternTest, MultipleStarts) { + std::string Stars(1024, '*'); + Stars += 'X'; + std::string Stars2(1024, 'A'); + + Expected Pat = GlobPattern::create(Stars); + EXPECT_TRUE((bool)Pat); + EXPECT_FALSE(Pat->match(Stars2)); +} }