From a7912cb421db4f4039048cdba2b7fc98ae295342 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Wed, 3 Apr 2024 08:54:03 -0400 Subject: Put checks that detect UB under their own flag below debug_assertions --- compiler/rustc_session/src/config/cfg.rs | 6 ++++++ compiler/rustc_session/src/options.rs | 3 +++ compiler/rustc_session/src/session.rs | 4 ++++ 3 files changed, 13 insertions(+) (limited to 'compiler/rustc_session/src') diff --git a/compiler/rustc_session/src/config/cfg.rs b/compiler/rustc_session/src/config/cfg.rs index 337019f720b..34dcd0cf598 100644 --- a/compiler/rustc_session/src/config/cfg.rs +++ b/compiler/rustc_session/src/config/cfg.rs @@ -212,6 +212,10 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg { ins_none!(sym::test); } + if sess.ub_checks() { + ins_none!(sym::ub_checks); + } + ret } @@ -367,6 +371,8 @@ impl CheckCfg { ins!(sym::test, no_values); + ins!(sym::ub_checks, no_values); + ins!(sym::unix, no_values); ins!(sym::windows, no_values); } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index a76eb6b06aa..5e7c2465097 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1992,6 +1992,9 @@ written to standard error output)"), "in diagnostics, use heuristics to shorten paths referring to items"), tune_cpu: Option = (None, parse_opt_string, [TRACKED], "select processor to schedule for (`rustc --print target-cpus` for details)"), + #[rustc_lint_opt_deny_field_access("use `Session::ub_checks` instead of this field")] + ub_checks: Option = (None, parse_opt_bool, [TRACKED], + "emit runtime checks for Undefined Behavior (default: -Cdebug-assertions)"), ui_testing: bool = (false, parse_bool, [UNTRACKED], "emit compiler diagnostics in a form suitable for UI testing (default: no)"), uninit_const_chunk_threshold: usize = (16, parse_number, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 55fff4421ae..22ca8a3cf3e 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -735,6 +735,10 @@ impl Session { self.opts.cg.overflow_checks.unwrap_or(self.opts.debug_assertions) } + pub fn ub_checks(&self) -> bool { + self.opts.unstable_opts.ub_checks.unwrap_or(self.opts.debug_assertions) + } + pub fn relocation_model(&self) -> RelocModel { self.opts.cg.relocation_model.unwrap_or(self.target.relocation_model) } -- cgit 1.4.1-3-g733a5