@@ -171,9 +171,12 @@ pub(super) fn handle_needs(
171171 } ,
172172 ] ;
173173
174- let ( name, comment) = match ln. split_once ( [ ':' , ' ' ] ) {
175- Some ( ( name, comment) ) => ( name, Some ( comment) ) ,
176- None => ( ln, None ) ,
174+ // Because `needs-target-has-atomic` accepts comma separated arguments after a colon to specify
175+ // data sizes, we check whether comment starts with colon.
176+ let ( name, comment, comment_starts_with_colon) = if let Some ( index) = ln. find ( [ ':' , ' ' ] ) {
177+ ( & ln[ ..index] , Some ( & ln[ index + 1 ..] ) , ln. as_bytes ( ) [ index] == b':' )
178+ } else {
179+ ( ln, None , false )
177180 } ;
178181
179182 if !name. starts_with ( "needs-" ) {
@@ -185,6 +188,39 @@ pub(super) fn handle_needs(
185188 return IgnoreDecision :: Continue ;
186189 }
187190
191+ // Check here because `needs-target-has-atomic` requires parsing comments.
192+ if name == "needs-target-has-atomic" {
193+ // `needs-target-has-atomic` requires comma-separated data sizes.
194+ if !comment_starts_with_colon || comment. is_none ( ) {
195+ return IgnoreDecision :: Error {
196+ message : "`needs-target-has-atomic` requires data sizes for atomic operations"
197+ . into ( ) ,
198+ } ;
199+ }
200+ let comment = comment. unwrap ( ) ;
201+
202+ // Parse the comment to specify data sizes.
203+ for size in comment. split ( ',' ) . map ( |size| size. trim ( ) ) {
204+ if ![ "ptr" , "128" , "64" , "32" , "16" , "8" ] . contains ( & size) {
205+ return IgnoreDecision :: Error {
206+ message : "expected values for `needs-target-has-atomic` are: `128`, `16`, \
207+ `32`, `64`, `8`, and `ptr`"
208+ . into ( ) ,
209+ } ;
210+ }
211+ if !config. has_atomic ( size) {
212+ return IgnoreDecision :: Ignore {
213+ reason : if size == "ptr" {
214+ "ignored on targets without ptr-size atomic operations" . into ( )
215+ } else {
216+ format ! ( "ignored on targets without {size}-bit atomic operations" )
217+ } ,
218+ } ;
219+ }
220+ }
221+ return IgnoreDecision :: Continue ;
222+ }
223+
188224 let mut found_valid = false ;
189225 for need in needs {
190226 if need. name == name {
0 commit comments