3 use clippy_utils::diagnostics::span_lint_and_help;
4 use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions};
5 use rustc_lint::{EarlyContext, EarlyLintPass, Lint};
6 use rustc_session::{declare_lint_pass, declare_tool_lint};
8 #[derive(Clone, Copy, PartialEq, Eq)]
14 impl fmt::Display for AsmStyle {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 AsmStyle::Intel => f.write_str("Intel"),
18 AsmStyle::Att => f.write_str("AT&T"),
23 impl std::ops::Not for AsmStyle {
24 type Output = AsmStyle;
26 fn not(self) -> AsmStyle {
28 AsmStyle::Intel => AsmStyle::Att,
29 AsmStyle::Att => AsmStyle::Intel,
34 fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr, check_for: AsmStyle) {
35 if let ExprKind::InlineAsm(ref inline_asm) = expr.kind {
36 let style = if inline_asm.options.contains(InlineAsmOptions::ATT_SYNTAX) {
42 if style == check_for {
47 &format!("{} x86 assembly syntax used", style),
49 &format!("use {} x86 assembly syntax", !style),
55 declare_clippy_lint! {
57 /// Checks for usage of Intel x86 assembly syntax.
59 /// ### Why is this bad?
60 /// The lint has been enabled to indicate a preference
61 /// for AT&T x86 assembly syntax.
66 /// # #![feature(asm)]
67 /// # unsafe { let ptr = "".as_ptr();
68 /// # use std::arch::asm;
69 /// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr);
74 /// # #![feature(asm)]
75 /// # unsafe { let ptr = "".as_ptr();
76 /// # use std::arch::asm;
77 /// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax));
80 #[clippy::version = "1.49.0"]
81 pub INLINE_ASM_X86_INTEL_SYNTAX,
83 "prefer AT&T x86 assembly syntax"
86 declare_lint_pass!(InlineAsmX86IntelSyntax => [INLINE_ASM_X86_INTEL_SYNTAX]);
88 impl EarlyLintPass for InlineAsmX86IntelSyntax {
89 fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
90 check_expr_asm_syntax(Self::get_lints()[0], cx, expr, AsmStyle::Intel);
94 declare_clippy_lint! {
96 /// Checks for usage of AT&T x86 assembly syntax.
98 /// ### Why is this bad?
99 /// The lint has been enabled to indicate a preference
100 /// for Intel x86 assembly syntax.
105 /// # #![feature(asm)]
106 /// # unsafe { let ptr = "".as_ptr();
107 /// # use std::arch::asm;
108 /// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax));
113 /// # #![feature(asm)]
114 /// # unsafe { let ptr = "".as_ptr();
115 /// # use std::arch::asm;
116 /// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr);
119 #[clippy::version = "1.49.0"]
120 pub INLINE_ASM_X86_ATT_SYNTAX,
122 "prefer Intel x86 assembly syntax"
125 declare_lint_pass!(InlineAsmX86AttSyntax => [INLINE_ASM_X86_ATT_SYNTAX]);
127 impl EarlyLintPass for InlineAsmX86AttSyntax {
128 fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
129 check_expr_asm_syntax(Self::get_lints()[0], cx, expr, AsmStyle::Att);