Capture stackalloc size expression only if needed#24183
Capture stackalloc size expression only if needed#24183VSadov merged 4 commits intodotnet:masterfrom
Conversation
|
@dotnet/roslyn-compiler - please review |
OmarTawfik
left a comment
There was a problem hiding this comment.
LGTM. Can you please add a test that makes sure we optimize more complex constants as well? stackalloc int[5+6]
Thanks @alrz!
|
Also, what happens if it does not fit? Like I would expect it to still emit a checked |
Shouldn't that produce a warning then (for constants)? or an error since it always throw (similar to #8456). |
|
@alrz - giving a warning should be a separate issue/workitem A general approach is that compiler must handle corner cases predictably even if such corner cases are unlikely. This change keeps such behavior and with better IL, so everyone is 👍 Some corner cases clearly indicate that the code contains an error. In such cases a warning may be considered. That is not as simple. The questions that must be asked are:
IMO the chance of breaking existing code would be low, but the benefits are also not extremely high. It seems worth logging an issue about the warning, but whether it will be accepted/rejected - hard to tell. |
|
Filed dotnet/roslyn-analyzers#6232 for a warning candidate in warning waves |
|
@dotnet-bot test windows_release_unit64_prtest please |
|
runs just keep timing out for no reasons (other runs too) will reopen |
|
@dotnet-bot test windows_release_unit64_prtest please |
|
@dotnet-bot test windows_debug_unit64_prtest please |
|
@dotnet-bot test windows_release_unit64_prtest please |
|
@dotnet-bot test windows_debug_unit64_prtest please |
|
there are actually real failures. tests are failing with |
|
@dotnet-bot test this please |
|
I do not see anything in this change that could cause SO. Perhaps it was a problem in the branch.. |
|
this is driving me nuts, anything I can do locally to make sure things are ok? |
|
@alrz are the tests passing locally? |
|
On my machine just the ones that require ilasm tool. No stackoverflow. |
|
@alrz To repro CI-only problems, we have commands that are the same that CI uses. Look at |
|
OK, all green except for tests fixed in #24323. local: CI (excluding timeouts): The VB failure doesn't appear in CI results though so I'm not sure if that's the cause. probably worth to wait for #24323 to reach master first. |
|
I wonder if all required fixes have reached the branch |
| { | ||
| M(); | ||
| } | ||
| catch (OverflowException) |
There was a problem hiding this comment.
I think you might not be able to catch this when it actually runs.
There was a problem hiding this comment.
Ah, no it is a regular overflow, not a StackOverflow.
There was a problem hiding this comment.
Actually this is the problem. On 64bit this is not an overflow since the native int can take this value, but then it becomes SO when we localloc.
I guess on 64bit we should not run the compiled code, only validate the IL.
There was a problem hiding this comment.
How can I repro locally? Does ReleaseExe.WithPlatform(Platform.X86) help here?
There was a problem hiding this comment.
or should I skip it for now?
There was a problem hiding this comment.
both build and test utilities in the repo root take -test64 switch.
I think build -test64 might do it.
There was a problem hiding this comment.
nope :-), just tried build -test64 and it only did a build. Need to run test -test64 after that.
Normally our test failures are not platform specific, so we just rely on CI
There was a problem hiding this comment.
I would just make a fix and push the change to the branch.
It should really be something like:
var expectedIL = "....";
if (IntPtr.Size == 4)
{
CompileAndVerify(comp, expectedOutput: "10", verify: Verification.Fails)
. . . Verify (expectedIL):...
}
else
{
// on 64bit the native int does not overflow, so we get StackOverflow instead
// therefore we will just check the IL
CompileAndVerify(comp, verify: Verification.Fails, options:TestOptions.ReleaseDll)
. . . Verify (expectedIL):...
}|
Microsoft.CodeAnalysis.Editor.UnitTests.Structure.StructureTaggerTests.OutliningTaggerTooltipText [FAIL] seems like a flaky test https://ci.dot.net/job/dotnet_roslyn/job/master/job/windows_release_unit64_prtest/11891/ |
|
@dotnet-bot test windows_release_unit64_prtest please |
|
Thanks!! |

Fixes #24174