Sigil
Sigil copied to clipboard
Readonly prefix added to wrong instructions when doVerify is false
I was hitting an issue where dynamic methods created with doVerify
set to true work, while the same emitted instructions throw an InvalidProgramException
when doVerify
is set to false.
After checking the generated instructions I noticed that the readonly. prefixes are added to the wrong instructions!
Example:
emit.LoadLocal(myLocal);
emit.LoadConstant(0);
emit.LoadElement<DateTime?>();
ldloc.0
readonly.ldc.i4.0
ldelema System.Nullable`1[System.DateTime]
or
emit.LoadLocal(myLocal);
emit.BranchIfTrue(myLabel);
ldloc.3
readonly.brtrue.s _label8
or
emit.StoreElement<DateTime?>()
readonly.stelem System.Nullable`1[System.DateTime]
I will debug further and hopefully will be able to submit a pull request once I have some more time available.
It seems the InjectReadOnly
uses the TypeOnStack.UsedBy
field which is set by the VerifiableTracker
which is called by the RollingVerifier
. Either we need to disable the readonly prefix when doVerify
is false or make the RollingVerifierWithoutVerification
still keep track of stack usage so it can determine readonly prefixes. @kevin-montrose What are your thoughts on this? I would be happy to work either way.
It seems that this project is abandoned.
Anyway, I was hitting a problem with the readonly prefix too. I'm not sure is the same as yours, though. https://github.com/chaplin89/Sigil/commit/b00e1e19405b91deafd4ac413fc541251776789c