forked from OSchip/llvm-project
[dfsan] Introduce dfsan_union runtime function.
Differential Revision: http://llvm-reviews.chandlerc.com/D1347 llvm-svn: 188229
This commit is contained in:
parent
633ec6848b
commit
21b2929aca
|
@ -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);
|
||||
|
||||
|
|
|
@ -137,6 +137,15 @@ void *__dfsan_memcpy(void *dest, const void *src, size_t n) {
|
|||
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 =
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue