Skip to content

Commit 0b8e94e

Browse files
authored
Merge pull request #1542 from rust-lang/disable_verifier
Disable clif ir verifier by default
2 parents 89c5aa9 + b98b620 commit 0b8e94e

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/base.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::ty::adjustment::PointerCoercion;
1414
use rustc_middle::ty::layout::FnAbiOf;
1515
use rustc_middle::ty::print::with_no_trimmed_paths;
1616

17+
use crate::BackendConfig;
1718
use crate::constant::ConstantCx;
1819
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
1920
use crate::inline_asm::codegen_naked_asm;
@@ -30,6 +31,7 @@ pub(crate) struct CodegenedFunction {
3031

3132
pub(crate) fn codegen_fn<'tcx>(
3233
tcx: TyCtxt<'tcx>,
34+
backend_config: &BackendConfig,
3335
cx: &mut crate::CodegenCx,
3436
type_dbg: &mut TypeDebugContext<'tcx>,
3537
cached_func: Function,
@@ -162,7 +164,7 @@ pub(crate) fn codegen_fn<'tcx>(
162164
}
163165

164166
// Verify function
165-
verify_func(tcx, &clif_comments, &func);
167+
verify_func(tcx, backend_config, &clif_comments, &func);
166168

167169
Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
168170
}
@@ -264,11 +266,16 @@ pub(crate) fn compile_fn(
264266
});
265267
}
266268

267-
pub(crate) fn verify_func(
269+
fn verify_func(
268270
tcx: TyCtxt<'_>,
271+
backend_config: &BackendConfig,
269272
writer: &crate::pretty_clif::CommentWriter,
270273
func: &Function,
271274
) {
275+
if !tcx.sess.verify_llvm_ir() && !backend_config.enable_verifier {
276+
return;
277+
}
278+
272279
tcx.prof.generic_activity("verify clif ir").run(|| {
273280
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
274281
match cranelift_codegen::verify_function(&func, &flags) {

src/driver/aot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ fn module_codegen(
516516
MonoItem::Fn(inst) => {
517517
if let Some(codegened_function) = crate::base::codegen_fn(
518518
tcx,
519+
&backend_config,
519520
&mut cx,
520521
&mut type_dbg,
521522
Function::new(),

src/driver/jit.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{BackendConfig, CodegenCx, CodegenMode};
2020

2121
struct JitState {
2222
jit_module: UnwindModule<JITModule>,
23+
backend_config: BackendConfig,
2324
}
2425

2526
thread_local! {
@@ -115,6 +116,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
115116
CodegenMode::Jit => {
116117
codegen_and_compile_fn(
117118
tcx,
119+
&backend_config,
118120
&mut cx,
119121
&mut cached_context,
120122
&mut jit_module,
@@ -169,7 +171,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
169171
LAZY_JIT_STATE.with(|lazy_jit_state| {
170172
let mut lazy_jit_state = lazy_jit_state.borrow_mut();
171173
assert!(lazy_jit_state.is_none());
172-
*lazy_jit_state = Some(JitState { jit_module });
174+
*lazy_jit_state = Some(JitState { jit_module, backend_config });
173175
});
174176

175177
let f: extern "C" fn(c_int, *const *const c_char) -> c_int =
@@ -205,6 +207,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
205207

206208
pub(crate) fn codegen_and_compile_fn<'tcx>(
207209
tcx: TyCtxt<'tcx>,
210+
backend_config: &BackendConfig,
208211
cx: &mut crate::CodegenCx,
209212
cached_context: &mut Context,
210213
module: &mut dyn Module,
@@ -221,6 +224,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
221224
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
222225
if let Some(codegened_func) = crate::base::codegen_fn(
223226
tcx,
227+
&backend_config,
224228
cx,
225229
&mut TypeDebugContext::default(),
226230
cached_func,
@@ -282,7 +286,14 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
282286
false,
283287
Symbol::intern("dummy_cgu_name"),
284288
);
285-
codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
289+
codegen_and_compile_fn(
290+
tcx,
291+
&lazy_jit_state.backend_config,
292+
&mut cx,
293+
&mut Context::new(),
294+
jit_module,
295+
instance,
296+
);
286297

287298
assert!(cx.global_asm.is_empty());
288299
jit_module.finalize_definitions();

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
278278

279279
let mut flags_builder = settings::builder();
280280
flags_builder.enable("is_pic").unwrap();
281-
let enable_verifier = if backend_config.enable_verifier { "true" } else { "false" };
281+
let enable_verifier =
282+
if sess.verify_llvm_ir() || backend_config.enable_verifier { "true" } else { "false" };
282283
flags_builder.set("enable_verifier", enable_verifier).unwrap();
283284
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
284285

0 commit comments

Comments
 (0)