<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 5, 2014 at 3:24 AM, Alexey Samsonov <span dir="ltr"><<a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: samsonov<br>
Date: Mon Aug  4 20:24:22 2014<br>
New Revision: 214833<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=214833&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=214833&view=rev</a><br>
Log:<br>
[UBSan] Allow to suppress reports from vptr checker for specified types.<br>
<br>
Based on <a href="http://reviews.llvm.org/D4702" target="_blank">http://reviews.llvm.org/D4702</a> by Byoungyoung Lee!<br>
<br>
Modified:<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h<br>
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc<br>
    compiler-rt/trunk/lib/ubsan/ubsan_diag.cc<br>
    compiler-rt/trunk/lib/ubsan/ubsan_diag.h<br>
    compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc<br>
    compiler-rt/trunk/lib/ubsan/ubsan_init.cc<br>
    compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc?rev=214833&r1=214832&r2=214833&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc?rev=214833&r1=214832&r2=214833&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc Mon Aug  4 20:24:22 2014<br>
@@ -22,8 +22,8 @@<br>
 namespace __sanitizer {<br>
<br>
 static const char *const kTypeStrings[SuppressionTypeCount] = {<br>
-    "none",   "race", "mutex",           "thread",<br>
-    "signal", "leak", "called_from_lib", "deadlock"};<br>
+    "none", "race",            "mutex",    "thread",    "signal",<br>
+    "leak", "called_from_lib", "deadlock", "vptr_check"};<br>
<br>
 bool TemplateMatch(char *templ, const char *str) {<br>
   if (str == 0 || str[0] == 0)<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h?rev=214833&r1=214832&r2=214833&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h?rev=214833&r1=214832&r2=214833&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.h Mon Aug  4 20:24:22 2014<br>
@@ -27,6 +27,7 @@ enum SuppressionType {<br>
   SuppressionLeak,<br>
   SuppressionLib,<br>
   SuppressionDeadlock,<br>
+  SuppressionVptrCheck,<br>
   SuppressionTypeCount<br>
 };<br>
<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc?rev=214833&r1=214832&r2=214833&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc?rev=214833&r1=214832&r2=214833&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc Mon Aug  4 20:24:22 2014<br>
@@ -66,11 +66,13 @@ TEST(Suppressions, TypeStrings) {<br>
   CHECK(!internal_strcmp(SuppressionTypeString(SuppressionSignal), "signal"));<br>
   CHECK(!internal_strcmp(SuppressionTypeString(SuppressionLeak), "leak"));<br>
   CHECK(!internal_strcmp(SuppressionTypeString(SuppressionLib),<br>
-      "called_from_lib"));<br>
+                         "called_from_lib"));<br>
   CHECK(<br>
       !internal_strcmp(SuppressionTypeString(SuppressionDeadlock), "deadlock"));<br>
+  CHECK(!internal_strcmp(SuppressionTypeString(SuppressionVptrCheck),<br>
+                         "vptr_check"));<br>
   // Ensure this test is up-to-date when suppression types are added.<br>
-  CHECK_EQ(SuppressionTypeCount, 8);<br>
+  CHECK_EQ(9, SuppressionTypeCount);<br>
 }<br>
<br>
 class SuppressionContextTest : public ::testing::Test {<br>
<br>
Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=214833&r1=214832&r2=214833&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=214833&r1=214832&r2=214833&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (original)<br>
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cc Mon Aug  4 20:24:22 2014<br>
@@ -312,3 +312,12 @@ ScopedReport::~ScopedReport() {<br>
   if (DieAfterReport)<br>
     Die();<br>
 }<br>
+<br>
+bool __ubsan::MatchSuppression(const char *Str, SuppressionType Type) {<br>
+  Suppression *s;<br>
+  // If .preinit_array is not used, it is possible that the UBSan runtime is not<br>
+  // initialized.<br>
+  if (!SANITIZER_CAN_USE_PREINIT_ARRAY)<br>
+    InitIfNecessary();<br>
+  return SuppressionContext::Get()->Match(Str, Type, &s);<br>
+}<br>
<br>
Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.h?rev=214833&r1=214832&r2=214833&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.h?rev=214833&r1=214832&r2=214833&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.h (original)<br>
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.h Mon Aug  4 20:24:22 2014<br>
@@ -15,6 +15,7 @@<br>
<br>
 #include "ubsan_value.h"<br>
 #include "sanitizer_common/sanitizer_stacktrace.h"<br>
+#include "sanitizer_common/sanitizer_suppressions.h"<br>
<br>
 namespace __ubsan {<br>
<br>
@@ -218,6 +219,8 @@ public:<br>
   ~ScopedReport();<br>
 };<br>
<br>
+bool MatchSuppression(const char *Str, SuppressionType Type);<br>
+<br>
 } // namespace __ubsan<br>
