[PATCH] [dfsan] Introduce dfsan_union runtime functionn.

Peter Collingbourne peter at pcc.me.uk
Fri Aug 9 19:03:01 PDT 2013


Hi eugenis,

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

Files:
  include/sanitizer/dfsan_interface.h
  lib/dfsan/dfsan.cc
  lib/dfsan/lit_tests/propagate.c

Index: include/sanitizer/dfsan_interface.h
===================================================================
--- include/sanitizer/dfsan_interface.h
+++ include/sanitizer/dfsan_interface.h
@@ -39,6 +39,10 @@
   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);
 
Index: lib/dfsan/dfsan.cc
===================================================================
--- lib/dfsan/dfsan.cc
+++ lib/dfsan/dfsan.cc
@@ -137,6 +137,15 @@
   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 =
Index: lib/dfsan/lit_tests/propagate.c
===================================================================
--- lib/dfsan/lit_tests/propagate.c
+++ lib/dfsan/lit_tests/propagate.c
@@ -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 @@
   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));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1347.1.patch
Type: text/x-patch
Size: 1960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130809/b6af1e32/attachment.bin>


More information about the llvm-commits mailing list