Skip to content

Disable LLVM verification by default #51230

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

Merged
merged 3 commits into from
Jul 11, 2018
Merged
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
3 changes: 3 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
@@ -356,6 +356,9 @@
# Print backtrace on internal compiler errors during bootstrap
#backtrace-on-ice = false

# Whether to verify generated LLVM IR
#verify-llvm-ir = false

# =============================================================================
# Options for specific targets
#
4 changes: 4 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
@@ -283,6 +283,10 @@ fn main() {
cmd.arg("--cfg").arg("parallel_queries");
}

if env::var_os("RUSTC_VERIFY_LLVM_IR").is_some() {
cmd.arg("-Z").arg("verify-llvm-ir");
}

let color = match env::var("RUSTC_COLOR") {
Ok(s) => usize::from_str(&s).expect("RUSTC_COLOR should be an integer"),
Err(_) => 0,
4 changes: 4 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
@@ -898,6 +898,10 @@ impl<'a> Builder<'a> {
cargo.env("RUSTC_BACKTRACE_ON_ICE", "1");
}

if self.config.rust_verify_llvm_ir {
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
}

cargo.env("RUSTC_VERBOSE", format!("{}", self.verbosity));

// in std, we want to avoid denying warnings for stage 0 as that makes cfg's painful.
3 changes: 3 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
@@ -105,6 +105,7 @@ pub struct Config {
pub rust_dist_src: bool,
pub rust_codegen_backends: Vec<Interned<String>>,
pub rust_codegen_backends_dir: String,
pub rust_verify_llvm_ir: bool,

pub build: Interned<String>,
pub hosts: Vec<Interned<String>>,
@@ -311,6 +312,7 @@ struct Rust {
lld: Option<bool>,
deny_warnings: Option<bool>,
backtrace_on_ice: Option<bool>,
verify_llvm_ir: Option<bool>,
}

/// TOML representation of how each build target is configured.
@@ -542,6 +544,7 @@ impl Config {
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);

if let Some(ref backends) = rust.codegen_backends {
config.rust_codegen_backends = backends.iter()
6 changes: 3 additions & 3 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
@@ -1152,8 +1152,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"gather codegen statistics"),
asm_comments: bool = (false, parse_bool, [TRACKED],
"generate comments into the assembly (may change behavior)"),
no_verify: bool = (false, parse_bool, [TRACKED],
"skip LLVM verification"),
verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
"verify LLVM IR"),
borrowck_stats: bool = (false, parse_bool, [UNTRACKED],
"gather borrowck statistics"),
no_landing_pads: bool = (false, parse_bool, [TRACKED],
@@ -3097,7 +3097,7 @@ mod tests {
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.debugging_opts.no_verify = true;
opts.debugging_opts.verify_llvm_ir = true;
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
4 changes: 2 additions & 2 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
@@ -513,8 +513,8 @@ impl Session {
pub fn asm_comments(&self) -> bool {
self.opts.debugging_opts.asm_comments
}
pub fn no_verify(&self) -> bool {
self.opts.debugging_opts.no_verify
pub fn verify_llvm_ir(&self) -> bool {
self.opts.debugging_opts.verify_llvm_ir
}
pub fn borrowck_stats(&self) -> bool {
self.opts.debugging_opts.borrowck_stats
17 changes: 11 additions & 6 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
@@ -461,9 +461,12 @@ fn run_pass_manager(cgcx: &CodegenContext,
unsafe {
let pm = llvm::LLVMCreatePassManager();
llvm::LLVMRustAddAnalysisPasses(tm, pm, llmod);
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
assert!(!pass.is_null());
llvm::LLVMRustAddPass(pm, pass);

if config.verify_llvm_ir {
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
assert!(!pass.is_null());
llvm::LLVMRustAddPass(pm, pass);
}

// When optimizing for LTO we don't actually pass in `-O0`, but we force
// it to always happen at least with `-O1`.
@@ -494,9 +497,11 @@ fn run_pass_manager(cgcx: &CodegenContext,
}
});

let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
assert!(!pass.is_null());
llvm::LLVMRustAddPass(pm, pass);
if config.verify_llvm_ir {
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
assert!(!pass.is_null());
llvm::LLVMRustAddPass(pm, pass);
}

time_ext(cgcx.time_passes, None, "LTO passes", ||
llvm::LLVMRunPassManager(pm, llmod));
8 changes: 4 additions & 4 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
@@ -232,7 +232,7 @@ pub struct ModuleConfig {
emit_obj: bool,
// Miscellaneous flags. These are mostly copied from command-line
// options.
no_verify: bool,
pub verify_llvm_ir: bool,
no_prepopulate_passes: bool,
no_builtins: bool,
time_passes: bool,
@@ -271,7 +271,7 @@ impl ModuleConfig {
embed_bitcode_marker: false,
no_integrated_as: false,

no_verify: false,
verify_llvm_ir: false,
no_prepopulate_passes: false,
no_builtins: false,
time_passes: false,
@@ -283,7 +283,7 @@ impl ModuleConfig {
}

fn set_flags(&mut self, sess: &Session, no_builtins: bool) {
self.no_verify = sess.no_verify();
self.verify_llvm_ir = sess.verify_llvm_ir();
self.no_prepopulate_passes = sess.opts.cg.no_prepopulate_passes;
self.no_builtins = no_builtins || sess.target.target.options.no_builtins;
self.time_passes = sess.time_passes();
@@ -542,7 +542,7 @@ unsafe fn optimize(cgcx: &CodegenContext,
true
};

if !config.no_verify { assert!(addpass("verify")); }
if config.verify_llvm_ir { assert!(addpass("verify")); }
if !config.no_prepopulate_passes {
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);