more code cleanup (instrumentation)
MODIFY
instrumentation/afl-gcc-pass.so.cc
instrumentation/afl-gcc-pass.so.cc
@@ -228,7 +228,7 @@ struct afl_pass : gimple_opt_pass {
const bool neverZero;
/* Count instrumented blocks. */
- int inst_blocks;
+ unsigned int inst_blocks;
virtual unsigned int execute(function *fn) {
@@ -931,7 +931,7 @@ int plugin_init(struct plugin_name_args * info,
quiet = true;
/* Decide instrumentation ratio. */
- int inst_ratio = 100;
+ unsigned int inst_ratio = 100U;
if (char *inst_ratio_str = getenv("AFL_INST_RATIO"))
if (sscanf(inst_ratio_str, "%u", &inst_ratio) != 1 || !inst_ratio ||
inst_ratio > 100)

MODIFY
instrumentation/afl-llvm-dict2file.so.cc
instrumentation/afl-llvm-dict2file.so.cc
@@ -355,7 +355,8 @@ bool AFLdict2filePass::runOnModule(Module &M) {
*Str2P = callInst->getArgOperand(1);
std::string Str1, Str2;
StringRef TmpStr;
- bool HasStr1 = getConstantStringInfo(Str1P, TmpStr);
+ bool HasStr1;
+ getConstantStringInfo(Str1P, TmpStr);
if (TmpStr.empty()) {
HasStr1 = false;
@@ -367,7 +368,8 @@ bool AFLdict2filePass::runOnModule(Module &M) {
}
- bool HasStr2 = getConstantStringInfo(Str2P, TmpStr);
+ bool HasStr2;
+ getConstantStringInfo(Str2P, TmpStr);
if (TmpStr.empty()) {
HasStr2 = false;

MODIFY
instrumentation/afl-llvm-lto-instrumentation.so.cc
instrumentation/afl-llvm-lto-instrumentation.so.cc
@@ -70,7 +70,7 @@ class AFLLTOPass : public ModulePass {
if (getenv("AFL_DEBUG")) debug = 1;
if ((ptr = getenv("AFL_LLVM_LTO_STARTID")) != NULL)
if ((afl_global_id = atoi(ptr)) < 0 || afl_global_id >= MAP_SIZE)
- FATAL("AFL_LLVM_LTO_STARTID value of \"%s\" is not between 0 and %d\n",
+ FATAL("AFL_LLVM_LTO_STARTID value of \"%s\" is not between 0 and %u\n",
ptr, MAP_SIZE - 1);
skip_nozero = getenv("AFL_LLVM_SKIP_NEVERZERO");
@@ -102,7 +102,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
LLVMContext & C = M.getContext();
std::vector<std::string> dictionary;
- std::vector<CallInst *> calls;
+// std::vector<CallInst *> calls;
DenseMap<Value *, std::string *> valueMap;
std::vector<BasicBlock *> BlockList;
char * ptr;
@@ -471,7 +471,8 @@ bool AFLLTOPass::runOnModule(Module &M) {
*Str2P = callInst->getArgOperand(1);
std::string Str1, Str2;
StringRef TmpStr;
- bool HasStr1 = getConstantStringInfo(Str1P, TmpStr);
+ bool HasStr1;
+ getConstantStringInfo(Str1P, TmpStr);
if (TmpStr.empty()) {
HasStr1 = false;
@@ -483,7 +484,8 @@ bool AFLLTOPass::runOnModule(Module &M) {
}
- bool HasStr2 = getConstantStringInfo(Str2P, TmpStr);
+ bool HasStr2;
+ getConstantStringInfo(Str2P, TmpStr);
if (TmpStr.empty()) {
HasStr2 = false;
@@ -671,7 +673,6 @@ bool AFLLTOPass::runOnModule(Module &M) {
if (!be_quiet) {
- std::string outstring;
fprintf(stderr, "%s: length %zu/%zu \"", FuncName.c_str(), optLen,
thestring.length());
for (uint8_t i = 0; i < thestring.length(); i++) {
@@ -799,7 +800,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
if (documentFile) {
- fprintf(documentFile, "ModuleID=%llu Function=%s edgeID=%u\n",
+ fprintf(documentFile, "ModuleID=%llu Function=%s edgeID=%d\n",
moduleID, F.getName().str().c_str(), afl_global_id);
}
@@ -871,10 +872,10 @@ bool AFLLTOPass::runOnModule(Module &M) {
while ((map = map >> 1))
pow2map++;
WARNF(
- "We have %u blocks to instrument but the map size is only %u. Either "
- "edit config.h and set MAP_SIZE_POW2 from %u to %u, then recompile "
+ "We have %d blocks to instrument but the map size is only %u. Either "
+ "edit config.h and set MAP_SIZE_POW2 from %d to %u, then recompile "
"afl-fuzz and llvm_mode and then make this target - or set "
- "AFL_MAP_SIZE with at least size %u when running afl-fuzz with this "
+ "AFL_MAP_SIZE with at least size %d when running afl-fuzz with this "
"target.",
afl_global_id, MAP_SIZE, MAP_SIZE_POW2, pow2map, afl_global_id);
@@ -937,8 +938,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
if (dictionary.size()) {
- size_t memlen = 0, count = 0, offset = 0;
- char * ptr;
+ size_t memlen = 0, count = 0;
// sort and unique the dictionary
std::sort(dictionary.begin(), dictionary.end());
@@ -953,14 +953,14 @@ bool AFLLTOPass::runOnModule(Module &M) {
}
if (!be_quiet)
- printf("AUTODICTIONARY: %lu string%s found\n", count,
+ printf("AUTODICTIONARY: %zu string%s found\n", count,
count == 1 ? "" : "s");
if (count) {
if ((ptr = (char *)malloc(memlen + count)) == NULL) {
- fprintf(stderr, "Error: malloc for %lu bytes failed!\n",
+ fprintf(stderr, "Error: malloc for %zu bytes failed!\n",
memlen + count);
exit(-1);
@@ -968,6 +968,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
count = 0;
+ size_t offset = 0;
for (auto token : dictionary) {
if (offset + token.length() < 0xfffff0 && count < MAX_AUTO_EXTRAS) {
@@ -1031,7 +1032,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
getenv("AFL_USE_MSAN") ? ", MSAN" : "",
getenv("AFL_USE_CFISAN") ? ", CFISAN" : "",
getenv("AFL_USE_UBSAN") ? ", UBSAN" : "");
- OKF("Instrumented %u locations with no collisions (on average %llu "
+ OKF("Instrumented %d locations with no collisions (on average %llu "
"collisions would be in afl-gcc/afl-clang-fast) (%s mode).",
inst_blocks, calculateCollisions(inst_blocks), modeline);

MODIFY
instrumentation/afl-llvm-pass.so.cc
instrumentation/afl-llvm-pass.so.cc
@@ -327,10 +327,10 @@ bool AFLCoverage::runOnModule(Module &M) {
// does the function have calls? and is any of the calls larger than one
// basic block?
- for (auto &BB : F) {
+ for (auto &BB_2 : F) {
if (has_calls) break;
- for (auto &IN : BB) {
+ for (auto &IN : BB_2) {
CallInst *callInst = nullptr;
if ((callInst = dyn_cast<CallInst>(&IN))) {
@@ -628,7 +628,7 @@ bool AFLCoverage::runOnModule(Module &M) {
getenv("AFL_USE_MSAN") ? ", MSAN" : "",
getenv("AFL_USE_CFISAN") ? ", CFISAN" : "",
getenv("AFL_USE_UBSAN") ? ", UBSAN" : "");
- OKF("Instrumented %u locations (%s mode, ratio %u%%).", inst_blocks,
+ OKF("Instrumented %d locations (%s mode, ratio %u%%).", inst_blocks,
modeline, inst_ratio);
}

MODIFY
instrumentation/compare-transform-pass.so.cc
instrumentation/compare-transform-pass.so.cc
@@ -100,6 +100,12 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
IntegerType * Int32Ty = IntegerType::getInt32Ty(C);
IntegerType * Int64Ty = IntegerType::getInt64Ty(C);
+#if LLVM_VERSION_MAJOR < 9
+ Function *tolowerFn;
+#else
+ FunctionCallee tolowerFn;
+#endif
+ {
#if LLVM_VERSION_MAJOR < 9
Constant *
#else
@@ -112,11 +118,11 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
#endif
);
#if LLVM_VERSION_MAJOR < 9
- Function *tolowerFn = cast<Function>(c);
+ tolowerFn = cast<Function>(c);
#else
- FunctionCallee tolowerFn = c;
+ tolowerFn = c;
#endif
-
+ }
/* iterate over all functions, bbs and instruction and add suitable calls to
* strcmp/memcmp/strncmp/strcasecmp/strncasecmp */
for (auto &F : M) {
@@ -234,7 +240,7 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
if (!HasStr2) {
- auto *Ptr = dyn_cast<ConstantExpr>(Str1P);
+ Ptr = dyn_cast<ConstantExpr>(Str1P);
if (Ptr && Ptr->isGEPWithNoNotionalOverIndexing()) {
if (auto *Var = dyn_cast<GlobalVariable>(Ptr->getOperand(0))) {

MODIFY
instrumentation/split-compares-pass.so.cc
instrumentation/split-compares-pass.so.cc
@@ -53,7 +53,7 @@ class SplitComparesTransform : public ModulePass {
public:
static char ID;
- SplitComparesTransform() : ModulePass(ID) {
+ SplitComparesTransform() : ModulePass(ID), enableFPSplit(0) {
initInstrumentList();
@@ -900,7 +900,6 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
/* compare the fractions of the operands */
Instruction *icmp_fraction_result;
- Instruction *icmp_fraction_result2;
BasicBlock * middle2_bb = middle_bb;
PHINode * PN2 = nullptr;
switch (FcmpInst->getPredicate()) {
@@ -927,6 +926,8 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
case CmpInst::FCMP_OLT:
case CmpInst::FCMP_ULT: {
+ Instruction *icmp_fraction_result2;
+
middle2_bb = middle_bb->splitBasicBlock(
BasicBlock::iterator(middle_bb->getTerminator()));

more code cleanup (instrumentation)