tsan: extend suppressions format with ^ and $ symbols
not it's possible to write more precise suppressions,
e.g. "^foo$" won't match "blafoobar"
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@186424 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/sanitizer_common/sanitizer_suppressions.cc b/lib/sanitizer_common/sanitizer_suppressions.cc
index f88020f..0676c0b 100644
--- a/lib/sanitizer_common/sanitizer_suppressions.cc
+++ b/lib/sanitizer_common/sanitizer_suppressions.cc
@@ -26,25 +26,41 @@
bool TemplateMatch(char *templ, const char *str) {
if (str == 0 || str[0] == 0)
return false;
- char *tpos;
- const char *spos;
+ bool start = false;
+ if (templ && templ[0] == '^') {
+ start = true;
+ templ++;
+ }
+ bool asterisk = false;
while (templ && templ[0]) {
if (templ[0] == '*') {
templ++;
+ start = false;
+ asterisk = true;
continue;
}
+ if (templ[0] == '$')
+ return str[0] == 0 || asterisk;
if (str[0] == 0)
return false;
- tpos = (char*)internal_strchr(templ, '*');
+ char *tpos = (char*)internal_strchr(templ, '*');
+ char *tpos1 = (char*)internal_strchr(templ, '$');
+ if (tpos == 0 || (tpos1 && tpos1 < tpos))
+ tpos = tpos1;
if (tpos != 0)
tpos[0] = 0;
- spos = internal_strstr(str, templ);
+ const char *str0 = str;
+ const char *spos = internal_strstr(str, templ);
str = spos + internal_strlen(templ);
templ = tpos;
if (tpos)
- tpos[0] = '*';
+ tpos[0] = tpos == tpos1 ? '$' : '*';
if (spos == 0)
return false;
+ if (start && spos != str0)
+ return false;
+ start = false;
+ asterisk = false;
}
return true;
}
diff --git a/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc b/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc
index 75061ac..f44911e 100644
--- a/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc
+++ b/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc
@@ -24,19 +24,38 @@
}
TEST(Suppressions, Match) {
+ EXPECT_TRUE(MyMatch("foobar$", "foobar"));
+
EXPECT_TRUE(MyMatch("foobar", "foobar"));
+ EXPECT_TRUE(MyMatch("*foobar*", "foobar"));
EXPECT_TRUE(MyMatch("foobar", "prefix_foobar_postfix"));
EXPECT_TRUE(MyMatch("*foobar*", "prefix_foobar_postfix"));
EXPECT_TRUE(MyMatch("foo*bar", "foo_middle_bar"));
EXPECT_TRUE(MyMatch("foo*bar", "foobar"));
EXPECT_TRUE(MyMatch("foo*bar*baz", "foo_middle_bar_another_baz"));
EXPECT_TRUE(MyMatch("foo*bar*baz", "foo_middle_barbaz"));
+ EXPECT_TRUE(MyMatch("^foobar", "foobar"));
+ EXPECT_TRUE(MyMatch("^foobar", "foobar_postfix"));
+ EXPECT_TRUE(MyMatch("^*foobar", "foobar"));
+ EXPECT_TRUE(MyMatch("^*foobar", "prefix_foobar"));
+ EXPECT_TRUE(MyMatch("foobar$", "foobar"));
+ EXPECT_TRUE(MyMatch("foobar$", "prefix_foobar"));
+ EXPECT_TRUE(MyMatch("*foobar*$", "foobar"));
+ EXPECT_TRUE(MyMatch("*foobar*$", "foobar_postfix"));
+ EXPECT_TRUE(MyMatch("^foobar$", "foobar"));
EXPECT_FALSE(MyMatch("foo", "baz"));
EXPECT_FALSE(MyMatch("foobarbaz", "foobar"));
EXPECT_FALSE(MyMatch("foobarbaz", "barbaz"));
EXPECT_FALSE(MyMatch("foo*bar", "foobaz"));
EXPECT_FALSE(MyMatch("foo*bar", "foo_baz"));
+ EXPECT_FALSE(MyMatch("^foobar", "prefix_foobar"));
+ EXPECT_FALSE(MyMatch("foobar$", "foobar_postfix"));
+ EXPECT_FALSE(MyMatch("^foobar$", "prefix_foobar"));
+ EXPECT_FALSE(MyMatch("^foobar$", "foobar_postfix"));
+ EXPECT_FALSE(MyMatch("foo^bar", "foobar"));
+ EXPECT_FALSE(MyMatch("foo$bar", "foobar"));
+ EXPECT_FALSE(MyMatch("foo$^bar", "foobar"));
}
TEST(Suppressions, TypeStrings) {