Skip to content

Commit

Permalink
Warn on redundant --cfg directive when revisions are used
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Oct 19, 2024
1 parent b27f33a commit 7cc7974
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
14 changes: 13 additions & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,19 @@ impl<'test> TestCx<'test> {

if let Some(revision) = self.revision {
let normalized_revision = normalize_revision(revision);
cmd.args(&["--cfg", &normalized_revision]);
let cfg_arg = ["--cfg", &normalized_revision];
let arg = format!("--cfg={normalized_revision}");
if self
.props
.compile_flags
.windows(2)
.any(|args| args == cfg_arg || args[0] == arg || args[1] == arg)
{
panic!(
"error: redundant cfg argument `{normalized_revision}` is already created by the revision"
);
}
cmd.args(cfg_arg);
}

if !self.props.no_auto_check_cfg {
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/precondition-checks/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
//@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked requires
//@ revisions: toolarge badalign
//@[toolarge] compile-flags: --cfg toolarge
//@[badalign] compile-flags: --cfg badalign

fn main() {
unsafe {
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/sanitizer/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
//@ revisions: address cfi kcfi leak memory thread
//@compile-flags: -Ctarget-feature=-crt-static
//@[address]needs-sanitizer-address
//@[address]compile-flags: -Zsanitizer=address --cfg address
//@[address]compile-flags: -Zsanitizer=address
//@[cfi]needs-sanitizer-cfi
//@[cfi]compile-flags: -Zsanitizer=cfi --cfg cfi
//@[cfi]compile-flags: -Zsanitizer=cfi
//@[cfi]compile-flags: -Clto -Ccodegen-units=1
//@[kcfi]needs-llvm-components: x86
//@[kcfi]compile-flags: -Zsanitizer=kcfi --cfg kcfi --target x86_64-unknown-none
//@[kcfi]compile-flags: -Zsanitizer=kcfi --target x86_64-unknown-none
//@[kcfi]compile-flags: -C panic=abort
//@[leak]needs-sanitizer-leak
//@[leak]compile-flags: -Zsanitizer=leak --cfg leak
//@[leak]compile-flags: -Zsanitizer=leak
//@[memory]needs-sanitizer-memory
//@[memory]compile-flags: -Zsanitizer=memory --cfg memory
//@[memory]compile-flags: -Zsanitizer=memory
//@[thread]needs-sanitizer-thread
//@[thread]compile-flags: -Zsanitizer=thread --cfg thread
//@[thread]compile-flags: -Zsanitizer=thread

#![feature(cfg_sanitize, no_core, lang_items)]
#![crate_type="lib"]
Expand Down

0 comments on commit 7cc7974

Please sign in to comment.