-
Notifications
You must be signed in to change notification settings - Fork 4.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
JIT: fix flags lossage in morph comma/ind interchange #68082
Conversation
Morph may transform `IND(COMMA(..., z))` into `COMMA(... , IND(z))` and when doing so it was not computing appropriately conservative flags for the new `IND`. In particular it was losing `GTF_GLOB_REF`. This allowed subsequent opts to reorder operands in an unsafe manner. Fixes dotnet#68049.
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsMorph may transform This allowed subsequent opts to reorder operands in an unsafe manner. Fixes #68049.
|
@jakobbotsch PTAL Leads to a few diffs in SPMI. |
src/coreclr/jit/morph.cpp
Outdated
op1->gtFlags |= (addr->gtFlags & GTF_ALL_EFFECT); | ||
op1->gtFlags |= treeFlags & (GTF_GLOB_REF | GTF_IND_FLAGS); |
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.
Is the GTF_IND_FLAGS
portion needed? Seems like it'd be set by the |= treeFlags & ~GTF_ALL_EFFECT;
above.
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.
Is the
GTF_IND_FLAGS
portion needed?
No, it's not needed.
CollectibleALC alc = new CollectibleALC(); | ||
System.Reflection.Assembly asm = alc.LoadFromAssemblyPath(System.Reflection.Assembly.GetExecutingAssembly().Location); | ||
System.Reflection.MethodInfo mi = asm.GetType(typeof(Runtime_68049_1).FullName).GetMethod(nameof(MainInner)); | ||
System.Type runtimeTy = asm.GetType(typeof(Runtime).FullName); | ||
mi.Invoke(null, new object[]{System.Activator.CreateInstance(runtimeTy)}); | ||
return (int) s_result; |
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.
I would remove this test. It requires loading the assembly from file which means it has to be disabled in various configurations in issues.targets. Also I think the s_result
is being set in the other instance of the type (the one loaded in the other ALC), not in this one, so it will always fail. Probably easier to just rely on the other test.
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.
Ok.
Evidently we can't just copy the flags over:
|
The extra flag is the
and
so after the IND/COMMA interchange we end up with a non-faulting excepting indir off off zero which is also unreachable.
This eventually makes the flag checker uneasy. This may be why the old code cleared We perhaps should check for comma throw here and just nuke the indir entirely. |
It already looks strange to me here. How can an indirection have both |
That's okay -- an array access is guaranteed to either throw an exception or give you and address you can safely dereference. Recall (What I wrote above may be a little off, I'm not yet sure how we get into the IND/COMMA interchange, since it looks like the IND is already under the COMMA. Need to do a bit more debugging). Update: there's an intermediate tree state that isn't shown in the dumps. It would eappear there's some other part of morph that can transform
|
Ah ok, but they are mutually exclusive if the child of the indirection does not have |
I need to debug through this part too as I don't quite see how it ends up complaining about what it complains about. [Edit: you were right about this case, a non-faulting indir should not have |
Debugged and the actual checker flag complaint is indeed about |
Morph may transform
IND(COMMA(..., z))
intoCOMMA(... , IND(z))
and when doing so it was not computing appropriately conservative
flags for the new
IND
. In particular it was losingGTF_GLOB_REF
.This allowed subsequent opts to reorder operands in an unsafe manner.
Fixes #68049.