<br>
 #endif // UBSAN_DIAG_H<br>
<br>
Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc?rev=214833&r1=214832&r2=214833&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc?rev=214833&r1=214832&r2=214833&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc (original)<br>
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc Mon Aug  4 20:24:22 2014<br>
@@ -18,6 +18,7 @@<br>
 #include "ubsan_type_hash.h"<br>
<br>
 #include "sanitizer_common/sanitizer_common.h"<br>
+#include "sanitizer_common/sanitizer_suppressions.h"<br>
<br>
 using namespace __sanitizer;<br>
 using namespace __ubsan;<br>
@@ -33,6 +34,12 @@ static void HandleDynamicTypeCacheMiss(<br>
     // Just a cache miss. The type matches after all.<br>
     return;<br>
<br>
+  // Check if error report should be suppressed.<br>
+  DynamicTypeInfo DTI = getDynamicTypeInfo((void*)Pointer);<br>
+  if (DTI.isValid() &&<br>
+      MatchSuppression(DTI.getMostDerivedTypeName(), SuppressionVptrCheck))<br>
+    return;<br>
+<br>
   SourceLocation Loc = Data->Loc.acquire();<br>
   if (Loc.isDisabled())<br>
     return;<br>
@@ -44,23 +51,23 @@ static void HandleDynamicTypeCacheMiss(<br>
     << TypeCheckKinds[Data->TypeCheckKind] << (void*)Pointer << Data->Type;<br>
<br>
   // If possible, say what type it actually points to.<br>
-  DynamicTypeInfo DTI = getDynamicTypeInfo((void*)Pointer);<br>
   if (!DTI.isValid())<br>
     Diag(Pointer, DL_Note, "object has invalid vptr")<br>
-      << MangledName(DTI.getMostDerivedTypeName())<br>
-      << Range(Pointer, Pointer + sizeof(uptr), "invalid vptr");<br>
+        << MangledName(DTI.getMostDerivedTypeName())<br>
+        << Range(Pointer, Pointer + sizeof(uptr), "invalid vptr");<br>
   else if (!DTI.getOffset())<br>
     Diag(Pointer, DL_Note, "object is of type %0")<br>
-      << MangledName(DTI.getMostDerivedTypeName())<br>
-      << Range(Pointer, Pointer + sizeof(uptr), "vptr for %0");<br>
+        << MangledName(DTI.getMostDerivedTypeName())<br>
+        << Range(Pointer, Pointer + sizeof(uptr), "vptr for %0");<br>
   else<br>
     // FIXME: Find the type at the specified offset, and include that<br>
     //        in the note.<br>
     Diag(Pointer - DTI.getOffset(), DL_Note,<br>
          "object is base class subobject at offset %0 within object of type %1")<br>
-      << DTI.getOffset() << MangledName(DTI.getMostDerivedTypeName())<br>
-      << MangledName(DTI.getSubobjectTypeName())<br>
-      << Range(Pointer, Pointer + sizeof(uptr), "vptr for %2 base class of %1");<br>
+        << DTI.getOffset() << MangledName(DTI.getMostDerivedTypeName())<br>
+        << MangledName(DTI.getSubobjectTypeName())<br>
+        << Range(Pointer, Pointer + sizeof(uptr),<br>
+                 "vptr for %2 base class of %1");<br>
<br>
   MaybePrintStackTrace(pc, bp);<br>
 }<br>
<br>
Modified: compiler-rt/trunk/lib/ubsan/ubsan_init.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init.cc?rev=214833&r1=214832&r2=214833&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init.cc?rev=214833&r1=214832&r2=214833&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/ubsan/ubsan_init.cc (original)<br>
+++ compiler-rt/trunk/lib/ubsan/ubsan_init.cc Mon Aug  4 20:24:22 2014<br>
@@ -16,6 +16,7 @@<br>
 #include "sanitizer_common/sanitizer_common.h"<br>
 #include "sanitizer_common/sanitizer_libc.h"<br>
 #include "sanitizer_common/sanitizer_mutex.h"<br>
+#include "sanitizer_common/sanitizer_suppressions.h"<br>
 #include "sanitizer_common/sanitizer_symbolizer.h"<br>
<br>
 using namespace __ubsan;<br>
@@ -42,6 +43,7 @@ void __ubsan::InitIfNecessary() {<br>
   }<br>
   // Initialize UBSan-specific flags.<br>
   InitializeFlags();<br>
+  SuppressionContext::InitIfNecessary();<br>
   ubsan_inited = true;<br>
 }<br>
