-
Notifications
You must be signed in to change notification settings - Fork 2k
Clippy wrongly reports clippy::large_stack_arrays on static struct #9460
Copy link
Copy link
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
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
- Clone this repository:
git clone https://github.com/AFLplusplus/LibAFL.git - Checkout to:
git checkout b86314282907aa77d727e3bb9a1b03b75ad441c0 - 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Type
Fields
Give feedbackNo fields configured for issues without a type.