[PATCH] Adding type-string based blacklist for sanitizers

Byoungyoung Lee byoungyoung at chromium.org
Mon Jul 7 08:43:54 PDT 2014


Hi rsmith, samsonov, kcc,

While I'm working on applying Undefined Sanitizer's vptr, I found that existing blacklisting methods (source file names or function names) do not fit well to handle many false positive cases for Undefined Sanitizer (e.g., a template class, which causes a false positive, is used in all over different places).

Thus, we have added type-string based blacklisting. Please note that this blacklisting is not based on any LLVM internal types (e.g., Module/Function), but simply based on generic "string" types. This is because UBsan instruments in the Clang's CodeGen phase and unrolls type information into the "string" from Clang specific QualType, which is not visible for LLVM.

http://reviews.llvm.org/D4406

Files:
  include/llvm/Transforms/Utils/SpecialCaseList.h
  lib/Transforms/Utils/SpecialCaseList.cpp
  unittests/Transforms/Utils/SpecialCaseList.cpp

Index: unittests/Transforms/Utils/SpecialCaseList.cpp
===================================================================
--- unittests/Transforms/Utils/SpecialCaseList.cpp
+++ unittests/Transforms/Utils/SpecialCaseList.cpp
@@ -102,6 +102,23 @@
   EXPECT_FALSE(SCL->isIn(*Bar, "functional"));
 }
 
+TEST_F(SpecialCaseListTest, TypeIsIn) {
+  Module M("hello", Ctx);
+  GlobalVariable *Bar = makeGlobal("bar", "bar_t", M);
+
+  std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("type:bar_t\n"));
+  EXPECT_TRUE(SCL->isIn(*Bar));
+
+  SCL.reset(makeSpecialCaseList("type:b*\n"));
+  EXPECT_TRUE(SCL->isIn(*Bar));
+
+  SCL.reset(makeSpecialCaseList("type:*_t\n"));
+  EXPECT_TRUE(SCL->isIn(*Bar));
+
+  SCL.reset(makeSpecialCaseList("type:bar\n"));
+  EXPECT_FALSE(SCL->isIn(*Bar));
+}
+
 TEST_F(SpecialCaseListTest, GlobalIsIn) {
   Module M("hello", Ctx);
   GlobalVariable *Foo = makeGlobal("foo", "t1", M);
Index: lib/Transforms/Utils/SpecialCaseList.cpp
===================================================================
--- lib/Transforms/Utils/SpecialCaseList.cpp
+++ lib/Transforms/Utils/SpecialCaseList.cpp
@@ -168,6 +168,11 @@
   }
 }
 
+bool SpecialCaseList::isIn(const StringRef TypeStr,
+                           const StringRef Category) const {
+  return inSectionCategory("type", TypeStr, Category);
+}
+
 bool SpecialCaseList::isIn(const Function& F, const StringRef Category) const {
   return isIn(*F.getParent(), Category) ||
          inSectionCategory("fun", F.getName(), Category);
Index: include/llvm/Transforms/Utils/SpecialCaseList.h
===================================================================
--- include/llvm/Transforms/Utils/SpecialCaseList.h
+++ include/llvm/Transforms/Utils/SpecialCaseList.h
@@ -73,6 +73,11 @@
 
   ~SpecialCaseList();
 
+  /// Returns whether this type string is listed in the given category,
+  /// which may be ommitted to search the empty category.
+  bool isIn(const StringRef TypeStr,
+            const StringRef Category = StringRef()) const;
+
   /// Returns whether either this function or its source file are listed in the
   /// given category, which may be omitted to search the empty category.
   bool isIn(const Function &F, const StringRef Category = StringRef()) const;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4406.11118.patch
Type: text/x-patch
Size: 2251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140707/977f9176/attachment.bin>


More information about the llvm-commits mailing list