[PATCH] Change the way labels are propagated when comparing memory through libc functions
Lorenzo Martignoni
martignlo at google.com
Fri Nov 22 09:06:38 PST 2013
Hi pcc,
(not necessarily for submission)
My point is to start the discussion about what is the best way to propagate the labels in such functions. I personally believe the logic for propagating the labels should match the implementation (and that is what I tried to do in the attached patch).
http://llvm-reviews.chandlerc.com/D2252
Files:
lib/dfsan/dfsan_custom.cc
lib/dfsan/lit_tests/custom.c
Index: lib/dfsan/dfsan_custom.cc
===================================================================
--- lib/dfsan/dfsan_custom.cc
+++ lib/dfsan/dfsan_custom.cc
@@ -67,7 +67,7 @@
dfsan_label *ret_label) {
for (size_t i = 0;; ++i) {
if (s[i] == c || s[i] == 0) {
- *ret_label = dfsan_union(dfsan_read_label(s, i+1), c_label);
+ *ret_label = dfsan_union(dfsan_read_label(s + i, 1), c_label);
return s[i] == 0 ? 0 : const_cast<char *>(s+i);
}
}
@@ -81,13 +81,13 @@
const char *cs1 = (const char *) s1, *cs2 = (const char *) s2;
for (size_t i = 0; i != n; ++i) {
if (cs1[i] != cs2[i]) {
- *ret_label = dfsan_union(dfsan_read_label(cs1, i+1),
- dfsan_read_label(cs2, i+1));
+ *ret_label = dfsan_union(dfsan_read_label(cs1 + i, 1),
+ dfsan_read_label(cs2 + i, 1));
return cs1[i] - cs2[i];
}
}
- *ret_label = dfsan_union(dfsan_read_label(cs1, n),
- dfsan_read_label(cs2, n));
+ *ret_label = dfsan_union(dfsan_read_label(cs1 + n - 1, 1),
+ dfsan_read_label(cs2 + n - 1, 1));
return 0;
}
@@ -97,8 +97,8 @@
dfsan_label *ret_label) {
for (size_t i = 0;; ++i) {
if (s1[i] != s2[i] || s1[i] == 0 || s2[i] == 0) {
- *ret_label = dfsan_union(dfsan_read_label(s1, i+1),
- dfsan_read_label(s2, i+1));
+ *ret_label = dfsan_union(dfsan_read_label(s1 + i, 1),
+ dfsan_read_label(s2 + i, 1));
return s1[i] - s2[i];
}
}
@@ -110,8 +110,8 @@
dfsan_label s2_label, dfsan_label *ret_label) {
for (size_t i = 0;; ++i) {
if (tolower(s1[i]) != tolower(s2[i]) || s1[i] == 0 || s2[i] == 0) {
- *ret_label = dfsan_union(dfsan_read_label(s1, i+1),
- dfsan_read_label(s2, i+1));
+ *ret_label = dfsan_union(dfsan_read_label(s1 + i, 1),
+ dfsan_read_label(s2 + i, 1));
return s1[i] - s2[i];
}
}
@@ -129,9 +129,9 @@
}
for (size_t i = 0;; ++i) {
- if (s1[i] != s2[i] || s1[i] == 0 || s2[i] == 0 || i == n-1) {
- *ret_label = dfsan_union(dfsan_read_label(s1, i+1),
- dfsan_read_label(s2, i+1));
+ if (s1[i] != s2[i] || s1[i] == 0 || s2[i] == 0 || i == n - 1) {
+ *ret_label = dfsan_union(dfsan_read_label(s1 + i, 1),
+ dfsan_read_label(s2 + i, 1));
return s1[i] - s2[i];
}
}
@@ -150,8 +150,8 @@
for (size_t i = 0;; ++i) {
if (tolower(s1[i]) != tolower(s2[i]) || s1[i] == 0 || s2[i] == 0 ||
i == n - 1) {
- *ret_label = dfsan_union(dfsan_read_label(s1, i+1),
- dfsan_read_label(s2, i+1));
+ *ret_label = dfsan_union(dfsan_read_label(s1 + i, 1),
+ dfsan_read_label(s2 + i, 1));
return s1[i] - s2[i];
}
}
Index: lib/dfsan/lit_tests/custom.c
===================================================================
--- lib/dfsan/lit_tests/custom.c
+++ lib/dfsan/lit_tests/custom.c
@@ -179,7 +179,7 @@
rv = strcasecmp(str1, str3);
assert(rv == 0);
- ASSERT_LABEL(rv, dfsan_union(i_label, j_label));
+ ASSERT_ZERO_LABEL(rv);
}
void test_strncasecmp() {
@@ -210,7 +210,7 @@
crv = strchr(str1, 'x');
assert(!crv);
- ASSERT_LABEL(crv, i_label);
+ ASSERT_ZERO_LABEL(crv);
}
void test_calloc() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2252.1.patch
Type: text/x-patch
Size: 3564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131122/eb09e229/attachment.bin>
More information about the llvm-commits
mailing list