Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit abc4788

Browse files
committed
Add new test directive needs-atomic to support #87377
1 parent 9959f98 commit abc4788

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

‎src/tools/compiletest/src/common.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,16 @@ impl Config {
477477
ASM_SUPPORTED_ARCHS.contains(&self.target_cfg().arch.as_str())
478478
}
479479

480+
pub fn has_atomic(&self, size: Option<u64>) -> bool {
481+
if let Some(size) = size {
482+
(self.target_cfg().min_atomic_width()..=self.target_cfg().max_atomic_width())
483+
.contains(&size)
484+
&& self.target_cfg().atomic_cas
485+
} else {
486+
self.target_cfg().atomic_cas
487+
}
488+
}
489+
480490
pub fn git_config(&self) -> GitConfig<'_> {
481491
GitConfig {
482492
git_repository: &self.git_repository,
@@ -645,12 +655,26 @@ pub struct TargetCfg {
645655
pub(crate) xray: bool,
646656
#[serde(default = "default_reloc_model")]
647657
pub(crate) relocation_model: String,
658+
#[serde(default)]
659+
max_atomic_width: Option<u64>,
660+
#[serde(default)]
661+
min_atomic_width: Option<u64>,
662+
#[serde(default = "default_atomic_cas")]
663+
atomic_cas: bool,
648664
}
649665

650666
impl TargetCfg {
651667
pub(crate) fn os_and_env(&self) -> String {
652668
format!("{}-{}", self.os, self.env)
653669
}
670+
671+
fn max_atomic_width(&self) -> u64 {
672+
self.max_atomic_width.unwrap_or(self.pointer_width as _)
673+
}
674+
675+
fn min_atomic_width(&self) -> u64 {
676+
self.min_atomic_width.unwrap_or(8)
677+
}
654678
}
655679

656680
fn default_os() -> String {
@@ -661,6 +685,10 @@ fn default_reloc_model() -> String {
661685
"pic".into()
662686
}
663687

688+
fn default_atomic_cas() -> bool {
689+
true
690+
}
691+
664692
#[derive(Eq, PartialEq, Clone, Debug, Default, serde::Deserialize)]
665693
#[serde(rename_all = "kebab-case")]
666694
pub enum Endian {

‎src/tools/compiletest/src/directive-list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
127127
"min-llvm-version",
128128
"min-system-llvm-version",
129129
"needs-asm-support",
130+
"needs-atomic",
130131
"needs-deterministic-layouts",
131132
"needs-dlltool",
132133
"needs-dynamic-linking",

‎src/tools/compiletest/src/header/needs.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ pub(super) fn handle_needs(
1414
condition: &mut |_| config.has_asm_support().then_some(IgnoreDecision::Continue),
1515
ignore_reason: "ignored on targets without inline assembly support",
1616
},
17+
Need {
18+
name: "needs-atomic",
19+
condition: &mut |comment| {
20+
let Some(comment_content) = comment else {
21+
return Some(IgnoreDecision::Continue);
22+
};
23+
if comment_content.trim().is_empty() {
24+
return Some(IgnoreDecision::Continue);
25+
}
26+
27+
let (size, rest) = match comment_content.trim_start().split_once([':', ' ']) {
28+
Some((size, rest)) => (size, Some(rest)),
29+
None => (comment_content.trim(), None),
30+
};
31+
eprintln!("size={size}, rest={rest:?}");
32+
33+
let size = if size == "ptr" {
34+
*comment = rest;
35+
Some(config.target_cfg().pointer_width as _)
36+
} else if let Ok(size) = size.parse() {
37+
if ![128, 64, 32, 16, 8].contains(&size) {
38+
return Some(IgnoreDecision::Error {
39+
message: "expected values for `needs-atomic` are: (none), `128`,\
40+
`16`, `32`, `64`, `8`, and `ptr"
41+
.into(),
42+
});
43+
} else {
44+
*comment = rest;
45+
Some(size)
46+
}
47+
} else {
48+
None
49+
};
50+
config.has_atomic(size).then_some(IgnoreDecision::Continue)
51+
},
52+
ignore_reason: "ignored on targets without atomic operations",
53+
},
1754
Need {
1855
name: "needs-sanitizer-support",
1956
condition: &mut |_| cache.sanitizer_support.then_some(IgnoreDecision::Continue),

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /