Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy wrongly reports clippy::large_stack_arrays on static struct #9460

Closed
tokatoka opened this issue Sep 10, 2022 · 0 comments
Closed

Clippy wrongly reports clippy::large_stack_arrays on static struct #9460

tokatoka opened this issue Sep 10, 2022 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@tokatoka
Copy link

Summary

Hello, I have a problem with clippy::large_stack_arrays lint.

Clippy reports clippy::large_stack_arrays on a public static mut struct defined like

/// The global `CmpLog` map for the current `LibAFL` run.
#[no_mangle]
pub static mut libafl_cmplog_map: CmpLogMap = CmpLogMap {
    headers: [CmpLogHeader {
        hits: 0,
        shape: 0,
        kind: 0,
    }; CMPLOG_MAP_W],
    vals: CmpLogVals {
        operands: [[CmpLogInstruction(0, 0); CMPLOG_MAP_H]; CMPLOG_MAP_W],
    },
};

and here's the short output from clippy

error: allocating a local array larger than 512000 bytes
   --> libafl_targets/src/cmplog.rs:165:19
    |
165 |         operands: [[CmpLogInstruction(0, 0); CMPLOG_MAP_H]; CMPLOG_MAP_W],

clippy suggests to put this on heap, but it is not possible because it's a static struct.

Thank you!

Lint Name

clippy::large_stack_arrays

Reproducer

  1. Clone this repository: git clone https://github.com/AFLplusplus/LibAFL.git
  2. Checkout to: git checkout b86314282907aa77d727e3bb9a1b03b75ad441c0
  3. Run clippy: cargo +nightly clippy --all --all-features

Clippy reports

error: allocating a local array larger than 512000 bytes
   --> libafl_targets/src/cmplog.rs:165:19
    |
165 |         operands: [[CmpLogInstruction(0, 0); CMPLOG_MAP_H]; CMPLOG_MAP_W],
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: the lint level is defined here
   --> libafl_targets/src/lib.rs:7:9
    |
7   | #![deny(clippy::pedantic)]
    |         ^^^^^^^^^^^^^^^^
    = note: `#[deny(clippy::large_stack_arrays)]` implied by `#[deny(clippy::pedantic)]`
    = help: consider allocating on the heap with `vec![[CmpLogInstruction(0, 0); CMPLOG_MAP_H]; CMPLOG_MAP_W].into_boxed_slice()`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays

But, in our code, this is a pub static mutstruct (https://github.com/AFLplusplus/LibAFL/blob/main/libafl_targets/src/cmplog.rs#L158)

/// The global `CmpLog` map for the current `LibAFL` run.
#[no_mangle]
pub static mut libafl_cmplog_map: CmpLogMap = CmpLogMap {
    headers: [CmpLogHeader {
        hits: 0,
        shape: 0,
        kind: 0,
    }; CMPLOG_MAP_W],
    vals: CmpLogVals {
        operands: [[CmpLogInstruction(0, 0); CMPLOG_MAP_H]; CMPLOG_MAP_W],
    },
};

and it is not possible to allocate this on heap

Version

rustc 1.65.0-nightly (1d37ed661 2022-09-09)
binary: rustc
commit-hash: 1d37ed661a6922e7a167609b8cd7eb31e972b19b
commit-date: 2022-09-09
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 15.0.0

Additional Labels

No response

@tokatoka tokatoka added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Sep 10, 2022
bors added a commit that referenced this issue Sep 12, 2022
Don't lint `large_stack_array` inside static items

We now check if the linted `Expr` is inside an `ItemKind::Static`, which can't take the suggested `Box<[...]`. I _think_ this is the correct fix for #9460

I removed `if_chain` while I was at it.

changelog: Don't lint `large_stack_array` inside static items
@bors bors closed this as completed in 6f41a44 Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant