Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke OptimizerLastEPCallbacks in PreLinkThinLTO #69665

Merged
merged 3 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,15 +868,23 @@ LLVMRustOptimizeWithNewPassManager(
} else {
for (const auto &C : PipelineStartEPCallbacks)
PB.registerPipelineStartEPCallback(C);
for (const auto &C : OptimizerLastEPCallbacks)
PB.registerOptimizerLastEPCallback(C);
if (OptStage != LLVMRustOptStage::PreLinkThinLTO) {
for (const auto &C : OptimizerLastEPCallbacks)
PB.registerOptimizerLastEPCallback(C);
}

switch (OptStage) {
case LLVMRustOptStage::PreLinkNoLTO:
MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
break;
case LLVMRustOptStage::PreLinkThinLTO:
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);
if (!OptimizerLastEPCallbacks.empty()) {
FunctionPassManager FPM(DebugPassManager);
for (const auto &C : OptimizerLastEPCallbacks)
C(FPM, OptLevel);
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
}
break;
case LLVMRustOptStage::PreLinkFatLTO:
MPM = PB.buildLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);
Expand Down
4 changes: 2 additions & 2 deletions src/test/codegen/sanitizer-recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//[MSAN-RECOVER-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-recover=memory -C lto=fat
//
// MSAN-NOT: @__msan_keep_going
// MSAN-RECOVER: @__msan_keep_going = weak_odr {{.*}} constant i32 1
// MSAN-RECOVER-LTO: @__msan_keep_going = weak_odr {{.*}} constant i32 1
// MSAN-RECOVER: @__msan_keep_going = weak_odr {{.*}}constant i32 1
// MSAN-RECOVER-LTO: @__msan_keep_going = weak_odr {{.*}}constant i32 1

// ASAN-LABEL: define i32 @penguin(
// ASAN: call void @__asan_report_load4(i64 %0)
Expand Down
27 changes: 27 additions & 0 deletions src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Regression test for sanitizer function instrumentation passes not
// being run when compiling with new LLVM pass manager and ThinLTO.
// Note: The issue occured only on non-zero opt-level.
//
// min-llvm-version 9.0
// needs-sanitizer-support
// only-x86_64
//
// no-prefer-dynamic
// revisions: opt0 opt1
// compile-flags: -Znew-llvm-pass-manager=yes -Zsanitizer=address -Clto=thin
//[opt0]compile-flags: -Copt-level=0
//[opt1]compile-flags: -Copt-level=1
// run-fail
// error-pattern: ERROR: AddressSanitizer: stack-use-after-scope

static mut P: *mut usize = std::ptr::null_mut();

fn main() {
unsafe {
{
let mut x = 0;
P = &mut x;
}
std::ptr::write_volatile(P, 123);
}
}
18 changes: 18 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ fn no_system_llvm() {
assert!(parse_rs(&config, "// no-system-llvm").ignore);
}

#[test]
fn llvm_version() {
let mut config = config();

config.llvm_version = Some("8.1.2-rust".to_owned());
assert!(parse_rs(&config, "// min-llvm-version 9.0").ignore);

config.llvm_version = Some("9.0.1-rust-1.43.0-dev".to_owned());
assert!(parse_rs(&config, "// min-llvm-version 9.2").ignore);

config.llvm_version = Some("9.3.1-rust-1.43.0-dev".to_owned());
assert!(!parse_rs(&config, "// min-llvm-version 9.2").ignore);

// FIXME.
// config.llvm_version = Some("10.0.0-rust".to_owned());
// assert!(!parse_rs(&config, "// min-llvm-version 9.0").ignore);
}

#[test]
fn ignore_target() {
let mut config = config();
Expand Down