Add -Zlint-llvm-ir
This commit is contained in:
parent
c9bd03cb72
commit
9589eb95d2
@ -573,6 +573,7 @@ pub(crate) unsafe fn llvm_optimize(
|
|||||||
cgcx.opts.cg.linker_plugin_lto.enabled(),
|
cgcx.opts.cg.linker_plugin_lto.enabled(),
|
||||||
config.no_prepopulate_passes,
|
config.no_prepopulate_passes,
|
||||||
config.verify_llvm_ir,
|
config.verify_llvm_ir,
|
||||||
|
config.lint_llvm_ir,
|
||||||
using_thin_buffers,
|
using_thin_buffers,
|
||||||
config.merge_functions,
|
config.merge_functions,
|
||||||
unroll_loops,
|
unroll_loops,
|
||||||
|
@ -2217,6 +2217,7 @@ pub fn LLVMRustOptimize<'a>(
|
|||||||
IsLinkerPluginLTO: bool,
|
IsLinkerPluginLTO: bool,
|
||||||
NoPrepopulatePasses: bool,
|
NoPrepopulatePasses: bool,
|
||||||
VerifyIR: bool,
|
VerifyIR: bool,
|
||||||
|
LintIR: bool,
|
||||||
UseThinLTOBuffers: bool,
|
UseThinLTOBuffers: bool,
|
||||||
MergeFunctions: bool,
|
MergeFunctions: bool,
|
||||||
UnrollLoops: bool,
|
UnrollLoops: bool,
|
||||||
|
@ -111,6 +111,7 @@ pub struct ModuleConfig {
|
|||||||
// Miscellaneous flags. These are mostly copied from command-line
|
// Miscellaneous flags. These are mostly copied from command-line
|
||||||
// options.
|
// options.
|
||||||
pub verify_llvm_ir: bool,
|
pub verify_llvm_ir: bool,
|
||||||
|
pub lint_llvm_ir: bool,
|
||||||
pub no_prepopulate_passes: bool,
|
pub no_prepopulate_passes: bool,
|
||||||
pub no_builtins: bool,
|
pub no_builtins: bool,
|
||||||
pub time_module: bool,
|
pub time_module: bool,
|
||||||
@ -236,6 +237,7 @@ macro_rules! if_regular {
|
|||||||
bc_cmdline: sess.target.bitcode_llvm_cmdline.to_string(),
|
bc_cmdline: sess.target.bitcode_llvm_cmdline.to_string(),
|
||||||
|
|
||||||
verify_llvm_ir: sess.verify_llvm_ir(),
|
verify_llvm_ir: sess.verify_llvm_ir(),
|
||||||
|
lint_llvm_ir: sess.opts.unstable_opts.lint_llvm_ir,
|
||||||
no_prepopulate_passes: sess.opts.cg.no_prepopulate_passes,
|
no_prepopulate_passes: sess.opts.cg.no_prepopulate_passes,
|
||||||
no_builtins: no_builtins || sess.target.no_builtins,
|
no_builtins: no_builtins || sess.target.no_builtins,
|
||||||
|
|
||||||
|
@ -793,6 +793,7 @@ macro_rules! tracked {
|
|||||||
tracked!(instrument_xray, Some(InstrumentXRay::default()));
|
tracked!(instrument_xray, Some(InstrumentXRay::default()));
|
||||||
tracked!(link_directives, false);
|
tracked!(link_directives, false);
|
||||||
tracked!(link_only, true);
|
tracked!(link_only, true);
|
||||||
|
tracked!(lint_llvm_ir, true);
|
||||||
tracked!(llvm_module_flag, vec![("bar".to_string(), 123, "max".to_string())]);
|
tracked!(llvm_module_flag, vec![("bar".to_string(), 123, "max".to_string())]);
|
||||||
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
|
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
|
||||||
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
|
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
|
||||||
|
@ -713,7 +713,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
|
|||||||
LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef,
|
LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef,
|
||||||
LLVMRustPassBuilderOptLevel OptLevelRust, LLVMRustOptStage OptStage,
|
LLVMRustPassBuilderOptLevel OptLevelRust, LLVMRustOptStage OptStage,
|
||||||
bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR,
|
bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR,
|
||||||
bool UseThinLTOBuffers, bool MergeFunctions, bool UnrollLoops,
|
bool LintIR, bool UseThinLTOBuffers, bool MergeFunctions, bool UnrollLoops,
|
||||||
bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls,
|
bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls,
|
||||||
bool EmitLifetimeMarkers, LLVMRustSanitizerOptions *SanitizerOptions,
|
bool EmitLifetimeMarkers, LLVMRustSanitizerOptions *SanitizerOptions,
|
||||||
const char *PGOGenPath, const char *PGOUsePath, bool InstrumentCoverage,
|
const char *PGOGenPath, const char *PGOUsePath, bool InstrumentCoverage,
|
||||||
@ -842,6 +842,13 @@ extern "C" LLVMRustResult LLVMRustOptimize(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LintIR) {
|
||||||
|
PipelineStartEPCallbacks.push_back(
|
||||||
|
[](ModulePassManager &MPM, OptimizationLevel Level) {
|
||||||
|
MPM.addPass(createModuleToFunctionPassAdaptor(LintPass()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (InstrumentGCOV) {
|
if (InstrumentGCOV) {
|
||||||
PipelineStartEPCallbacks.push_back(
|
PipelineStartEPCallbacks.push_back(
|
||||||
[](ModulePassManager &MPM, OptimizationLevel Level) {
|
[](ModulePassManager &MPM, OptimizationLevel Level) {
|
||||||
|
@ -1795,6 +1795,8 @@ pub(crate) fn parse_wasm_c_abi(slot: &mut WasmCAbi, v: Option<&str>) -> bool {
|
|||||||
"link the `.rlink` file generated by `-Z no-link` (default: no)"),
|
"link the `.rlink` file generated by `-Z no-link` (default: no)"),
|
||||||
linker_features: LinkerFeaturesCli = (LinkerFeaturesCli::default(), parse_linker_features, [UNTRACKED],
|
linker_features: LinkerFeaturesCli = (LinkerFeaturesCli::default(), parse_linker_features, [UNTRACKED],
|
||||||
"a comma-separated list of linker features to enable (+) or disable (-): `lld`"),
|
"a comma-separated list of linker features to enable (+) or disable (-): `lld`"),
|
||||||
|
lint_llvm_ir: bool = (false, parse_bool, [TRACKED],
|
||||||
|
"lint LLVM IR (default: no)"),
|
||||||
lint_mir: bool = (false, parse_bool, [UNTRACKED],
|
lint_mir: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"lint MIR before and after each transformation"),
|
"lint MIR before and after each transformation"),
|
||||||
llvm_module_flag: Vec<(String, u32, String)> = (Vec::new(), parse_llvm_module_flag, [TRACKED],
|
llvm_module_flag: Vec<(String, u32, String)> = (Vec::new(), parse_llvm_module_flag, [TRACKED],
|
||||||
|
7
src/doc/unstable-book/src/compiler-flags/lint-llvm-ir.md
Normal file
7
src/doc/unstable-book/src/compiler-flags/lint-llvm-ir.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# `lint-llvm-ir`
|
||||||
|
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
This flag will add `LintPass` to the start of the pipeline.
|
||||||
|
You can use it to check for common errors in the LLVM IR generated by `rustc`.
|
||||||
|
You can add `-Cllvm-args=-lint-abort-on-error` to abort the process if errors were found.
|
@ -1,7 +1,7 @@
|
|||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
//@ revisions:aarch64 loongarch64 powerpc64 sparc64 x86_64
|
//@ revisions:aarch64 loongarch64 powerpc64 sparc64 x86_64
|
||||||
// FIXME: Add `-Cllvm-args=--lint-abort-on-error` after LLVM 19
|
//@ min-llvm-version: 19
|
||||||
//@ compile-flags: -O -C no-prepopulate-passes -C passes=lint
|
//@ compile-flags: -O -Cno-prepopulate-passes -Zlint-llvm-ir -Cllvm-args=-lint-abort-on-error
|
||||||
|
|
||||||
//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu
|
//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu
|
||||||
//@[aarch64] needs-llvm-components: arm
|
//@[aarch64] needs-llvm-components: arm
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//@ revisions: linux apple
|
//@ revisions: linux apple
|
||||||
//@ compile-flags: -C opt-level=0 -C no-prepopulate-passes -C passes=lint
|
//@ min-llvm-version: 19
|
||||||
|
//@ compile-flags: -Copt-level=0 -Cno-prepopulate-passes -Zlint-llvm-ir -Cllvm-args=-lint-abort-on-error
|
||||||
|
|
||||||
//@[linux] compile-flags: --target x86_64-unknown-linux-gnu
|
//@[linux] compile-flags: --target x86_64-unknown-linux-gnu
|
||||||
//@[linux] needs-llvm-components: x86
|
//@[linux] needs-llvm-components: x86
|
||||||
|
Loading…
Reference in New Issue
Block a user