Skip to content

Commit

Permalink
Retain compatibility with LLVM 6, 7, 8 and 9
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Nov 18, 2019
1 parent 6f169dd commit 5024d14
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/LTO/LTO.h"

#include "llvm-c/Transforms/PassManagerBuilder.h"

#include "llvm/Transforms/Instrumentation.h"
#if LLVM_VERSION_GE(9, 0)
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
#endif
#if LLVM_VERSION_GE(8, 0)
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
#endif

using namespace llvm;
using namespace llvm::legacy;

Expand Down Expand Up @@ -88,18 +93,30 @@ extern "C" LLVMPassRef LLVMRustCreateAddressSanitizerFunctionPass(bool Recover)
extern "C" LLVMPassRef LLVMRustCreateModuleAddressSanitizerPass(bool Recover) {
const bool CompileKernel = false;

#if LLVM_VERSION_GE(9, 0)
return wrap(createModuleAddressSanitizerLegacyPassPass(CompileKernel, Recover));
#else
return wrap(createAddressSanitizerModulePass(CompileKernel, Recover));
#endif
}

extern "C" LLVMPassRef LLVMRustCreateMemorySanitizerPass(int TrackOrigins, bool Recover) {
#if LLVM_VERSION_GE(8, 0)
const bool CompileKernel = false;

return wrap(createMemorySanitizerLegacyPassPass(
MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
#else
return wrap(createMemorySanitizerPass(TrackOrigins, Recover));
#endif
}

extern "C" LLVMPassRef LLVMRustCreateThreadSanitizerPass() {
#if LLVM_VERSION_GE(8, 0)
return wrap(createThreadSanitizerLegacyPassPass());
#else
return wrap(createThreadSanitizerPass());
#endif
}

extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) {
Expand Down

0 comments on commit 5024d14

Please sign in to comment.