diff options
author | Kostya Serebryany <kcc@google.com> | 2016-08-30 03:05:50 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-08-30 03:05:50 +0000 |
commit | d4492f81011df9dd12ff78275b45bb81093700c7 (patch) | |
tree | a4b97afdf5518646ff1eabeeaf54802592da04fe /llvm/lib/Fuzzer/FuzzerTraceState.cpp | |
parent | 84832a7a795033386bd80cc8028ef2a8b23692a9 (diff) | |
download | llvm-d4492f81011df9dd12ff78275b45bb81093700c7.zip llvm-d4492f81011df9dd12ff78275b45bb81093700c7.tar.gz llvm-d4492f81011df9dd12ff78275b45bb81093700c7.tar.bz2 |
[libFuzzer] use bits instead of bytes for memcmp/strcmp value profile -- the fuzzer reaches the goal much faster, at least on the simple puzzles
llvm-svn: 280054
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerTraceState.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerTraceState.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerTraceState.cpp b/llvm/lib/Fuzzer/FuzzerTraceState.cpp index 7bbc759..732e1a44 100644 --- a/llvm/lib/Fuzzer/FuzzerTraceState.cpp +++ b/llvm/lib/Fuzzer/FuzzerTraceState.cpp @@ -552,26 +552,34 @@ static void AddValueForMemcmp(void *caller_pc, const void *s1, const void *s2, size_t n) { if (!n) return; size_t Len = std::min(n, (size_t)32); - const char *A1 = reinterpret_cast<const char *>(s1); - const char *A2 = reinterpret_cast<const char *>(s2); - size_t LastSameByte = 0; - for (; LastSameByte < Len; LastSameByte++) - if (A1[LastSameByte] != A2[LastSameByte]) + const uint8_t *A1 = reinterpret_cast<const uint8_t *>(s1); + const uint8_t *A2 = reinterpret_cast<const uint8_t *>(s2); + size_t I = 0; + for (; I < Len; I++) + if (A1[I] != A2[I]) break; size_t PC = reinterpret_cast<size_t>(caller_pc); - VP.AddValue((PC & 4095) | (LastSameByte << 12)); + size_t Idx = I * 8; + if (I < Len) + Idx += __builtin_popcountl((A1[I] ^ A2[I])) - 1; + VP.AddValue((PC & 4095) | (Idx << 12)); } static void AddValueForStrcmp(void *caller_pc, const char *s1, const char *s2, size_t n) { if (!n) return; size_t Len = std::min(n, (size_t)32); - size_t LastSameByte = 0; - for (; LastSameByte < Len; LastSameByte++) - if (s1[LastSameByte] != s2[LastSameByte] || s1[LastSameByte] == 0) + const uint8_t *A1 = reinterpret_cast<const uint8_t *>(s1); + const uint8_t *A2 = reinterpret_cast<const uint8_t *>(s2); + size_t I = 0; + for (; I < Len; I++) + if (A1[I] != A2[I] || A1[I] == 0) break; size_t PC = reinterpret_cast<size_t>(caller_pc); - VP.AddValue((PC & 4095) | (LastSameByte << 12)); + size_t Idx = I * 8; + if (I < Len && A1[I]) + Idx += __builtin_popcountl((A1[I] ^ A2[I])) - 1; + VP.AddValue((PC & 4095) | (Idx << 12)); } ATTRIBUTE_TARGET_POPCNT |