File tree 2 files changed +31
-2
lines changed
compiler/rustc_builtin_macros/src
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>(
140
140
return Err ( dcx. create_err ( errors:: AsmRequiresTemplate { span : sp } ) ) ;
141
141
}
142
142
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
+
145
160
let mut args = AsmArgs {
146
161
templates : vec ! [ first_template] ,
147
162
operands : vec ! [ ] ,
Original file line number Diff line number Diff line change @@ -83,18 +83,32 @@ fn template_allowed() {
83
83
}
84
84
}
85
85
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
+
86
97
pub fn main ( ) {
87
98
std:: cfg_match! {
88
99
reva => {
89
100
assert_eq!( const_operand( ) , 5 ) ;
90
101
assert_eq!( ignore_const_operand_cfg_attr( ) , 5 ) ;
91
102
assert_eq!( ignore_const_operand( ) , 5 ) ;
103
+ assert_eq!( first_template( ) , 5 ) ;
92
104
93
105
}
94
106
revb => {
95
107
assert_eq!( const_operand( ) , 10 ) ;
96
108
assert_eq!( ignore_const_operand_cfg_attr( ) , 10 ) ;
97
109
assert_eq!( ignore_const_operand( ) , 10 ) ;
110
+ assert_eq!( first_template( ) , 10 ) ;
111
+
98
112
}
99
113
}
100
114
options ( ) ;
You can’t perform that action at this time.
0 commit comments