-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add diagnostic for stack allocations of 1 GB or more #119798
Open
iSwapna
wants to merge
16
commits into
rust-lang:master
Choose a base branch
from
iSwapna:issue-83060-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−0
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0afd3e1
Add span_bug for locals larger than 1GB
iSwapna c9f5a23
Lint instead of warn
iSwapna f75765e
tidy
iSwapna 1bc466a
mingw fix
iSwapna 3f02139
tidy!
iSwapna 5f4d7ce
fix doctest
iSwapna 27df2a6
text for doc
iSwapna 6f8c577
Another attempt
iSwapna c4ddef9
Update compiler/rustc_codegen_ssa/src/mir/mod.rs
iSwapna 6b4a161
Update compiler/rustc_lint_defs/src/builtin.rs
iSwapna 171beb3
Update compiler/rustc_lint_defs/src/builtin.rs
iSwapna f36c7ee
Update compiler/rustc_codegen_ssa/src/mir/mod.rs
iSwapna a035e3a
Update compiler/rustc_lint_defs/src/builtin.rs
iSwapna ec78d7b
Update compiler/rustc_codegen_ssa/src/mir/mod.rs
iSwapna 2f56984
Remove original implementation
iSwapna ffda82c
Add "size" in error str
iSwapna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This test checks that allocating a stack size of 1GB or more results in a warning | ||
//@build-pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we should turn the warning and test with build-fail ( since CI core dumps) or the warning needs to be an error. The failure is in doc-tests. I believe it's the latter, but want to be sure. @estebank |
||
//@ only-64bit | ||
|
||
fn func() { | ||
const CAP: usize = std::u32::MAX as usize; | ||
let mut x: [u8; CAP>>1] = [0; CAP>>1]; | ||
//~^ warning: allocation of size: 1 GiB exceeds most system architecture limits | ||
//~| NOTE on by default | ||
x[2] = 123; | ||
println!("{}", x[2]); | ||
} | ||
|
||
fn main() { | ||
std::thread::Builder::new() | ||
.stack_size(3 * 1024 * 1024 * 1024) | ||
.spawn(func) | ||
.unwrap() | ||
.join() | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
warning: allocation of size: 1 GiB exceeds most system architecture limits | ||
--> $DIR/large-stack-size-issue-83060.rs:7:9 | ||
| | ||
LL | let mut x: [u8; CAP>>1] = [0; CAP>>1]; | ||
| ^^^^^ | ||
| | ||
= note: `#[warn(dangerous_stack_allocation)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add more context, like in the lint description, about some common platform limits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, it's limited in some ways by (possibly a bug in )LLVM and so most platforms are affected.