[compiler-rt] r222954 - Add a HasSuppressionType method into SuppressionContext
Kuba Brecka
kuba.brecka at gmail.com
Sat Nov 29 06:18:05 PST 2014
Author: kuba.brecka
Date: Sat Nov 29 08:18:05 2014
New Revision: 222954
URL: http://llvm.org/viewvc/llvm-project?rev=222954&view=rev
Log:
Add a HasSuppressionType method into SuppressionContext
Extending SuppressionContext to add a HasSuppressionType method that tells whether a certain suppression type is currently used or not. It's a step to implement issue suppressions for ASan, see http://reviews.llvm.org/D6280.
Reviewed at http://reviews.llvm.org/D6443
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h
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=222954&r1=222953&r2=222954&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc Sat Nov 29 08:18:05 2014
@@ -70,6 +70,10 @@ bool TemplateMatch(char *templ, const ch
ALIGNED(64) static char placeholder[sizeof(SuppressionContext)];
static SuppressionContext *suppression_ctx = 0;
+SuppressionContext::SuppressionContext() : suppressions_(1), can_parse_(true) {
+ internal_memset(has_suppresson_type_, 0, sizeof(has_suppresson_type_));
+}
+
SuppressionContext *SuppressionContext::Get() {
CHECK(suppression_ctx);
return suppression_ctx;
@@ -96,6 +100,8 @@ void SuppressionContext::InitIfNecessary
bool SuppressionContext::Match(const char *str, SuppressionType type,
Suppression **s) {
+ if (!has_suppresson_type_[type])
+ return false;
can_parse_ = false;
uptr i;
for (i = 0; i < suppressions_.size(); i++)
@@ -151,6 +157,7 @@ void SuppressionContext::Parse(const cha
s.hit_count = 0;
s.weight = 0;
suppressions_.push_back(s);
+ has_suppresson_type_[s.type] = true;
}
if (end[0] == 0)
break;
@@ -162,6 +169,10 @@ uptr SuppressionContext::SuppressionCoun
return suppressions_.size();
}
+bool SuppressionContext::HasSuppressionType(SuppressionType type) const {
+ return has_suppresson_type_[type];
+}
+
const Suppression *SuppressionContext::SuppressionAt(uptr i) const {
CHECK_LT(i, suppressions_.size());
return &suppressions_[i];
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h?rev=222954&r1=222953&r2=222954&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h Sat Nov 29 08:18:05 2014
@@ -43,6 +43,7 @@ class SuppressionContext {
void Parse(const char *str);
bool Match(const char* str, SuppressionType type, Suppression **s);
uptr SuppressionCount() const;
+ bool HasSuppressionType(SuppressionType type) const;
const Suppression *SuppressionAt(uptr i) const;
void GetMatched(InternalMmapVector<Suppression *> *matched);
@@ -54,8 +55,9 @@ class SuppressionContext {
static SuppressionContext *Get();
private:
- SuppressionContext() : suppressions_(1), can_parse_(true) {}
+ SuppressionContext();
InternalMmapVector<Suppression> suppressions_;
+ bool has_suppresson_type_[SuppressionTypeCount];
bool can_parse_;
friend class SuppressionContextTest;
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=222954&r1=222953&r2=222954&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 Sat Nov 29 08:18:05 2014
@@ -153,4 +153,14 @@ TEST_F(SuppressionContextTest, ParseType
EXPECT_EQ(0, strcmp((*Suppressions())[0].templ, "foo"));
}
+TEST_F(SuppressionContextTest, HasSuppressionType) {
+ ctx_->Parse(
+ "race:foo\n"
+ "thread:bar\n");
+ EXPECT_TRUE(ctx_->HasSuppressionType(SuppressionRace));
+ EXPECT_TRUE(ctx_->HasSuppressionType(SuppressionThread));
+ EXPECT_FALSE(ctx_->HasSuppressionType(SuppressionMutex));
+ EXPECT_FALSE(ctx_->HasSuppressionType(SuppressionSignal));
+}
+
} // namespace __sanitizer
More information about the llvm-commits
mailing list