-
Notifications
You must be signed in to change notification settings - Fork 463
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
Warn if stackalloc would throw with a constant size at runtime #6232
Comments
Tagging @VSadov to triage |
What is the maximum stack size the compiler is supposed to assume? Since the E.g. And since this is just a warning, I assume that some future version of .Net allowed stacks larger than 2 GB is not an issue? |
The idea is that while we do not know how platform/OS handles the stack, we know that ‘localloc’ takes an int. So if the size does not fit in an int, it will certanly throw. In reality the problems will start much earlier. Default stack limits are generally 1-4 mBs. That makes it questionable that we would warn on outlandish sizes when anything more that couple kBs is dangerous. |
As far as I can tell, that's not true. The spec says that |
Default stack size comes from the Perhaps the warning could be tied to the default limit (1MB) and a compiler switch that allows the default to be changed could also exist (seems like a more generally useful thing with stack allocations being more readily possible in safe code anyways). However, the warning should probably emit at percentage (maybe 50-75%) of the actual max stack, rather than at max stack itself. Even the main method has some stack taken away by locals/etc (and other method calls temporarily shrink the available space as well), so |
e.g.
Span<int> s = stackalloc int[int.MaxValue]
Similar to dotnet/roslyn#8456
Relates to warning waves
The text was updated successfully, but these errors were encountered: