@@ -7,11 +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:: {
11- symbol:: { kw, sym, Symbol } ,
12- BytePos ,
13- } ;
10+ use rustc_session:: lint;
11+ use rustc_span:: symbol:: { kw, sym, Symbol } ;
1412use rustc_span:: { InnerSpan , Span } ;
13+ use rustc_target:: asm:: InlineAsmArch ;
1514
1615struct AsmArgs {
1716 templates : Vec < P < ast:: Expr > > ,
@@ -402,8 +401,6 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
402401 let mut line_spans = Vec :: with_capacity ( args. templates . len ( ) ) ;
403402 let mut curarg = 0 ;
404403
405- let default_dialect = ecx. sess . inline_asm_dialect ( ) ;
406-
407404 for template_expr in args. templates . into_iter ( ) {
408405 if !template. is_empty ( ) {
409406 template. push ( ast:: InlineAsmTemplatePiece :: String ( "\n " . to_string ( ) ) ) ;
@@ -430,56 +427,36 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
430427 let template_str = & template_str. as_str ( ) ;
431428 let template_snippet = ecx. source_map ( ) . span_to_snippet ( template_sp) . ok ( ) ;
432429
433- if let Some ( snippet) = & template_snippet {
434- let snippet = snippet. trim_matches ( '"' ) ;
435- match default_dialect {
436- ast:: LlvmAsmDialect :: Intel => {
437- if let Some ( span) = check_syntax_directive ( snippet, ".intel_syntax" ) {
438- let span = template_span. from_inner ( span) ;
439- let mut err = ecx. struct_span_err ( span, "intel syntax is the default syntax on this target, and trying to use this directive may cause issues" ) ;
440- err. span_suggestion (
441- span,
442- "remove this assembler directive" ,
443- "" . to_string ( ) ,
444- Applicability :: MachineApplicable ,
445- ) ;
446- err. emit ( ) ;
447- }
448-
449- if let Some ( span) = check_syntax_directive ( snippet, ".att_syntax" ) {
450- let span = template_span. from_inner ( span) ;
451- let mut err = ecx. struct_span_err ( span, "using the .att_syntax directive may cause issues, use the att_syntax option instead" ) ;
452- let asm_end = sp. hi ( ) - BytePos ( 2 ) ;
453- let suggestions = vec ! [
454- ( span, "" . to_string( ) ) ,
455- (
456- Span :: new( asm_end, asm_end, sp. ctxt( ) ) ,
457- ", options(att_syntax)" . to_string( ) ,
458- ) ,
459- ] ;
460- err. multipart_suggestion (
461- "remove the assembler directive and replace it with options(att_syntax)" ,
462- suggestions,
463- Applicability :: MachineApplicable ,
464- ) ;
465- err. emit ( ) ;
430+ if let Some ( InlineAsmArch :: X86 | InlineAsmArch :: X86_64 ) = ecx. sess . asm_arch {
431+ let find_span = |needle : & str | -> Span {
432+ if let Some ( snippet) = & template_snippet {
433+ if let Some ( pos) = snippet. find ( needle) {
434+ let end = pos
435+ + & snippet[ pos..]
436+ . find ( |c| matches ! ( c, '\n' | ';' | '\\' | '"' ) )
437+ . unwrap_or ( snippet[ pos..] . len ( ) - 1 ) ;
438+ let inner = InnerSpan :: new ( pos, end) ;
439+ return template_sp. from_inner ( inner) ;
466440 }
467441 }
468- ast:: LlvmAsmDialect :: Att => {
469- if let Some ( span) = check_syntax_directive ( snippet, ".att_syntax" ) {
470- let span = template_span. from_inner ( span) ;
471- let mut err = ecx. struct_span_err ( span, "att syntax is the default syntax on this target, and trying to use this directive may cause issues" ) ;
472- err. span_suggestion (
473- span,
474- "remove this assembler directive" ,
475- "" . to_string ( ) ,
476- Applicability :: MachineApplicable ,
477- ) ;
478- err. emit ( ) ;
479- }
442+ template_sp
443+ } ;
480444
481- // Use of .intel_syntax is ignored
482- }
445+ if template_str. contains ( ".intel_syntax" ) {
446+ ecx. parse_sess ( ) . buffer_lint (
447+ lint:: builtin:: BAD_ASM_STYLE ,
448+ find_span ( ".intel_syntax" ) ,
449+ ecx. resolver . lint_node_id ( ecx. current_expansion . id ) ,
450+ "avoid using `.intel_syntax`, Intel syntax is the default" ,
451+ ) ;
452+ }
453+ if template_str. contains ( ".att_syntax" ) {
454+ ecx. parse_sess ( ) . buffer_lint (
455+ lint:: builtin:: BAD_ASM_STYLE ,
456+ find_span ( ".att_syntax" ) ,
457+ ecx. resolver . lint_node_id ( ecx. current_expansion . id ) ,
458+ "avoid using `.att_syntax`, prefer using `options(att_syntax)` instead" ,
459+ ) ;
483460 }
484461 }
485462
@@ -690,15 +667,3 @@ pub fn expand_asm<'cx>(
690667 }
691668 }
692669}
693-
694- fn check_syntax_directive < S : AsRef < str > > ( piece : S , syntax : & str ) -> Option < InnerSpan > {
695- let piece = piece. as_ref ( ) ;
696- if let Some ( idx) = piece. find ( syntax) {
697- let end =
698- idx + & piece[ idx..] . find ( |c| matches ! ( c, '\n' | ';' ) ) . unwrap_or ( piece[ idx..] . len ( ) ) ;
699- // Offset by one because these represent the span with the " removed
700- Some ( InnerSpan :: new ( idx + 1 , end + 1 ) )
701- } else {
702- None
703- }
704- }
0 commit comments