[compiler-rt] r188229 - [dfsan] Introduce dfsan_union runtime function.

Peter Collingbourne peter at pcc.me.uk
Mon Aug 12 16:47:37 PDT 2013


Author: pcc
Date: Mon Aug 12 18:47:37 2013
New Revision: 188229

URL: http://llvm.org/viewvc/llvm-project?rev=188229&view=rev
Log:
[dfsan] Introduce dfsan_union runtime function.

Differential Revision: http://llvm-reviews.chandlerc.com/D1347

Modified:
    compiler-rt/trunk/include/sanitizer/dfsan_interface.h
    compiler-rt/trunk/lib/dfsan/dfsan.cc
    compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c

Modified: compiler-rt/trunk/include/sanitizer/dfsan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/dfsan_interface.h?rev=188229&r1=188228&r2=188229&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/dfsan_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/dfsan_interface.h Mon Aug 12 18:47:37 2013
@@ -39,6 +39,10 @@ struct dfsan_label_info {
   void *userdata;
 };
 
+/// Computes the union of \c l1 and \c l2, possibly creating a union label in
+/// the process.
+dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
+
 /// Creates and returns a base label with the given description and user data.
 dfsan_label dfsan_create_label(const char *desc, void *userdata);
 

Modified: compiler-rt/trunk/lib/dfsan/dfsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.cc?rev=188229&r1=188228&r2=188229&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.cc Mon Aug 12 18:47:37 2013
@@ -137,6 +137,15 @@ void *__dfsan_memcpy(void *dest, const v
   return internal_memcpy(dest, src, n);
 }
 
+// Like __dfsan_union, but for use from the client or custom functions.  Hence
+// the equality comparison is done here before calling __dfsan_union.
+SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
+dfsan_union(dfsan_label l1, dfsan_label l2) {
+  if (l1 == l2)
+    return l1;
+  return __dfsan_union(l1, l2);
+}
+
 SANITIZER_INTERFACE_ATTRIBUTE
 dfsan_label dfsan_create_label(const char *desc, void *userdata) {
   dfsan_label label =

Modified: compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c?rev=188229&r1=188228&r2=188229&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c (original)
+++ compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c Mon Aug 12 18:47:37 2013
@@ -7,6 +7,8 @@
 #include <assert.h>
 
 int main(void) {
+  assert(dfsan_union(0, 0) == 0);
+
   int i = 1;
   dfsan_label i_label = dfsan_create_label("i", 0);
   dfsan_set_label(i_label, &i, sizeof(i));
@@ -23,6 +25,9 @@ int main(void) {
   assert(dfsan_has_label(ij_label, i_label));
   assert(dfsan_has_label(ij_label, j_label));
   assert(!dfsan_has_label(ij_label, k_label));
+  // Test uniquing.
+  assert(dfsan_union(i_label, j_label) == ij_label);
+  assert(dfsan_union(j_label, i_label) == ij_label);
 
   dfsan_label ijk_label = dfsan_get_label(i + j + k);
   assert(dfsan_has_label(ijk_label, i_label));





More information about the llvm-commits mailing list