@@ -784,8 +784,14 @@ extern "C" LLVMRustResult LLVMRustOptimize(
784784 // the PassBuilder does not create a pipeline.
785785 std::vector<std::function<void (ModulePassManager &, OptimizationLevel)>>
786786 PipelineStartEPCallbacks;
787+ #if LLVM_VERSION_GE(20, 0)
788+ std::vector<std::function<void (ModulePassManager &, OptimizationLevel,
789+ ThinOrFullLTOPhase)>>
790+ OptimizerLastEPCallbacks;
791+ #else
787792 std::vector<std::function<void (ModulePassManager &, OptimizationLevel)>>
788793 OptimizerLastEPCallbacks;
794+ #endif
789795
790796 if (!IsLinkerPluginLTO && SanitizerOptions && SanitizerOptions->SanitizeCFI &&
791797 !NoPrepopulatePasses) {
@@ -832,7 +838,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
832838 SanitizerOptions->SanitizeDataFlowABIList +
833839 SanitizerOptions->SanitizeDataFlowABIListLen );
834840 OptimizerLastEPCallbacks.push_back (
841+ #if LLVM_VERSION_GE(20, 0)
842+ [ABIListFiles](ModulePassManager &MPM, OptimizationLevel Level,
843+ ThinOrFullLTOPhase phase) {
844+ #else
835845 [ABIListFiles](ModulePassManager &MPM, OptimizationLevel Level) {
846+ #endif
836847 MPM.addPass (DataFlowSanitizerPass (ABIListFiles));
837848 });
838849 }
@@ -844,23 +855,39 @@ extern "C" LLVMRustResult LLVMRustOptimize(
844855 /* CompileKernel=*/ false ,
845856 /* EagerChecks=*/ true );
846857 OptimizerLastEPCallbacks.push_back (
858+ #if LLVM_VERSION_GE(20, 0)
859+ [Options](ModulePassManager &MPM, OptimizationLevel Level,
860+ ThinOrFullLTOPhase phase) {
861+ #else
847862 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
863+ #endif
848864 MPM.addPass (MemorySanitizerPass (Options));
849865 });
850866 }
851867
852868 if (SanitizerOptions->SanitizeThread ) {
853- OptimizerLastEPCallbacks.push_back ([](ModulePassManager &MPM,
854- OptimizationLevel Level) {
855- MPM.addPass (ModuleThreadSanitizerPass ());
856- MPM.addPass (createModuleToFunctionPassAdaptor (ThreadSanitizerPass ()));
857- });
869+ OptimizerLastEPCallbacks.push_back (
870+ #if LLVM_VERSION_GE(20, 0)
871+ [](ModulePassManager &MPM, OptimizationLevel Level,
872+ ThinOrFullLTOPhase phase) {
873+ #else
874+ [](ModulePassManager &MPM, OptimizationLevel Level) {
875+ #endif
876+ MPM.addPass (ModuleThreadSanitizerPass ());
877+ MPM.addPass (
878+ createModuleToFunctionPassAdaptor (ThreadSanitizerPass ()));
879+ });
858880 }
859881
860882 if (SanitizerOptions->SanitizeAddress ||
861883 SanitizerOptions->SanitizeKernelAddress ) {
862884 OptimizerLastEPCallbacks.push_back (
885+ #if LLVM_VERSION_GE(20, 0)
886+ [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level,
887+ ThinOrFullLTOPhase phase) {
888+ #else
863889 [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
890+ #endif
864891 auto CompileKernel = SanitizerOptions->SanitizeKernelAddress ;
865892 AddressSanitizerOptions opts = AddressSanitizerOptions{
866893 CompileKernel,
@@ -874,7 +901,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
874901 }
875902 if (SanitizerOptions->SanitizeHWAddress ) {
876903 OptimizerLastEPCallbacks.push_back (
904+ #if LLVM_VERSION_GE(20, 0)
905+ [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level,
906+ ThinOrFullLTOPhase phase) {
907+ #else
877908 [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
909+ #endif
878910 HWAddressSanitizerOptions opts (
879911 /* CompileKernel=*/ false ,
880912 SanitizerOptions->SanitizeHWAddressRecover ,
@@ -935,7 +967,11 @@ extern "C" LLVMRustResult LLVMRustOptimize(
935967 for (const auto &C : PipelineStartEPCallbacks)
936968 C (MPM, OptLevel);
937969 for (const auto &C : OptimizerLastEPCallbacks)
970+ #if LLVM_VERSION_GE(20, 0)
971+ C (MPM, OptLevel, ThinOrFullLTOPhase::None);
972+ #else
938973 C (MPM, OptLevel);
974+ #endif
939975 }
940976
941977 if (ExtraPassesLen) {
0 commit comments