File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
compiler/rustc_builtin_macros/src Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -140,8 +140,23 @@ pub fn parse_asm_args<'a>(
140140 return Err ( dcx. create_err ( errors:: AsmRequiresTemplate { span : sp } ) ) ;
141141 }
142142
143- let _attributes = AsmAttrVec :: parse ( ecx, p) ?;
144- let first_template = p. parse_expr ( ) ?;
143+ let first_template = loop {
144+ let attributes = AsmAttrVec :: parse ( ecx, p) ?;
145+ let is_configured_out =
146+ ecx. ecfg . features . asm_cfg ( ) && strip_unconfigured. configure ( attributes) . is_none ( ) ;
147+
148+ let template = p. parse_expr ( ) ?;
149+
150+ if !is_configured_out {
151+ break template;
152+ }
153+
154+ if !p. eat ( exp ! ( Comma ) ) {
155+ // After a template string, we always expect *only* a comma...
156+ return Err ( dcx. create_err ( errors:: AsmExpectedComma { span : p. token . span } ) ) ;
157+ }
158+ } ;
159+
145160 let mut args = AsmArgs {
146161 templates : vec ! [ first_template] ,
147162 operands : vec ! [ ] ,
Original file line number Diff line number Diff line change @@ -83,18 +83,32 @@ fn template_allowed() {
8383 }
8484}
8585
86+ #[ unsafe( naked) ]
87+ extern "C" fn first_template ( ) -> u64 {
88+ naked_asm ! (
89+ #[ cfg( reva) ]
90+ "mov rax, 5" ,
91+ #[ cfg( revb) ]
92+ "mov rax, 10" ,
93+ "ret" ,
94+ )
95+ }
96+
8697pub fn main ( ) {
8798 std:: cfg_match! {
8899 reva => {
89100 assert_eq!( const_operand( ) , 5 ) ;
90101 assert_eq!( ignore_const_operand_cfg_attr( ) , 5 ) ;
91102 assert_eq!( ignore_const_operand( ) , 5 ) ;
103+ assert_eq!( first_template( ) , 5 ) ;
92104
93105 }
94106 revb => {
95107 assert_eq!( const_operand( ) , 10 ) ;
96108 assert_eq!( ignore_const_operand_cfg_attr( ) , 10 ) ;
97109 assert_eq!( ignore_const_operand( ) , 10 ) ;
110+ assert_eq!( first_template( ) , 10 ) ;
111+
98112 }
99113 }
100114 options ( ) ;
You can’t perform that action at this time.
0 commit comments