<br>
<br>
Modified: compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp?rev=214833&r1=214832&r2=214833&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp?rev=214833&r1=214832&r2=214833&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp (original)<br>
+++ compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp Mon Aug  4 20:24:22 2014<br>
@@ -11,6 +11,19 @@<br>
 // RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t oU 2>&1 | FileCheck %s --check-prefix=CHECK-OFFSET --strict-whitespace<br>
 // RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL-MEMBER --strict-whitespace<br>
<br>
+// RUN: %clangxx -fsanitize=vptr -fno-sanitize-recover -g %s -O3 -o %t<br>
+// RUN: (echo "vptr_check:S"; echo "vptr_check:T"; echo "vptr_check:U") > %t.supp<br>
+// RUN: ASAN_OPTIONS="$ASAN_OPTIONS suppressions=%t.supp" UBSAN_OPTIONS=suppressions=%t.supp %run %t mS 2>&1<br>
+// RUN: ASAN_OPTIONS="$ASAN_OPTIONS suppressions=%t.supp" UBSAN_OPTIONS=suppressions=%t.supp %run %t fS 2>&1<br>
+// RUN: ASAN_OPTIONS="$ASAN_OPTIONS suppressions=%t.supp" UBSAN_OPTIONS=suppressions=%t.supp %run %t cS 2>&1<br>
+// RUN: ASAN_OPTIONS="$ASAN_OPTIONS suppressions=%t.supp" UBSAN_OPTIONS=suppressions=%t.supp %run %t mV 2>&1<br>
+// RUN: ASAN_OPTIONS="$ASAN_OPTIONS suppressions=%t.supp" UBSAN_OPTIONS=suppressions=%t.supp %run %t fV 2>&1<br>
+// RUN: ASAN_OPTIONS="$ASAN_OPTIONS suppressions=%t.supp" UBSAN_OPTIONS=suppressions=%t.supp %run %t cV 2>&1<br>
+// RUN: ASAN_OPTIONS="$ASAN_OPTIONS suppressions=%t.supp" UBSAN_OPTIONS=suppressions=%t.supp %run %t oU 2>&1<br>
+<br>
+// RUN: echo "vptr_check:S" > %t.loc-supp<br>
+// RUN: ASAN_OPTIONS="$ASAN_OPTIONS suppressions=%t.loc-supp" UBSAN_OPTIONS=suppressions=%t.loc-supp not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS<br></blockquote><div><br></div><div>
This test doesn't do "export ASAN_OPTIONS=...", so using $ASAN_OPTIONS in RUN: lines breaks when test runner checks for unset shell variables. I've fixed this in r214855.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

+<br>
 // FIXME: This test produces linker errors on Darwin.<br>
 // XFAIL: darwin<br>
<br>
@@ -31,6 +44,8 @@ struct T : S {<br>
<br>
 struct U : S, T { virtual int v() { return 2; } };<br>
<br>
+struct V : S {};<br>
+<br>
 // Make p global so that lsan does not complain.<br>
 T *p = 0;<br>
<br>
@@ -84,6 +99,19 @@ int access_p(T *p, char type) {<br>
     {T &r = *p;}<br>
     break;<br>
<br>
+  case 'x':<br>
+    for (int i = 0; i < 2; i++) {<br>
+      // Check that the first iteration ("S") succeeds, while the second ("V") fails.<br>
+      p = reinterpret_cast<T*>((i == 0) ? new S : new V);<br>
+      // CHECK-LOC-SUPPRESS: vptr.cpp:[[@LINE+5]]:7: runtime error: member call on address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T'<br>
+      // CHECK-LOC-SUPPRESS-NEXT: [[PTR]]: note: object is of type 'V'<br>
+      // CHECK-LOC-SUPPRESS-NEXT: {{^ .. .. .. ..  .. .. .. .. .. .. .. ..  }}<br>
+      // CHECK-LOC-SUPPRESS-NEXT: {{^              \^~~~~~~~~~~(~~~~~~~~~~~~)? *$}}<br>
+      // CHECK-LOC-SUPPRESS-NEXT: {{^              vptr for 'V'}}<br>
+      p->g();<br>
+    }<br>
+    return 0;<br>
+<br>
   case 'm':<br>
     // CHECK-MEMBER: vptr.cpp:[[@LINE+6]]:15: runtime error: member access within address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T'<br>
     // CHECK-MEMBER-NEXT: [[PTR]]: note: object is of type [[DYN_TYPE:'S'|'U']]<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br>
</div></div>