LLVM cmplog factoring custom Instruction iterator with added restriction

This commit is contained in:
David CARLIER
2023-02-13 23:00:15 +00:00
parent 6030df2f56
commit 8bc3fa1df2
4 changed files with 20 additions and 30 deletions

View File

@ -582,6 +582,24 @@ bool isInInstrumentList(llvm::Function *F, std::string Filename) {
} }
template <class Iterator>
Iterator Unique(Iterator first, Iterator last) {
static_assert(std::is_trivially_copyable<
typename std::iterator_traits<Iterator>
>::value_type, "Invalid underlying type");
while (first != last) {
Iterator next(first);
last = std::remove(++next, last, *first);
first = next;
}
return last;
}
// Calculate the number of average collisions that would occur if all // Calculate the number of average collisions that would occur if all
// location IDs would be assigned randomly (like normal afl/afl++). // location IDs would be assigned randomly (like normal afl/afl++).
// This uses the "balls in bins" algorithm. // This uses the "balls in bins" algorithm.

View File

@ -9,6 +9,7 @@
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <optional> #include <optional>
#include <type_traits>
#include <sys/time.h> #include <sys/time.h>
#include "llvm/Config/llvm-config.h" #include "llvm/Config/llvm-config.h"
@ -53,6 +54,7 @@ void initInstrumentList();
bool isInInstrumentList(llvm::Function *F, std::string Filename); bool isInInstrumentList(llvm::Function *F, std::string Filename);
unsigned long long int calculateCollisions(uint32_t edges); unsigned long long int calculateCollisions(uint32_t edges);
void scanForDangerousFunctions(llvm::Module *M); void scanForDangerousFunctions(llvm::Module *M);
template<class Iterator> Iterator Unique(Iterator, Iterator);
#ifndef IS_EXTERN #ifndef IS_EXTERN
#define IS_EXTERN #define IS_EXTERN

View File

@ -138,21 +138,6 @@ llvmGetPassPluginInfo() {
char CmpLogInstructions::ID = 0; char CmpLogInstructions::ID = 0;
#endif #endif
template <class Iterator>
Iterator Unique(Iterator first, Iterator last) {
while (first != last) {
Iterator next(first);
last = std::remove(++next, last, *first);
first = next;
}
return last;
}
bool CmpLogInstructions::hookInstrs(Module &M) { bool CmpLogInstructions::hookInstrs(Module &M) {
std::vector<Instruction *> icomps; std::vector<Instruction *> icomps;

View File

@ -131,21 +131,6 @@ llvmGetPassPluginInfo() {
char CmplogSwitches::ID = 0; char CmplogSwitches::ID = 0;
#endif #endif
template <class Iterator>
Iterator Unique(Iterator first, Iterator last) {
while (first != last) {
Iterator next(first);
last = std::remove(++next, last, *first);
first = next;
}
return last;
}
bool CmplogSwitches::hookInstrs(Module &M) { bool CmplogSwitches::hookInstrs(Module &M) {
std::vector<SwitchInst *> switches; std::vector<SwitchInst *> switches;