This is an archive of the discontinued LLVM Phabricator instance.

Use custom allocators for STL containers in libFuzzer
ClosedPublic

Authored by george.karpenkov on Aug 23 2017, 4:15 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

The fuzzer:: qualifier is often spurious, but might be a helpful indication that some magic is going on.

Suggestions for a better test are welcome.

kcc edited edge metadata.Aug 23 2017, 9:09 PM

Nice. Did this help?

lib/fuzzer/FuzzerDefs.h
22 ↗(On Diff #112483)

Why do you need this?

test/fuzzer/VectorTest.cpp
6 ↗(On Diff #112483)

Do some push_backs and pop_backs, just having a CTOR is not enough to trigger a warning.
Or maybe simply abandon the test and rely on having this tested with the rest of clang build.

@kcc removed the test, I couldn't reproducibly get an error in this test. Let's just rely on fuzzers being able to run.

@kcc is it good to go?

lib/fuzzer/FuzzerDefs.h
22 ↗(On Diff #112483)

to use std::allocator and std::set

kcc added inline comments.Aug 25 2017, 5:33 PM
lib/fuzzer/FuzzerDefs.h
22 ↗(On Diff #112483)

I am asking only about #include <iostream>
Isn't std::allocator defined in <memory>?

@kcc seems to work either way.

kcc added a comment.Aug 25 2017, 10:05 PM

@kcc seems to work either way.

<memory> is fine, <iostream> is not -- it brings too much unrelated stuff.

kcc accepted this revision.Aug 25 2017, 10:05 PM

LGTM

This revision is now accepted and ready to land.Aug 25 2017, 10:05 PM
This revision was automatically updated to reflect the committed changes.
vitalybuka added inline comments.
compiler-rt/trunk/lib/fuzzer/FuzzerMutate.h
145

It would be nicer with fuzzer::vector -> Vector

compiler-rt/trunk/lib/fuzzer/FuzzerMutate.h
145

I am not sure, Vector to me implies another datastructure. In any case, I have already committed the revision.

Maybe you need to do the same with string?

compiler-rt/trunk/lib/fuzzer/FuzzerMutate.h
145

It is another data structure and we use camel style for them.
So shorter more consistent naming would be nicer, but I will not insist.

Reverted. The error message seems to be about const/non-const, but I couldn't figure it out right now.

Maybe you need to do the same with string?

Why would it fail only under GCC though?

george.karpenkov reopened this revision.Aug 27 2017, 3:18 PM

@vitalybuka @kcc Got it down to:

#include<memory>
#include<vector>

template<typename T>
class my_allocator : public std::allocator<T> {};


template<typename T>
using Vector = std::vector<T, my_allocator<T>>;

int main() {
    Vector<Vector<uint8_t>> v;
    Vector<uint8_t> v2;
    v.push_back(v2);
}

which fails under Linux with:

In file included from allocators.cc:3:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/vector:64:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/stl_vector.h:319:9: error: no matching
      constructor for initialization of '_Vector_base<unsigned char, my_allocator<unsigned char> >'
      : _Base(__x.size(),
This revision is now accepted and ready to land.Aug 27 2017, 3:18 PM

Got it working under GCC, struct rebind was missing.

kcc accepted this revision.Aug 27 2017, 3:45 PM

LGTM
wow!

actually, even that was not sufficient: we seem to lose the ability to use initializer lists.

This revision was automatically updated to reflect the committed changes.