Skip to content

Commit

Permalink
pointers_in_nomem_asm_block: finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
Soveu committed Aug 24, 2024
1 parent 5f44d9e commit 2599e6c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5714,7 +5714,7 @@ Released 2018-09-13
[`path_ends_with_ext`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_ends_with_ext
[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch
[`permissions_set_readonly_false`]: https://rust-lang.github.io/rust-clippy/master/index.html#permissions_set_readonly_false
[`pointer_in_nomem_asm_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#pointer_in_nomem_asm_block
[`pointers_in_nomem_asm_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#pointers_in_nomem_asm_block
[`positional_named_format_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#positional_named_format_parameters
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma
[`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::pass_by_ref_or_value::TRIVIALLY_COPY_PASS_BY_REF_INFO,
crate::pattern_type_mismatch::PATTERN_TYPE_MISMATCH_INFO,
crate::permissions_set_readonly_false::PERMISSIONS_SET_READONLY_FALSE_INFO,
crate::pointer_in_nomem_asm_block::POINTER_IN_NOMEM_ASM_BLOCK_INFO,
crate::pointers_in_nomem_asm_block::POINTERS_IN_NOMEM_ASM_BLOCK_INFO,
crate::precedence::PRECEDENCE_INFO,
crate::ptr::CMP_NULL_INFO,
crate::ptr::INVALID_NULL_PTR_USAGE_INFO,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ mod partialeq_to_none;
mod pass_by_ref_or_value;
mod pattern_type_mismatch;
mod permissions_set_readonly_false;
mod pointer_in_nomem_asm_block;
mod pointers_in_nomem_asm_block;
mod precedence;
mod ptr;
mod ptr_offset_with_cast;
Expand Down Expand Up @@ -1177,7 +1177,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
store.register_late_pass(|_| Box::new(set_contains_or_insert::HashsetInsertAfterContains));
store.register_early_pass(|| Box::new(byte_char_slices::ByteCharSlice));
store.register_early_pass(|| Box::new(cfg_not_test::CfgNotTest));
store.register_late_pass(|_| Box::new(pointer_in_nomem_asm_block::PointerInNomemAsmBlock));
store.register_late_pass(|_| Box::new(pointers_in_nomem_asm_block::PointersInNomemAsmBlock));
// add lints here, do not remove this comment, it's used in `new_lint`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ declare_clippy_lint! {
/// }
/// ```
#[clippy::version = "1.81.0"]
pub POINTER_IN_NOMEM_ASM_BLOCK,
pub POINTERS_IN_NOMEM_ASM_BLOCK,
suspicious,
"pointer in nomem asm block"
"pointers in nomem asm block"
}

declare_lint_pass!(PointerInNomemAsmBlock => [POINTER_IN_NOMEM_ASM_BLOCK]);
declare_lint_pass!(PointersInNomemAsmBlock => [POINTERS_IN_NOMEM_ASM_BLOCK]);

impl<'tcx> LateLintPass<'tcx> for PointerInNomemAsmBlock {
impl<'tcx> LateLintPass<'tcx> for PointersInNomemAsmBlock {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
if let ExprKind::InlineAsm(asm) = &expr.kind {
check_asm(cx, asm);
Expand All @@ -59,9 +59,9 @@ fn check_asm(cx: &LateContext<'_>, asm: &InlineAsm<'_>) {

span_lint_and_then(
cx,
POINTER_IN_NOMEM_ASM_BLOCK,
POINTERS_IN_NOMEM_ASM_BLOCK,
spans,
"passing pointer to nomem asm block",
"passing pointers to nomem asm block",
additional_notes,
);
}
Expand All @@ -83,6 +83,6 @@ fn has_in_operand_pointer(cx: &LateContext<'_>, asm_op: &InlineAsmOperand<'_>) -
}

fn additional_notes(diag: &mut rustc_errors::Diag<'_, ()>) {
diag.note("`nomem` means that no memory write or read happens inside them asm! block");
diag.note("`nomem` means that no memory write or read happens inside the asm! block");
diag.note("if this is intentional and no pointers are read or written to, consider allowing the lint");
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ needs-asm-support
#![warn(clippy::pointer_in_nomem_asm_block)]
#![warn(clippy::pointers_in_nomem_asm_block)]
#![crate_type = "lib"]
#![no_std]

Expand All @@ -9,7 +9,7 @@ unsafe fn nomem_bad(p: &i32) {
asm!(
"asdf {p1}, {p2}, {p3}",
p1 = in(reg) p,
//~^ ERROR: passing pointer to nomem asm block
//~^ ERROR: passing pointers to nomem asm block
p2 = in(reg) p as *const _ as usize,
p3 = in(reg) p,
options(nomem, nostack, preserves_flags)
Expand All @@ -24,10 +24,10 @@ unsafe fn nomem_good(p: &i32) {

unsafe fn nomem_bad2(p: &mut i32) {
asm!("asdf {p}", p = in(reg) p, options(nomem, nostack, preserves_flags));
//~^ ERROR: passing pointer to nomem asm block
//~^ ERROR: passing pointers to nomem asm block
}

unsafe fn nomem_fn(p: extern "C" fn()) {
asm!("call {p}", p = in(reg) p, options(nomem));
//~^ ERROR: passing pointer to nomem asm block
//~^ ERROR: passing pointers to nomem asm block
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
error: passing pointer to nomem asm block
--> tests/ui/pointer_in_nomem_asm_block.rs:11:9
error: passing pointers to nomem asm block
--> tests/ui/pointers_in_nomem_asm_block.rs:11:9
|
LL | p1 = in(reg) p,
| ^^^^^^^^^^^^^^
...
LL | p3 = in(reg) p,
| ^^^^^^^^^^^^^^
|
= note: `nomem` means that no memory write or read happens inside them asm! block
= note: `nomem` means that no memory write or read happens inside the asm! block
= note: if this is intentional and no pointers are read or written to, consider allowing the lint
= note: `-D clippy::pointer-in-nomem-asm-block` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::pointer_in_nomem_asm_block)]`
= note: `-D clippy::pointers-in-nomem-asm-block` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::pointers_in_nomem_asm_block)]`

error: passing pointer to nomem asm block
--> tests/ui/pointer_in_nomem_asm_block.rs:26:22
error: passing pointers to nomem asm block
--> tests/ui/pointers_in_nomem_asm_block.rs:26:22
|
LL | asm!("asdf {p}", p = in(reg) p, options(nomem, nostack, preserves_flags));
| ^^^^^^^^^^^^^
|
= note: `nomem` means that no memory write or read happens inside them asm! block
= note: `nomem` means that no memory write or read happens inside the asm! block
= note: if this is intentional and no pointers are read or written to, consider allowing the lint

error: passing pointer to nomem asm block
--> tests/ui/pointer_in_nomem_asm_block.rs:31:22
error: passing pointers to nomem asm block
--> tests/ui/pointers_in_nomem_asm_block.rs:31:22
|
LL | asm!("call {p}", p = in(reg) p, options(nomem));
| ^^^^^^^^^^^^^
|
= note: `nomem` means that no memory write or read happens inside them asm! block
= note: `nomem` means that no memory write or read happens inside the asm! block
= note: if this is intentional and no pointers are read or written to, consider allowing the lint

error: aborting due to 3 previous errors
Expand Down

0 comments on commit 2599e6c

Please sign in to comment.