[compiler-rt] r186424 - tsan: extend suppressions format with ^ and $ symbols

Dmitry Vyukov dvyukov at google.com
Tue Jul 16 09:44:15 PDT 2013


Author: dvyukov
Date: Tue Jul 16 11:44:15 2013
New Revision: 186424

URL: http://llvm.org/viewvc/llvm-project?rev=186424&view=rev
Log:
tsan: extend suppressions format with ^ and $ symbols
not it's possible to write more precise suppressions,
e.g. "^foo$" won't match "blafoobar"

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc?rev=186424&r1=186423&r2=186424&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc Tue Jul 16 11:44:15 2013
@@ -26,25 +26,41 @@ static const char *const kTypeStrings[Su
 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;
 }

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc?rev=186424&r1=186423&r2=186424&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc Tue Jul 16 11:44:15 2013
@@ -24,19 +24,38 @@ static bool MyMatch(const char *templ, c
 }
 
 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) {





More information about the llvm-commits mailing list