Skip to content

Commit b4fb021

Browse files
committed
handle cfg on clobber_abi
1 parent ead0a60 commit b4fb021

File tree

1 file changed

+42
-17
lines changed
  • compiler/rustc_builtin_macros/src

1 file changed

+42
-17
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ fn eat_operand_keyword<'a>(
6262

6363
/// A parsed list of attributes that is not attached to any item.
6464
/// Used to check whether `asm!` arguments are configured out.
65-
struct AsmAttrList(ast::AttrVec);
65+
struct AsmAttrVec(ast::AttrVec);
6666

67-
impl AsmAttrList {
67+
impl AsmAttrVec {
6868
fn parse<'a>(ecx: &ExtCtxt<'a>, p: &mut Parser<'a>) -> PResult<'a, Self> {
6969
let span_start = p.token.span;
7070

@@ -86,6 +86,28 @@ impl AsmAttrList {
8686
Ok(Self(attributes))
8787
}
8888
}
89+
impl ast::HasAttrs for AsmAttrVec {
90+
// Follows `ast::Expr`.
91+
const SUPPORTS_CUSTOM_INNER_ATTRS: bool = false;
92+
93+
fn attrs(&self) -> &[rustc_ast::Attribute] {
94+
&self.0
95+
}
96+
97+
fn visit_attrs(&mut self, f: impl FnOnce(&mut rustc_ast::AttrVec)) {
98+
f(&mut self.0)
99+
}
100+
}
101+
102+
impl ast::HasTokens for AsmAttrVec {
103+
fn tokens(&self) -> Option<&rustc_ast::tokenstream::LazyAttrTokenStream> {
104+
None
105+
}
106+
107+
fn tokens_mut(&mut self) -> Option<&mut Option<rustc_ast::tokenstream::LazyAttrTokenStream>> {
108+
None
109+
}
110+
}
89111

90112
fn parse_args<'a>(
91113
ecx: &ExtCtxt<'a>,
@@ -107,11 +129,18 @@ pub fn parse_asm_args<'a>(
107129
) -> PResult<'a, AsmArgs> {
108130
let dcx = p.dcx();
109131

132+
let strip_unconfigured = rustc_expand::config::StripUnconfigured {
133+
sess: ecx.sess,
134+
features: Some(ecx.ecfg.features),
135+
config_tokens: false,
136+
lint_node_id: ecx.current_expansion.lint_node_id,
137+
};
138+
110139
if p.token == token::Eof {
111140
return Err(dcx.create_err(errors::AsmRequiresTemplate { span: sp }));
112141
}
113142

114-
let _attributes = AsmAttrList::parse(ecx, p)?;
143+
let _attributes = AsmAttrVec::parse(ecx, p)?;
115144
let first_template = p.parse_expr()?;
116145
let mut args = AsmArgs {
117146
templates: vec![first_template],
@@ -138,12 +167,16 @@ pub fn parse_asm_args<'a>(
138167
break;
139168
} // accept trailing commas
140169

141-
let _attributes = AsmAttrList::parse(ecx, p)?;
170+
let attributes = AsmAttrVec::parse(ecx, p)?;
171+
let is_configured_out = strip_unconfigured.configure(attributes).is_none();
142172

143173
// Parse clobber_abi
144174
if p.eat_keyword(exp!(ClobberAbi)) {
145-
parse_clobber_abi(p, &mut args)?;
146-
allow_templates = false;
175+
let new_abis = parse_clobber_abi(p)?;
176+
if !is_configured_out {
177+
args.clobber_abis.extend(new_abis);
178+
allow_templates = false;
179+
}
147180
continue;
148181
}
149182

@@ -466,7 +499,7 @@ fn parse_options<'a>(
466499
Ok(())
467500
}
468501

469-
fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a, ()> {
502+
fn parse_clobber_abi<'a>(p: &mut Parser<'a>) -> PResult<'a, Vec<(Symbol, Span)>> {
470503
let span_start = p.prev_token.span;
471504

472505
p.expect(exp!(OpenParen))?;
@@ -497,17 +530,9 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
497530
let full_span = span_start.to(p.prev_token.span);
498531

499532
match &new_abis[..] {
500-
// should have errored above during parsing
501-
[] => unreachable!(),
502-
[(abi, _span)] => args.clobber_abis.push((*abi, full_span)),
503-
abis => {
504-
for (abi, span) in abis {
505-
args.clobber_abis.push((*abi, *span));
506-
}
507-
}
533+
[(abi, _span)] => Ok(vec![(*abi, full_span)]),
534+
_ => Ok(new_abis),
508535
}
509-
510-
Ok(())
511536
}
512537

513538
fn parse_reg<'a>(

0 commit comments

Comments
 (0)