@@ -7,7 +7,10 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
7
7
use rustc_expand:: base:: { self , * } ;
8
8
use rustc_parse:: parser:: Parser ;
9
9
use 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
+ } ;
11
14
use rustc_span:: { InnerSpan , Span } ;
12
15
13
16
struct AsmArgs {
@@ -465,6 +468,54 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
465
468
for piece in unverified_pieces {
466
469
match piece {
467
470
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
+ }
468
519
template. push ( ast:: InlineAsmTemplatePiece :: String ( s. to_string ( ) ) )
469
520
}
470
521
parse:: Piece :: NextArgument ( arg) => {
0 commit comments