diff options
Diffstat (limited to 'libre/clamav/Add-support-for-LLVM-3.7.patch')
-rw-r--r-- | libre/clamav/Add-support-for-LLVM-3.7.patch | 740 |
1 files changed, 0 insertions, 740 deletions
diff --git a/libre/clamav/Add-support-for-LLVM-3.7.patch b/libre/clamav/Add-support-for-LLVM-3.7.patch deleted file mode 100644 index 8bcd1d7ea..000000000 --- a/libre/clamav/Add-support-for-LLVM-3.7.patch +++ /dev/null @@ -1,740 +0,0 @@ -From 3b1b2e757d0d1f13a3f234abf05d6e5015f52744 Mon Sep 17 00:00:00 2001 -From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> -Date: Fri, 14 Oct 2016 20:24:39 +0200 -Subject: Add support for LLVM 3.7 - -Main changes: -The DataLayoutPass is no longer necessary. -The LoopInfo pass is now a WrapperPass. -Before creating TargetLibraryInfo one needs to create a -TargetLibraryInfoImpl. -PassManager is now in the legacy:: namespace. -GetElementPtrInst::getIndexedType changed behavior causing segfaults in -the testsuite; emulating the old behavior now. -CreateCallX functions for fixed number X of elements got removed. -JITEmitDebugInfo Option was removed. -DIDescriptor was removed. - -Patch-Name: Add-support-for-LLVM-3.7.patch ---- - libclamav/c++/ClamBCRTChecks.cpp | 34 ++++++- - libclamav/c++/PointerTracking.cpp | 44 ++++++++- - libclamav/c++/bytecode2llvm.cpp | 181 +++++++++++++++++++++++++++++++++++--- - libclamav/c++/m4/llvm-flags.m4 | 4 +- - 4 files changed, 244 insertions(+), 19 deletions(-) - -diff --git a/libclamav/c++/ClamBCRTChecks.cpp b/libclamav/c++/ClamBCRTChecks.cpp -index 97099b2..35f7272 100644 ---- a/libclamav/c++/ClamBCRTChecks.cpp -+++ b/libclamav/c++/ClamBCRTChecks.cpp -@@ -201,9 +201,11 @@ namespace llvm { - TD = &getAnalysis<TargetData>(); - #elif LLVM_VERSION < 35 - TD = &getAnalysis<DataLayout>(); --#else -+#elif LLVM_VERSION < 37 - DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); - TD = DLP ? &DLP->getDataLayout() : 0; -+#else -+ TD = &F.getEntryBlock().getModule()->getDataLayout(); - #endif - SE = &getAnalysis<ScalarEvolution>(); - PT = &getAnalysis<PointerTracking>(); -@@ -212,7 +214,11 @@ namespace llvm { - #else - DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); - #endif -+#if LLVM_VERSION < 37 - expander = new SCEVExpander(*SE OPT("SCEVexpander")); -+#else -+ expander = new SCEVExpander(*SE, *TD OPT("SCEVexpander")); -+#endif - - std::vector<Instruction*> insns; - -@@ -351,8 +357,10 @@ namespace llvm { - AU.addRequired<TargetData>(); - #elif LLVM_VERSION < 35 - AU.addRequired<DataLayout>(); --#else -+#elif LLVM_VERSION < 37 - AU.addRequired<DataLayoutPass>(); -+#else -+ // No DataLayout pass needed anymore. - #endif - #if LLVM_VERSION < 35 - AU.addRequired<DominatorTree>(); -@@ -406,7 +414,11 @@ namespace llvm { - if (BaseMap.count(P)) { - return BaseMap[Ptr] = BaseMap[P]; - } -+#if LLVM_VERSION < 37 - Value *P2 = GetUnderlyingObject(P, TD); -+#else -+ Value *P2 = GetUnderlyingObject(P, *TD); -+#endif - if (P2 != P) { - Value *V = getPointerBase(P2); - return BaseMap[Ptr] = V; -@@ -524,7 +536,11 @@ namespace llvm { - } - } - if (LoadInst *LI = dyn_cast<LoadInst>(Base)) { -+#if LLVM_VERSION < 37 - Value *V = GetUnderlyingObject(LI->getPointerOperand()->stripPointerCasts(), TD); -+#else -+ Value *V = GetUnderlyingObject(LI->getPointerOperand()->stripPointerCasts(), *TD); -+#endif - if (Argument *A = dyn_cast<Argument>(V)) { - if (A->getArgNo() == 0) { - // pointers from hidden ctx are trusted to be at least the -@@ -651,7 +667,11 @@ namespace llvm { - } - BasicBlock *BB = I->getParent(); - BasicBlock::iterator It = I; -+#if LLVM_VERSION < 37 - BasicBlock *newBB = SplitBlock(BB, &*It, this); -+#else -+ BasicBlock *newBB = SplitBlock(BB, &*It); -+#endif - PHINode *PN; - unsigned MDDbgKind = I->getContext().getMDKindID("dbg"); - //verifyFunction(*BB->getParent()); -@@ -696,9 +716,15 @@ namespace llvm { - unsigned locationid = 0; - bool Approximate; - if (MDNode *Dbg = getLocation(I, Approximate, MDDbgKind)) { -+#if LLVM_VERSION < 37 - DILocation Loc(Dbg); - locationid = Loc.getLineNumber() << 8; - unsigned col = Loc.getColumnNumber(); -+#else -+ DebugLoc Loc(Dbg); -+ locationid = Loc.getLine() << 8; -+ unsigned col = Loc.getCol(); -+#endif - if (col > 254) - col = 254; - if (Approximate) -@@ -912,7 +938,11 @@ INITIALIZE_PASS_DEPENDENCY(TargetData) - #elif LLVM_VERSION < 35 - INITIALIZE_PASS_DEPENDENCY(DataLayout) - #else -+#if LLVM_VERSION < 37 - INITIALIZE_PASS_DEPENDENCY(DataLayoutPass) -+#else -+// No DataLayout pass needed anymore. -+#endif - #endif - #if LLVM_VERSION < 35 - INITIALIZE_PASS_DEPENDENCY(DominatorTree) -diff --git a/libclamav/c++/PointerTracking.cpp b/libclamav/c++/PointerTracking.cpp -index 8e17a4a..67340e8 100644 ---- a/libclamav/c++/PointerTracking.cpp -+++ b/libclamav/c++/PointerTracking.cpp -@@ -30,7 +30,11 @@ - #include "llvm/IR/InstIterator.h" - #endif - #include "llvm/Support/raw_ostream.h" -+#if LLVM_VERSION < 37 - #include "llvm/Target/TargetLibraryInfo.h" -+#else -+#include <llvm/Analysis/TargetLibraryInfo.h> -+#endif - - #if LLVM_VERSION < 32 - #include "llvm/Target/TargetData.h" -@@ -70,7 +74,11 @@ INITIALIZE_PASS_DEPENDENCY(DominatorTree) - #else - INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) - #endif -+#if LLVM_VERSION < 37 - INITIALIZE_PASS_DEPENDENCY(LoopInfo) -+#else -+INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) -+#endif - INITIALIZE_PASS_DEPENDENCY(ScalarEvolution) - #if LLVM_VERSION < 35 - INITIALIZE_PASS_DEPENDENCY(DominatorTree) -@@ -96,12 +104,18 @@ bool PointerTracking::runOnFunction(Function &F) { - TD = getAnalysisIfAvailable<TargetData>(); - #elif LLVM_VERSION < 35 - TD = getAnalysisIfAvailable<DataLayout>(); --#else -+#elif LLVM_VERSION < 37 - DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); - TD = DLP ? &DLP->getDataLayout() : 0; -+#else -+ TD = &F.getEntryBlock().getModule()->getDataLayout(); - #endif - SE = &getAnalysis<ScalarEvolution>(); -+#if LLVM_VERSION < 37 - LI = &getAnalysis<LoopInfo>(); -+#else -+ LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); -+#endif - #if LLVM_VERSION < 35 - DT = &getAnalysis<DominatorTree>(); - #else -@@ -116,7 +130,11 @@ void PointerTracking::getAnalysisUsage(AnalysisUsage &AU) const { - #else - AU.addRequiredTransitive<DominatorTreeWrapperPass>(); - #endif -+#if LLVM_VERSION < 37 - AU.addRequiredTransitive<LoopInfo>(); -+#else -+ AU.addRequiredTransitive<LoopInfoWrapperPass>(); -+#endif - AU.addRequiredTransitive<ScalarEvolution>(); - AU.setPreservesAll(); - } -@@ -178,12 +196,19 @@ const SCEV *PointerTracking::computeAllocationCount(Value *P, - if (CallInst *CI = extractMallocCall(V)) { - Value *arraySize = getMallocArraySize(CI, TD); - constType* AllocTy = getMallocAllocatedType(CI); --#else -+#elif LLVM_VERSION < 37 - TargetLibraryInfo* TLI = new TargetLibraryInfo(); - - if (CallInst *CI = extractMallocCall(V, TLI)) { - Value *arraySize = getMallocArraySize(CI, TD, TLI); - constType* AllocTy = getMallocAllocatedType(CI, TLI); -+#else -+ TargetLibraryInfoImpl* TLII = new TargetLibraryInfoImpl(); -+ TargetLibraryInfo* TLI = new TargetLibraryInfo(*TLII); -+ -+ if (CallInst *CI = extractMallocCall(V, TLI)) { -+ Value *arraySize = getMallocArraySize(CI, *TD, TLI); -+ constType* AllocTy = getMallocAllocatedType(CI, TLI); - #endif - if (!AllocTy || !arraySize) return SE->getCouldNotCompute(); - Ty = AllocTy; -@@ -240,7 +265,7 @@ Value *PointerTracking::computeAllocationCountValue(Value *P, constType *&Ty) co - if (!Ty) - return 0; - Value *arraySize = getMallocArraySize(CI, TD); --#else -+#elif LLVM_VERSION < 37 - TargetLibraryInfo* TLI = new TargetLibraryInfo(); - - if (CallInst *CI = extractMallocCall(V, TLI)) { -@@ -248,6 +273,15 @@ Value *PointerTracking::computeAllocationCountValue(Value *P, constType *&Ty) co - if (!Ty) - return 0; - Value *arraySize = getMallocArraySize(CI, TD, TLI); -+#else -+ TargetLibraryInfoImpl* TLII = new TargetLibraryInfoImpl(); -+ TargetLibraryInfo* TLI = new TargetLibraryInfo(*TLII); -+ -+ if (CallInst *CI = extractMallocCall(V, TLI)) { -+ Ty = getMallocAllocatedType(CI, TLI); -+ if (!Ty) -+ return 0; -+ Value *arraySize = getMallocArraySize(CI, *TD, TLI); - #endif - if (!arraySize) { - Ty = Type::getInt8Ty(P->getContext()); -@@ -351,7 +385,11 @@ void PointerTracking::getPointerOffset(Value *Pointer, Value *&Base, - const SCEV *&Offset) const - { - Pointer = Pointer->stripPointerCasts(); -+#if LLVM_VERSION < 37 - Base = GetUnderlyingObject(Pointer, TD); -+#else -+ Base = GetUnderlyingObject(Pointer, *TD); -+#endif - Limit = getAllocationSizeInBytes(Base); - if (isa<SCEVCouldNotCompute>(Limit)) { - Base = 0; -diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp -index e5aea03..2171993 100644 ---- a/libclamav/c++/bytecode2llvm.cpp -+++ b/libclamav/c++/bytecode2llvm.cpp -@@ -63,7 +63,11 @@ - #include "llvm/Object/ObjectFile.h" - #endif - #include "llvm/ExecutionEngine/JITEventListener.h" -+#if LLVM_VERSION < 37 - #include "llvm/PassManager.h" -+#else -+#include "llvm/IR/LegacyPassManager.h" -+#endif - #include "llvm/Support/Compiler.h" - #include "llvm/Support/Debug.h" - #include "llvm/Support/CommandLine.h" -@@ -231,7 +235,9 @@ namespace { - #define llvm_report_error(x) report_fatal_error(x) - #define llvm_install_error_handler(x) install_fatal_error_handler(x) - #define DwarfExceptionHandling JITExceptionHandling -+#if LLVM_VERSION < 37 - #define SetCurrentDebugLocation(x) SetCurrentDebugLocation(DebugLoc::getFromDILocation(x)) -+#endif - #define DEFINEPASS(passname) passname() : FunctionPass(ID) - #else - #define DEFINEPASS(passname) passname() : FunctionPass(&ID) -@@ -718,7 +724,11 @@ class RuntimeLimits : public FunctionPass { - BBMap[BB] = apicalls; - } - if (!BackedgeTargets.empty()) { -+#if LLVM_VERSION < 37 - LoopInfo &LI = getAnalysis<LoopInfo>(); -+#else -+ LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); -+#endif - ScalarEvolution &SE = getAnalysis<ScalarEvolution>(); - - // Now check whether any of these backedge targets are part of a loop -@@ -802,7 +812,11 @@ class RuntimeLimits : public FunctionPass { - #endif - // Load Flag that tells us we timed out (first byte in bc_ctx) - Value *Cond = Builder.CreateLoad(Flag, true); -+#if LLVM_VERSION < 37 - BasicBlock *newBB = SplitBlock(BB, BB->getTerminator(), this); -+#else -+ BasicBlock *newBB = SplitBlock(BB, BB->getTerminator()); -+#endif - TerminatorInst *TI = BB->getTerminator(); - BranchInst::Create(AbrtBB, newBB, Cond, TI); - TI->eraseFromParent(); -@@ -823,7 +837,11 @@ class RuntimeLimits : public FunctionPass { - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesAll(); -+#if LLVM_VERSION < 37 - AU.addRequired<LoopInfo>(); -+#else -+ AU.addRequired<LoopInfoWrapperPass>(); -+#endif - AU.addRequired<ScalarEvolution>(); - #if LLVM_VERSION < 35 - AU.addRequired<DominatorTree>(); -@@ -916,7 +934,11 @@ class LLVMCodegen { - Module *M; - LLVMContext &Context; - ExecutionEngine *EE; -+#if LLVM_VERSION < 37 - FunctionPassManager &PM, &PMUnsigned; -+#else -+ legacy::FunctionPassManager &PM, &PMUnsigned; -+#endif - LLVMTypeMapper *TypeMap; - - Function **apiFuncs; -@@ -1089,7 +1111,11 @@ class LLVMCodegen { - Constant *C = ConstantExpr::getPointerCast(GV, IP8Ty); - //TODO: check constant bounds here - return ConstantExpr::getPointerCast( -+#if LLVM_VERSION < 37 - ConstantExpr::getInBoundsGetElementPtr(C, ARRAYREF(Value*, idxs, 1)), -+#else -+ ConstantExpr::getInBoundsGetElementPtr(Ty, C, ARRAYREF(Value*, idxs, 1)), -+#endif - PTy); - } - if (isa<IntegerType>(Ty)) { -@@ -1118,15 +1144,21 @@ class LLVMCodegen { - - public: - LLVMCodegen(const struct cli_bc *bc, Module *M, struct CommonFunctions *CF, FunctionMapTy &cFuncs, -+#if LLVM_VERSION < 37 - ExecutionEngine *EE, FunctionPassManager &PM, FunctionPassManager &PMUnsigned, -+#else -+ ExecutionEngine *EE, legacy::FunctionPassManager &PM, legacy::FunctionPassManager &PMUnsigned, -+#endif - Function **apiFuncs, LLVMTypeMapper &apiMap) - : bc(bc), M(M), Context(M->getContext()), EE(EE), - PM(PM),PMUnsigned(PMUnsigned), TypeMap(), apiFuncs(apiFuncs),apiMap(apiMap), - compiledFunctions(cFuncs), BytecodeID("bc"+Twine(bc->id)), - #if LLVM_VERSION < 32 - Folder(EE->getTargetData()), Builder(Context, Folder), Values(), CF(CF) { --#else -+#elif LLVM_VERSION < 37 - Folder(EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) { -+#else -+ Folder(*EE->getDataLayout()), Builder(Context, Folder), Values(), CF(CF) { - #endif - - for (unsigned i=0;i<cli_apicall_maxglobal - _FIRST_GLOBAL;i++) { -@@ -1141,7 +1173,17 @@ class LLVMCodegen { - template <typename InputIterator> - #endif - Value* createGEP(Value *Base, constType *ETy, ARRAYREFPARAM(Value*,InputIterator Start,InputIterator End,ARef)) { -+#if LLVM_VERSION < 37 - constType *Ty = GetElementPtrInst::getIndexedType(Base->getType(),ARRAYREFP(Start,End,ARef)); -+#else -+ Type *Ty = NULL; -+ // This used to be done internally in LLVM's getIndexedTypeInternal. -+ PointerType *PTy = dyn_cast<PointerType>(Base->getType()->getScalarType()); -+ if (PTy) { -+ Type *Agg = PTy->getElementType(); -+ Ty = GetElementPtrInst::getIndexedType(Agg,ARRAYREFP(Start,End,ARef)); -+ } -+#endif - if (!Ty || (ETy && (Ty != ETy && (!isa<IntegerType>(Ty) || !isa<IntegerType>(ETy))))) { - if (cli_debug_flag) { - std::string str; -@@ -1457,7 +1499,11 @@ class LLVMCodegen { - if (func->dbgnodes[c] != ~0u) { - unsigned j = func->dbgnodes[c]; - assert(j < mdnodes.size()); -+#if LLVM_VERSION < 37 - Builder.SetCurrentDebugLocation(mdnodes[j]); -+#else -+ Builder.SetCurrentDebugLocation(DebugLoc(mdnodes[j])); -+#endif - } else - Builder.SetCurrentDebugLocation(0); - } -@@ -1767,11 +1813,16 @@ class LLVMCodegen { - #if LLVM_VERSION < 29 - CallInst *c = Builder.CreateCall4(CF->FMemset, Dst, Val, Len, - ConstantInt::get(Type::getInt32Ty(Context), 1)); --#else -+#elif LLVM_VERSION < 37 - CallInst *c = Builder.CreateCall5(CF->FMemset, Dst, Val, Len, - ConstantInt::get(Type::getInt32Ty(Context), 1), - ConstantInt::get(Type::getInt1Ty(Context), 0) - ); -+#else -+ Value *args[] = { Dst, Val, Len, -+ ConstantInt::get(Type::getInt32Ty(Context), 1), -+ ConstantInt::get(Type::getInt1Ty(Context), 0)}; -+ CallInst *c = Builder.CreateCall(CF->FMemset, ARRAYREF(Value*, args, args + 5)); - #endif - c->setTailCall(true); - c->setDoesNotThrow(); -@@ -1788,11 +1839,16 @@ class LLVMCodegen { - #if LLVM_VERSION < 29 - CallInst *c = Builder.CreateCall4(CF->FMemcpy, Dst, Src, Len, - ConstantInt::get(Type::getInt32Ty(Context), 1)); --#else -+#elif LLVM_VERSION < 37 - CallInst *c = Builder.CreateCall5(CF->FMemcpy, Dst, Src, Len, - ConstantInt::get(Type::getInt32Ty(Context), 1), - ConstantInt::get(Type::getInt1Ty(Context), 0) - ); -+#else -+ Value *args[] = { Dst, Src, Len, -+ ConstantInt::get(Type::getInt32Ty(Context), 1), -+ ConstantInt::get(Type::getInt1Ty(Context), 0)}; -+ CallInst *c = Builder.CreateCall(CF->FMemcpy, ARRAYREF(Value*, args, args + 5)); - #endif - c->setTailCall(true); - c->setDoesNotThrow(); -@@ -1809,10 +1865,15 @@ class LLVMCodegen { - #if LLVM_VERSION < 29 - CallInst *c = Builder.CreateCall4(CF->FMemmove, Dst, Src, Len, - ConstantInt::get(Type::getInt32Ty(Context), 1)); --#else -+#elif LLVM_VERSION < 37 - CallInst *c = Builder.CreateCall5(CF->FMemmove, Dst, Src, Len, - ConstantInt::get(Type::getInt32Ty(Context), 1), - ConstantInt::get(Type::getInt1Ty(Context), 0)); -+#else -+ Value *args[] = {Dst, Src, Len, -+ ConstantInt::get(Type::getInt32Ty(Context), 1), -+ ConstantInt::get(Type::getInt1Ty(Context), 0)}; -+ CallInst *c = Builder.CreateCall(CF->FMemmove, args); - #endif - c->setTailCall(true); - c->setDoesNotThrow(); -@@ -1830,7 +1891,12 @@ class LLVMCodegen { - #else - Value *Len = convertOperand(func, EE->getDataLayout()->getIntPtrType(Context), inst->u.three[2]); - #endif -+#if LLVM_VERSION < 37 - CallInst *c = Builder.CreateCall3(CF->FRealmemcmp, Dst, Src, Len); -+#else -+ Value *args[] = {Dst, Src, Len}; -+ CallInst *c = Builder.CreateCall(CF->FRealmemcmp, ARRAYREF(Value*, args, args + 3)); -+#endif - c->setTailCall(true); - c->setDoesNotThrow(); - Store(inst->dest, c); -@@ -2211,7 +2277,11 @@ static void addFunctionProtos(struct CommonFunctions *CF, ExecutionEngine *EE, M - } - #if LLVM_VERSION >= 29 - INITIALIZE_PASS_BEGIN(RuntimeLimits, "rl", "Runtime Limits", false, false) -+#if LLVM_VERSION < 37 - INITIALIZE_PASS_DEPENDENCY(LoopInfo) -+#else -+INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) -+#endif - INITIALIZE_PASS_DEPENDENCY(ScalarEvolution) - #if LLVM_VERSION < 35 - INITIALIZE_PASS_DEPENDENCY(DominatorTree) -@@ -2437,8 +2507,10 @@ static void addFPasses(FunctionPassManager &FPM, bool trusted, const TargetData - static void addFPasses(FunctionPassManager &FPM, bool trusted, const DataLayout *TD) - #elif LLVM_VERSION < 36 - static void addFPasses(FunctionPassManager &FPM, bool trusted, const Module *M) --#else -+#elif LLVM_VERSION < 37 - static void addFPasses(FunctionPassManager &FPM, bool trusted, Module *M) -+#else -+static void addFPasses(legacy::FunctionPassManager &FPM, bool trusted, Module *M) - #endif - { - // Set up the optimizer pipeline. Start with registering info about how -@@ -2449,10 +2521,12 @@ static void addFPasses(FunctionPassManager &FPM, bool trusted, Module *M) - FPM.add(new DataLayout(*TD)); - #elif LLVM_VERSION < 36 - FPM.add(new DataLayoutPass(M)); --#else -+#elif LLVM_VERSION < 37 - DataLayoutPass *DLP = new DataLayoutPass(); - DLP->doInitialization(*M); - FPM.add(DLP); -+#else -+ // No DataLayout pass needed anymore. - #endif - // Promote allocas to registers. - FPM.add(createPromoteMemoryToRegisterPass()); -@@ -2482,6 +2556,8 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs) - - #if LLVM_VERSION >= 31 - TargetOptions Options; -+#if LLVM_VERSION < 37 -+ // This option was removed. - #ifdef CL_DEBUG - //disable this for now, it leaks - Options.JITEmitDebugInfo = false; -@@ -2489,6 +2565,7 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs) - #else - Options.JITEmitDebugInfo = false; - #endif -+#endif - #if LLVM_VERSION < 34 - Options.DwarfExceptionHandling = false; - #else -@@ -2525,7 +2602,11 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs) - struct CommonFunctions CF; - addFunctionProtos(&CF, EE, M); - -+#if LLVM_VERSION < 37 - FunctionPassManager OurFPM(M), OurFPMUnsigned(M); -+#else -+ legacy::FunctionPassManager OurFPM(M), OurFPMUnsigned(M); -+#endif - #if LLVM_VERSION < 32 - M->setDataLayout(EE->getTargetData()->getStringRepresentation()); - #else -@@ -2665,17 +2746,23 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs) - break; - } - } -+#if LLVM_VERSION < 37 - PassManager PM; -+#else -+ legacy::PassManager PM; -+#endif - #if LLVM_VERSION < 32 - PM.add(new TargetData(*EE->getTargetData())); - #elif LLVM_VERSION < 35 - PM.add(new DataLayout(*EE->getDataLayout())); - #elif LLVM_VERSION < 36 - PM.add(new DataLayoutPass(M)); --#else -+#elif LLVM_VERSION < 37 - DataLayoutPass *DLP = new DataLayoutPass(); - DLP->doInitialization(*M); - PM.add(DLP); -+#else -+ // No DataLayout pass needed anymore. - #endif - // TODO: only run this on the untrusted bytecodes, not all of them... - if (has_untrusted) -@@ -2987,11 +3074,19 @@ static Metadata *findDbgGlobalDeclare(GlobalVariable *V) { - return 0; - - for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { -+#if LLVM_VERSION < 37 - DIDescriptor DIG(cast<MDNode>(NMD->getOperand(i))); - if (!DIG.isGlobalVariable()) - continue; - if (DIGlobalVariable(DIG).getGlobal() == V) - return DIG; -+#else -+ MDNode *DIG = NMD->getOperand(i); -+ if (!DIGlobalVariable::classof(DIG)) -+ continue; -+ if ((cast<DIGlobalVariable>(DIG))->getVariable() == V) -+ return DIG; -+#endif - } - return 0; - } -@@ -3008,11 +3103,19 @@ static Metadata *findDbgSubprogramDeclare(Function *V) { - return 0; - - for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { -+#if LLVM_VERSION < 37 - DIDescriptor DIG(cast<MDNode>(NMD->getOperand(i))); - if (!DIG.isSubprogram()) - continue; - if (DISubprogram(DIG).getFunction() == V) - return DIG; -+#else -+ MDNode *DIG = NMD->getOperand(i); -+ if (!DISubprogram::classof(DIG)) -+ continue; -+ if ((cast<DISubprogram>(DIG))->getFunction() == V) -+ return DIG; -+#endif - } - return 0; - } -@@ -3061,22 +3164,39 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName, - Metadata *DIGV = findDbgGlobalDeclare(GV); - #endif - if (!DIGV) return false; -+#if LLVM_VERSION < 37 - DIGlobalVariable Var(cast<MDNode>(DIGV)); -+#else -+ DIGlobalVariable *Var = cast<DIGlobalVariable>(DIGV); -+#endif - -+#if LLVM_VERSION < 37 - StringRef D = Var.getDisplayName(); -+#else -+ StringRef D = Var->getDisplayName(); -+#endif - if (!D.empty()) - DisplayName = D; -+#if LLVM_VERSION < 37 - LineNo = Var.getLineNumber(); -+#else -+ LineNo = Var->getLine(); -+#endif - #if LLVM_VERSION < 33 - Unit = Var.getCompileUnit(); --#else -+#elif LLVM_VERSION < 37 - G = Var.getFilename(); - H = Var.getDirectory(); -+#else -+ G = Var->getFilename(); -+ H = Var->getDirectory(); - #endif - #if LLVM_VERSION < 35 - TypeD = Var.getType(); --#else -+#elif LLVM_VERSION < 37 - T = Var.getType().getName(); -+#else -+ T = (cast<DIType>(*Var->getType())).getName(); - #endif - } else if (Function *F = dyn_cast<Function>(const_cast<Value*>(V))){ - #if LLVM_VERSION < 36 -@@ -3085,32 +3205,61 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName, - Metadata *DIF = findDbgSubprogramDeclare(F); - #endif - if (!DIF) return false; -+#if LLVM_VERSION < 37 - DISubprogram Var(cast<MDNode>(DIF)); -+#else -+ DISubprogram *Var = cast<DISubprogram>(DIF); -+#endif - -+#if LLVM_VERSION < 37 - StringRef D = Var.getDisplayName(); -+#else -+ StringRef D = Var->getDisplayName(); -+#endif - if (!D.empty()) - DisplayName = D; -+#if LLVM_VERSION < 37 - LineNo = Var.getLineNumber(); -+#else -+ LineNo = Var->getLine(); -+#endif - #if LLVM_VERSION < 33 - Unit = Var.getCompileUnit(); --#else -+#elif LLVM_VERSION < 37 - G = Var.getFilename(); - H = Var.getDirectory(); -+#else -+ G = Var->getFilename(); -+ H = Var->getDirectory(); - #endif - #if LLVM_VERSION < 35 - TypeD = Var.getType(); --#else -+#elif LLVM_VERSION < 37 - T = Var.getType().getName(); -+#else -+ T = Var->getType()->getName(); - #endif - } else { - const DbgDeclareInst *DDI = findDbgDeclare(V); - if (!DDI) return false; -+#if LLVM_VERSION < 37 - DIVariable Var(cast<MDNode>(DDI->getVariable())); -+#else -+ DIVariable* Var = DDI->getVariable(); -+#endif - -+#if LLVM_VERSION < 37 - StringRef D = Var.getName(); -+#else -+ StringRef D = Var->getName(); -+#endif - if (!D.empty()) - DisplayName = D; -+#if LLVM_VERSION < 37 - LineNo = Var.getLineNumber(); -+#else -+ LineNo = Var->getLine(); -+#endif - #if LLVM_VERSION < 33 - Unit = Var.getCompileUnit(); - #else -@@ -3120,8 +3269,10 @@ static bool getLocationInfo(const Value *V, std::string &DisplayName, - #endif - #if LLVM_VERSION < 35 - TypeD = Var.getType(); --#else -+#elif LLVM_VERSION < 37 - T = Var.getType().getName(); -+#else -+ T = (cast<DIType>(*Var->getType())).getName(); - #endif - } - -@@ -3157,9 +3308,15 @@ void printValue(llvm::Value *V, bool a, bool b) { - - void printLocation(llvm::Instruction *I, bool a, bool b) { - if (MDNode *N = I->getMetadata("dbg")) { -+#if LLVM_VERSION < 37 - DILocation Loc(N); - errs() << Loc.getFilename() << ":" << Loc.getLineNumber(); - if (unsigned Col = Loc.getColumnNumber()) { -+#else -+ DebugLoc Loc(N); -+ errs() << Loc.get()->getFilename() << ":" << Loc.getLine(); -+ if (unsigned Col = Loc.getCol()) { -+#endif - errs() << ":" << Col; - } - errs() << ": "; -diff --git a/libclamav/c++/m4/llvm-flags.m4 b/libclamav/c++/m4/llvm-flags.m4 -index dce4e10..04d6833 100644 ---- a/libclamav/c++/m4/llvm-flags.m4 -+++ b/libclamav/c++/m4/llvm-flags.m4 -@@ -98,14 +98,14 @@ elif test $llvmver_test -lt 290; then - elif test $llvmver_test -lt 360; then - llvmcomp="jit nativecodegen scalaropts ipo" - AC_MSG_RESULT([ok ($llvmver)]) --elif test $llvmver_test -lt 370; then -+elif test $llvmver_test -lt 380; then - dnl LLVM 3.6.0 removed jit, so we have to use mcjit - dnl and we're using InitializeNativeTargetAsmParser, so we need the architecture specific parsers - llvmcomp="mcjit nativecodegen scalaropts ipo x86asmparser powerpcasmparser" - AC_MSG_RESULT([ok ($llvmver)]) - else - AC_MSG_RESULT([no ($llvmver)]) -- AC_MSG_ERROR([LLVM < 3.7 required, but "$llvmver"($llvmver_test) found]) -+ AC_MSG_ERROR([LLVM < 3.8 required, but "$llvmver"($llvmver_test) found]) - fi - - dnl aquire the required flags to properly link in external LLVM |