@@ -7,7 +7,10 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
77use rustc_expand:: base:: { self , * } ;
88use rustc_parse:: parser:: Parser ;
99use rustc_parse_format as parse;
10- use rustc_span:: symbol:: { kw, sym, Symbol } ;
10+ use rustc_span:: {
11+ symbol:: { kw, sym, Symbol } ,
12+ BytePos ,
13+ } ;
1114use rustc_span:: { InnerSpan , Span } ;
1215
1316struct AsmArgs {
@@ -465,6 +468,54 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
465468 for piece in unverified_pieces {
466469 match piece {
467470 parse:: Piece :: String ( s) => {
471+ if let Some ( idx) = s. find ( ".intel_syntax" ) {
472+ let mut end = idx + ".intel_syntax" . len ( ) ;
473+ if let Some ( prefix_idx) = s. split_at ( end) . 1 . find ( "noprefix" ) {
474+ // Should be a space and it should be immediately after
475+ if prefix_idx == 1 {
476+ end += " noprefix" . len ( ) ;
477+ }
478+ }
479+
480+ let syntax_span =
481+ template_span. from_inner ( InnerSpan :: new ( idx + 1 , end + 1 ) ) ;
482+ let mut err = ecx. struct_span_err ( syntax_span, "intel sytnax is the default syntax, and trying to use this directive may cause issues" ) ;
483+ err. span_suggestion (
484+ syntax_span,
485+ "Remove this assembler directive" ,
486+ s. replace ( & s[ idx..end] , "" ) . to_string ( ) ,
487+ Applicability :: MachineApplicable ,
488+ ) ;
489+ err. emit ( ) ;
490+ }
491+
492+ if let Some ( idx) = s. find ( ".att_syntax" ) {
493+ let mut end = idx + ".att_syntax" . len ( ) ;
494+ if let Some ( prefix_idx) = s. split_at ( end) . 1 . find ( "noprefix" ) {
495+ // Should be a space and it should be immediately after
496+ if prefix_idx == 1 {
497+ end += " noprefix" . len ( ) ;
498+ }
499+ }
500+
501+ let syntax_span =
502+ template_span. from_inner ( InnerSpan :: new ( idx + 1 , end + 1 ) ) ;
503+ let mut err = ecx. struct_span_err ( syntax_span, "using the .att_syntax directive may cause issues, use the att_syntax option instead" ) ;
504+ let asm_end = sp. hi ( ) - BytePos ( 2 ) ;
505+ let suggestions = vec ! [
506+ ( syntax_span, "" . to_string( ) ) ,
507+ (
508+ Span :: new( asm_end, asm_end, sp. ctxt( ) ) ,
509+ ", options(att_syntax)" . to_string( ) ,
510+ ) ,
511+ ] ;
512+ err. multipart_suggestion (
513+ "Remove the assembler directive and replace it with options(att_syntax)" ,
514+ suggestions,
515+ Applicability :: MachineApplicable ,
516+ ) ;
517+ err. emit ( ) ;
518+ }
468519 template. push ( ast:: InlineAsmTemplatePiece :: String ( s. to_string ( ) ) )
469520 }
470521 parse:: Piece :: NextArgument ( arg) => {
0 commit comments