unify LLVM_VERSION_... usage
MODIFY
instrumentation/SanitizerCoverageLTO.so.cc
instrumentation/SanitizerCoverageLTO.so.cc
@@ -1325,7 +1325,7 @@ void ModuleSanitizerCoverage::instrumentFunction(
} else
-#if LLVM_VERSION_MAJOR > 13
+#if LLVM_VERSION_MAJOR >= 14
if (t->getTypeID() == llvm::Type::FixedVectorTyID) {
FixedVectorType *tt = dyn_cast<FixedVectorType>(t);
@@ -1468,7 +1468,7 @@ GlobalVariable *ModuleSanitizerCoverage::CreateFunctionLocalArrayInSection(
*CurModule, ArrayTy, false, GlobalVariable::PrivateLinkage,
Constant::getNullValue(ArrayTy), "__sancov_gen_");
-#if LLVM_VERSION_MAJOR > 12
+#if LLVM_VERSION_MAJOR >= 13
if (TargetTriple.supportsCOMDAT() &&
(TargetTriple.isOSBinFormatELF() || !F.isInterposable()))
if (auto Comdat = getOrCreateFunctionComdat(F, TargetTriple))
@@ -1628,10 +1628,10 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
if (Options.TracePC) {
IRB.CreateCall(SanCovTracePC)
-#if LLVM_VERSION_MAJOR < 12
- ->cannotMerge(); // gets the PC using GET_CALLER_PC.
-#else
+#if LLVM_VERSION_MAJOR >= 12
->setCannotMerge(); // gets the PC using GET_CALLER_PC.
+#else
+ ->cannotMerge(); // gets the PC using GET_CALLER_PC.
#endif
}

MODIFY
instrumentation/SanitizerCoveragePCGUARD.so.cc
instrumentation/SanitizerCoveragePCGUARD.so.cc
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/SpecialCaseList.h"
-#if LLVM_MAJOR > 10 || (LLVM_MAJOR == 10 && LLVM_MINOR > 0)
+#if LLVM_VERSION_MAJOR >= 11 || \
+ (LLVM_VERSION_MAJOR == 10 && LLVM_VERSION_MINOR >= 1)
#include "llvm/Support/VirtualFileSystem.h"
#endif
#include "llvm/Support/raw_ostream.h"
@@ -127,7 +128,7 @@ class ModuleSanitizerCoverage {
public:
ModuleSanitizerCoverage(
const SanitizerCoverageOptions &Options = SanitizerCoverageOptions()
-#if LLVM_MAJOR > 10
+#if (LLVM_VERSION_MAJOR >= 11)
,
const SpecialCaseList *Allowlist = nullptr,
const SpecialCaseList *Blocklist = nullptr
@@ -215,7 +216,7 @@ class ModuleSanitizerCoverageLegacyPass : public ModulePass {
public:
ModuleSanitizerCoverageLegacyPass(
const SanitizerCoverageOptions &Options = SanitizerCoverageOptions()
-#if LLVM_VERSION_MAJOR > 10
+#if LLVM_VERSION_MAJOR >= 11
,
const std::vector<std::string> &AllowlistFiles =
std::vector<std::string>(),
@@ -233,7 +234,7 @@ class ModuleSanitizerCoverageLegacyPass : public ModulePass {
bool runOnModule(Module &M) override {
ModuleSanitizerCoverage ModuleSancov(Options
-#if LLVM_MAJOR > 10
+#if (LLVM_VERSION_MAJOR >= 11)
,
Allowlist.get(), Blocklist.get()
#endif
@@ -283,7 +284,7 @@ PreservedAnalyses ModuleSanitizerCoveragePass::run(Module & M,
ModuleAnalysisManager &MAM) {
ModuleSanitizerCoverage ModuleSancov(Options
-#if LLVM_MAJOR > 10
+#if (LLVM_VERSION_MAJOR >= 11)
,
Allowlist.get(), Blocklist.get()
#endif
@@ -749,7 +750,7 @@ GlobalVariable *ModuleSanitizerCoverage::CreateFunctionLocalArrayInSection(
*CurModule, ArrayTy, false, GlobalVariable::PrivateLinkage,
Constant::getNullValue(ArrayTy), "__sancov_gen_");
-#if LLVM_VERSION_MAJOR > 12
+#if LLVM_VERSION_MAJOR >= 13
if (TargetTriple.supportsCOMDAT() &&
(TargetTriple.isOSBinFormatELF() || !F.isInterposable()))
if (auto Comdat = getOrCreateFunctionComdat(F, TargetTriple))
@@ -762,7 +763,8 @@ GlobalVariable *ModuleSanitizerCoverage::CreateFunctionLocalArrayInSection(
#endif
Array->setSection(getSectionName(Section));
-#if LLVM_MAJOR > 10 || (LLVM_MAJOR == 10 && LLVM_MINOR > 0)
+#if (LLVM_VERSION_MAJOR >= 11) || \
+ (LLVM_VERSION_MAJOR == 10 && LLVM_VERSION_MINOR >= 1)
Array->setAlignment(Align(DL->getTypeStoreSize(Ty).getFixedSize()));
#else
Array->setAlignment(Align(4)); // cheating
@@ -868,7 +870,7 @@ bool ModuleSanitizerCoverage::InjectCoverage(Function & F,
}
-#if LLVM__MAJOR > 11
+#if (LLVM_VERSION_MAJOR >= 12)
else if (t->getTypeID() == llvm::Type::FixedVectorTyID) {
FixedVectorType *tt = dyn_cast<FixedVectorType>(t);
@@ -962,7 +964,7 @@ bool ModuleSanitizerCoverage::InjectCoverage(Function & F,
} else
-#if LLVM_VERSION_MAJOR > 13
+#if LLVM_VERSION_MAJOR >= 14
if (t->getTypeID() == llvm::Type::FixedVectorTyID) {
FixedVectorType *tt = dyn_cast<FixedVectorType>(t);
@@ -1484,7 +1486,7 @@ INITIALIZE_PASS_END(ModuleSanitizerCoverageLegacyPass, "sancov",
ModulePass *llvm::createModuleSanitizerCoverageLegacyPassPass(
const SanitizerCoverageOptions &Options
-#if LLVM_MAJOR > 10
+#if (LLVM_VERSION_MAJOR >= 11)
,
const std::vector<std::string> &AllowlistFiles,
const std::vector<std::string> &BlocklistFiles
@@ -1492,7 +1494,7 @@ ModulePass *llvm::createModuleSanitizerCoverageLegacyPassPass(
) {
return new ModuleSanitizerCoverageLegacyPass(Options
-#if LLVM_MAJOR > 10
+#if (LLVM_VERSION_MAJOR >= 11)
,
AllowlistFiles, BlocklistFiles
#endif

MODIFY
instrumentation/afl-llvm-common.cc
instrumentation/afl-llvm-common.cc
@@ -281,7 +281,7 @@ void scanForDangerousFunctions(llvm::Module *M) {
if (!M) return;
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9)
for (GlobalIFunc &IF : M->ifuncs()) {

MODIFY
instrumentation/afl-llvm-lto-instrumentlist.so.cc
instrumentation/afl-llvm-lto-instrumentlist.so.cc
@@ -116,14 +116,14 @@ bool AFLcheckIfInstrument::runOnModule(Module &M) {
auto & Ctx = F.getContext();
AttributeList Attrs = F.getAttributes();
-#if LLVM_VERSION_MAJOR < 14
+#if LLVM_VERSION_MAJOR >= 14
+ AttributeList NewAttrs = Attrs.addFnAttribute(Ctx, "skipinstrument");
+ F.setAttributes(NewAttrs);
+#else
AttrBuilder NewAttrs;
NewAttrs.addAttribute("skipinstrument");
F.setAttributes(
Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
-#else
- AttributeList NewAttrs = Attrs.addFnAttribute(Ctx, "skipinstrument");
- F.setAttributes(NewAttrs);
#endif
}

MODIFY
instrumentation/afl-llvm-pass.so.cc
instrumentation/afl-llvm-pass.so.cc
@@ -52,7 +52,7 @@ typedef long double max_align_t;
#include "llvm/Support/MathExtras.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/CFG.h"
@@ -114,7 +114,7 @@ uint64_t PowerOf2Ceil(unsigned in) {
#endif
/* #if LLVM_VERSION_STRING >= "4.0.1" */
-#if LLVM_VERSION_MAJOR > 4 || \
+#if LLVM_VERSION_MAJOR >= 5 || \
(LLVM_VERSION_MAJOR == 4 && LLVM_VERSION_PATCH >= 1)
#define AFL_HAVE_VECTOR_INTRINSICS 1
#endif
@@ -662,22 +662,7 @@ bool AFLCoverage::runOnModule(Module &M) {
/* Update bitmap */
if (use_threadsafe_counters) { /* Atomic */
- /*
- #if LLVM_VERSION_MAJOR < 9
- if (neverZero_counters_str !=
- NULL) { // with llvm 9 we make this the default as the bug
- in llvm
- // is then fixed
- #else
- if (!skip_nozero) {
- #endif
- // register MapPtrIdx in a todo list
- todo.push_back(MapPtrIdx);
-
- } else {
-
- */
IRB.CreateAtomicRMW(llvm::AtomicRMWInst::BinOp::Add, MapPtrIdx, One,
#if LLVM_VERSION_MAJOR >= 13
llvm::MaybeAlign(1),
@@ -696,13 +681,12 @@ bool AFLCoverage::runOnModule(Module &M) {
Value *Incr = IRB.CreateAdd(Counter, One);
-#if LLVM_VERSION_MAJOR < 9
- if (neverZero_counters_str !=
- NULL) { // with llvm 9 we make this the default as the bug in llvm
- // is then fixed
-#else
+#if LLVM_VERSION_MAJOR >= 9
if (!skip_nozero) {
+#else
+ if (neverZero_counters_str != NULL) {
+
#endif
/* hexcoder: Realize a counter that skips zero during overflow.
* Once this counter reaches its maximum value, it next increments to

MODIFY
instrumentation/cmplog-instructions-pass.cc
instrumentation/cmplog-instructions-pass.cc
#include "llvm/Pass.h"
#include "llvm/Analysis/ValueTracking.h"
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DebugInfo.h"
@@ -66,11 +66,11 @@ class CmpLogInstructions : public ModulePass {
bool runOnModule(Module &M) override;
-#if LLVM_VERSION_MAJOR < 4
- const char *getPassName() const override {
+#if LLVM_VERSION_MAJOR >= 4
+ StringRef getPassName() const override {
#else
- StringRef getPassName() const override {
+ const char *getPassName() const override {
#endif
return "cmplog instructions";
@@ -113,10 +113,10 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
IntegerType *Int64Ty = IntegerType::getInt64Ty(C);
IntegerType *Int128Ty = IntegerType::getInt128Ty(C);
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c1 = M.getOrInsertFunction("__cmplog_ins_hook1", VoidTy, Int8Ty, Int8Ty,
Int8Ty
@@ -125,16 +125,16 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookIns1 = cast<Function>(c1);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookIns1 = c1;
+#else
+ Function *cmplogHookIns1 = cast<Function>(c1);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c2 = M.getOrInsertFunction("__cmplog_ins_hook2", VoidTy, Int16Ty, Int16Ty,
Int8Ty
@@ -143,16 +143,16 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookIns2 = cast<Function>(c2);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookIns2 = c2;
+#else
+ Function *cmplogHookIns2 = cast<Function>(c2);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c4 = M.getOrInsertFunction("__cmplog_ins_hook4", VoidTy, Int32Ty, Int32Ty,
Int8Ty
@@ -161,16 +161,16 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookIns4 = cast<Function>(c4);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookIns4 = c4;
+#else
+ Function *cmplogHookIns4 = cast<Function>(c4);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c8 = M.getOrInsertFunction("__cmplog_ins_hook8", VoidTy, Int64Ty, Int64Ty,
Int8Ty
@@ -179,16 +179,16 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookIns8 = cast<Function>(c8);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookIns8 = c8;
+#else
+ Function *cmplogHookIns8 = cast<Function>(c8);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c16 = M.getOrInsertFunction("__cmplog_ins_hook16", VoidTy, Int128Ty,
Int128Ty, Int8Ty
@@ -203,10 +203,10 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
FunctionCallee cmplogHookIns16 = c16;
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
cN = M.getOrInsertFunction("__cmplog_ins_hookN", VoidTy, Int128Ty,
Int128Ty, Int8Ty, Int8Ty
@@ -215,10 +215,10 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookInsN = cast<Function>(cN);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookInsN = cN;
+#else
+ Function *cmplogHookInsN = cast<Function>(cN);
#endif
GlobalVariable *AFLCmplogPtr = M.getNamedGlobal("__afl_cmp_map");
@@ -338,7 +338,7 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
}
-#if LLVM_MAJOR > 11
+#if (LLVM_VERSION_MAJOR >= 12)
vector_cnt = tt->getElementCount().getKnownMinValue();
ty0 = tt->getElementType();
#endif
@@ -359,7 +359,7 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
max_size = 80;
else if (ty0->isFP128Ty() || ty0->isPPC_FP128Ty())
max_size = 128;
-#if LLVM_MAJOR > 11
+#if (LLVM_VERSION_MAJOR >= 12)
else if (ty0->getTypeID() != llvm::Type::PointerTyID && !be_quiet)
fprintf(stderr, "Warning: unsupported cmp type for cmplog: %u!\n",
ty0->getTypeID());
@@ -371,7 +371,7 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
if (ty0->isVectorTy()) {
-#if LLVM_MAJOR > 11
+#if (LLVM_VERSION_MAJOR >= 12)
VectorType *tt = dyn_cast<VectorType>(ty0);
if (!tt) {
@@ -397,7 +397,7 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
} else {
-#if LLVM_MAJOR > 11
+#if (LLVM_VERSION_MAJOR >= 12)
if (ty0->getTypeID() != llvm::Type::PointerTyID && !be_quiet) {
fprintf(stderr, "Warning: unsupported cmp type for cmplog: %u\n",

MODIFY
instrumentation/cmplog-routines-pass.cc
instrumentation/cmplog-routines-pass.cc
#include "llvm/Pass.h"
#include "llvm/Analysis/ValueTracking.h"
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DebugInfo.h"
@@ -65,11 +65,11 @@ class CmpLogRoutines : public ModulePass {
bool runOnModule(Module &M) override;
-#if LLVM_VERSION_MAJOR < 4
- const char *getPassName() const override {
+#if LLVM_VERSION_MAJOR >= 4
+ StringRef getPassName() const override {
#else
- StringRef getPassName() const override {
+ const char *getPassName() const override {
#endif
return "cmplog routines";
@@ -97,10 +97,10 @@ bool CmpLogRoutines::hookRtns(Module &M) {
IntegerType *Int64Ty = IntegerType::getInt64Ty(C);
PointerType *i8PtrTy = PointerType::get(Int8Ty, 0);
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c = M.getOrInsertFunction("__cmplog_rtn_hook", VoidTy, i8PtrTy, i8PtrTy
#if LLVM_VERSION_MAJOR < 5
@@ -108,16 +108,16 @@ bool CmpLogRoutines::hookRtns(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookFn = cast<Function>(c);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookFn = c;
+#else
+ Function *cmplogHookFn = cast<Function>(c);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c1 = M.getOrInsertFunction("__cmplog_rtn_llvm_stdstring_stdstring",
VoidTy, i8PtrTy, i8PtrTy
@@ -126,16 +126,16 @@ bool CmpLogRoutines::hookRtns(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogLlvmStdStd = cast<Function>(c1);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogLlvmStdStd = c1;
+#else
+ Function *cmplogLlvmStdStd = cast<Function>(c1);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c2 = M.getOrInsertFunction("__cmplog_rtn_llvm_stdstring_cstring", VoidTy,
i8PtrTy, i8PtrTy
@@ -144,16 +144,16 @@ bool CmpLogRoutines::hookRtns(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogLlvmStdC = cast<Function>(c2);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogLlvmStdC = c2;
+#else
+ Function *cmplogLlvmStdC = cast<Function>(c2);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c3 = M.getOrInsertFunction("__cmplog_rtn_gcc_stdstring_stdstring", VoidTy,
i8PtrTy, i8PtrTy
@@ -162,16 +162,16 @@ bool CmpLogRoutines::hookRtns(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogGccStdStd = cast<Function>(c3);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogGccStdStd = c3;
+#else
+ Function *cmplogGccStdStd = cast<Function>(c3);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c4 = M.getOrInsertFunction("__cmplog_rtn_gcc_stdstring_cstring", VoidTy,
i8PtrTy, i8PtrTy
@@ -180,16 +180,16 @@ bool CmpLogRoutines::hookRtns(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogGccStdC = cast<Function>(c4);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogGccStdC = c4;
+#else
+ Function *cmplogGccStdC = cast<Function>(c4);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c5 = M.getOrInsertFunction("__cmplog_rtn_hook_n", VoidTy, i8PtrTy,
i8PtrTy, Int64Ty
@@ -198,16 +198,16 @@ bool CmpLogRoutines::hookRtns(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookFnN = cast<Function>(c5);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookFnN = c5;
+#else
+ Function *cmplogHookFnN = cast<Function>(c5);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c6 = M.getOrInsertFunction("__cmplog_rtn_hook_strn", VoidTy, i8PtrTy,
i8PtrTy, Int64Ty
@@ -216,16 +216,16 @@ bool CmpLogRoutines::hookRtns(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookFnStrN = cast<Function>(c6);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookFnStrN = c6;
+#else
+ Function *cmplogHookFnStrN = cast<Function>(c6);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c7 = M.getOrInsertFunction("__cmplog_rtn_hook_str", VoidTy, i8PtrTy,
i8PtrTy
@@ -234,10 +234,10 @@ bool CmpLogRoutines::hookRtns(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookFnStr = cast<Function>(c7);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookFnStr = c7;
+#else
+ Function *cmplogHookFnStr = cast<Function>(c7);
#endif
GlobalVariable *AFLCmplogPtr = M.getNamedGlobal("__afl_cmp_map");

MODIFY
instrumentation/cmplog-switches-pass.cc
instrumentation/cmplog-switches-pass.cc
#include "llvm/Pass.h"
#include "llvm/Analysis/ValueTracking.h"
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DebugInfo.h"
@@ -112,10 +112,10 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
IntegerType *Int32Ty = IntegerType::getInt32Ty(C);
IntegerType *Int64Ty = IntegerType::getInt64Ty(C);
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c1 = M.getOrInsertFunction("__cmplog_ins_hook1", VoidTy, Int8Ty, Int8Ty,
Int8Ty
@@ -124,16 +124,16 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookIns1 = cast<Function>(c1);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookIns1 = c1;
+#else
+ Function *cmplogHookIns1 = cast<Function>(c1);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c2 = M.getOrInsertFunction("__cmplog_ins_hook2", VoidTy, Int16Ty, Int16Ty,
Int8Ty
@@ -142,16 +142,16 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookIns2 = cast<Function>(c2);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookIns2 = c2;
+#else
+ Function *cmplogHookIns2 = cast<Function>(c2);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c4 = M.getOrInsertFunction("__cmplog_ins_hook4", VoidTy, Int32Ty, Int32Ty,
Int8Ty
@@ -160,16 +160,16 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookIns4 = cast<Function>(c4);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookIns4 = c4;
+#else
+ Function *cmplogHookIns4 = cast<Function>(c4);
#endif
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c8 = M.getOrInsertFunction("__cmplog_ins_hook8", VoidTy, Int64Ty, Int64Ty,
Int8Ty
@@ -178,10 +178,10 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- Function *cmplogHookIns8 = cast<Function>(c8);
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee cmplogHookIns8 = c8;
+#else
+ Function *cmplogHookIns8 = cast<Function>(c8);
#endif
GlobalVariable *AFLCmplogPtr = M.getNamedGlobal("__afl_cmp_map");

MODIFY
instrumentation/compare-transform-pass.so.cc
instrumentation/compare-transform-pass.so.cc
#include "llvm/Pass.h"
#include "llvm/Analysis/ValueTracking.h"
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DebugInfo.h"
@@ -64,11 +64,11 @@ class CompareTransform : public ModulePass {
bool runOnModule(Module &M) override;
-#if LLVM_VERSION_MAJOR < 4
- const char *getPassName() const override {
+#if LLVM_VERSION_MAJOR >= 4
+ StringRef getPassName() const override {
#else
- StringRef getPassName() const override {
+ const char *getPassName() const override {
#endif
return "transforms compare functions";
@@ -100,17 +100,17 @@ 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
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee tolowerFn;
+#else
+ Function * tolowerFn;
#endif
{
-#if LLVM_VERSION_MAJOR < 9
- Constant *
-#else
+#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
+#else
+ Constant *
#endif
c = M.getOrInsertFunction("tolower", Int32Ty, Int32Ty
#if LLVM_VERSION_MAJOR < 5
@@ -118,10 +118,10 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
NULL
#endif
);
-#if LLVM_VERSION_MAJOR < 9
- tolowerFn = cast<Function>(c);
-#else
+#if LLVM_VERSION_MAJOR >= 9
tolowerFn = c;
+#else
+ tolowerFn = cast<Function>(c);
#endif
}
@@ -496,10 +496,10 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
PHINode *PN = PHINode::Create(
Int32Ty, (next_lenchk_bb ? 2 : 1) * unrollLen + 1, "cmp_phi");
-#if LLVM_VERSION_MAJOR < 8
- TerminatorInst *term = bb->getTerminator();
-#else
+#if LLVM_VERSION_MAJOR >= 8
Instruction *term = bb->getTerminator();
+#else
+ TerminatorInst *term = bb->getTerminator();
#endif
BranchInst::Create(next_lenchk_bb ? next_lenchk_bb : next_cmp_bb, bb);
term->eraseFromParent();

MODIFY
instrumentation/split-compares-pass.so.cc
instrumentation/split-compares-pass.so.cc
#include "llvm/IR/Module.h"
#include "llvm/IR/IRBuilder.h"
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DebugInfo.h"
@@ -796,7 +796,7 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
LLVMContext &C = M.getContext();
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 7)
const DataLayout &dl = M.getDataLayout();
@@ -1398,7 +1398,7 @@ bool SplitComparesTransform::runOnModule(Module &M) {
bool brokenDebug = false;
if (verifyModule(M, &errs()
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9)
,
&brokenDebug // 9th May 2016

MODIFY
instrumentation/split-switches-pass.so.cc
instrumentation/split-switches-pass.so.cc
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/IRBuilder.h"
-#if LLVM_VERSION_MAJOR > 3 || \
+#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DebugInfo.h"
@@ -369,10 +369,10 @@ bool SplitSwitchesTransform::splitSwitches(Module &M) {
CaseVector Cases;
for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end(); i != e;
++i)
-#if LLVM_VERSION_MAJOR < 5
- Cases.push_back(CaseExpr(i.getCaseValue(), i.getCaseSuccessor()));
-#else
+#if LLVM_VERSION_MAJOR >= 5
Cases.push_back(CaseExpr(i->getCaseValue(), i->getCaseSuccessor()));
+#else
+ Cases.push_back(CaseExpr(i.getCaseValue(), i.getCaseSuccessor()));
#endif
/* bugfix thanks to pbst
* round up bytesChecked (in case getBitWidth() % 8 != 0) */

MODIFY
src/afl-cc.c
src/afl-cc.c
@@ -574,7 +574,7 @@ static void edit_params(u32 argc, char **argv, char **envp) {
if (instrument_mode == INSTRUMENT_PCGUARD) {
-#if LLVM_MAJOR > 10 || (LLVM_MAJOR == 10 && LLVM_MINOR > 0)
+#if LLVM_MAJOR >= 11 || (LLVM_MAJOR == 10 && LLVM_MINOR >= 1)
#if defined __ANDROID__ || ANDROID
cc_params[cc_par_cnt++] = "-fsanitize-coverage=trace-pc-guard";
instrument_mode = INSTRUMENT_LLVMNATIVE;
@@ -1167,7 +1167,7 @@ int main(int argc, char **argv, char **envp) {
}
-#if (LLVM_MAJOR > 2)
+#if (LLVM_MAJOR >= 3)
if ((ptr = find_object("SanitizerCoverageLTO.so", argv[0])) != NULL) {
@@ -1196,7 +1196,7 @@ int main(int argc, char **argv, char **envp) {
}
-#if (LLVM_MAJOR > 2)
+#if (LLVM_MAJOR >= 3)
if (strncmp(callname, "afl-clang-fast", 14) == 0) {
@@ -1724,8 +1724,8 @@ int main(int argc, char **argv, char **envp) {
compiler_mode == LTO ? " [SELECTED]" : "",
have_llvm ? "AVAILABLE" : "unavailable!",
compiler_mode == LLVM ? " [SELECTED]" : "",
- LLVM_MAJOR > 6 ? "DEFAULT" : " ",
- LLVM_MAJOR > 6 ? " " : "DEFAULT",
+ LLVM_MAJOR >= 7 ? "DEFAULT" : " ",
+ LLVM_MAJOR >= 7 ? " " : "DEFAULT",
have_gcc_plugin ? "AVAILABLE" : "unavailable!",
compiler_mode == GCC_PLUGIN ? " [SELECTED]" : "",
have_gcc ? "AVAILABLE" : "unavailable!",
@@ -1826,12 +1826,12 @@ int main(int argc, char **argv, char **envp) {
" AFL_GCC_INSTRUMENT_FILE: enable selective instrumentation by "
"filename\n");
-#if LLVM_MAJOR < 9
+#if LLVM_MAJOR >= 9
#define COUNTER_BEHAVIOUR \
- " AFL_LLVM_NOT_ZERO: use cycling trace counters that skip zero\n"
+ " AFL_LLVM_SKIP_NEVERZERO: do not skip zero on trace counters\n"
#else
#define COUNTER_BEHAVIOUR \
- " AFL_LLVM_SKIP_NEVERZERO: do not skip zero on trace counters\n"
+ " AFL_LLVM_NOT_ZERO: use cycling trace counters that skip zero\n"
#endif
if (have_llvm)
SAYF(
@@ -1905,7 +1905,7 @@ int main(int argc, char **argv, char **envp) {
"consult the README.md, especially section 3.1 about instrumenting "
"targets.\n\n");
-#if (LLVM_MAJOR > 2)
+#if (LLVM_MAJOR >= 3)
if (have_lto)
SAYF("afl-cc LTO with ld=%s %s\n", AFL_REAL_LD, AFL_CLANG_FLTO);
if (have_llvm)
@@ -1967,9 +1967,7 @@ int main(int argc, char **argv, char **envp) {
if (instrument_mode == 0 && compiler_mode < GCC_PLUGIN) {
-#if LLVM_MAJOR <= 6
- instrument_mode = INSTRUMENT_AFL;
-#else
+#if LLVM_MAJOR >= 7
#if LLVM_MAJOR < 11 && (LLVM_MAJOR < 10 || LLVM_MINOR < 1)
if (have_instr_env) {
@@ -1984,6 +1982,8 @@ int main(int argc, char **argv, char **envp) {
#endif
instrument_mode = INSTRUMENT_PCGUARD;
+#else
+ instrument_mode = INSTRUMENT_AFL;
#endif
}

unify LLVM_VERSION_... usage