Sigil icon indicating copy to clipboard operation
Sigil copied to clipboard

Readonly prefix added to wrong instructions when doVerify is false

Open Wazner opened this issue 7 years ago • 2 comments

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.

Wazner avatar May 03 '17 09:05 Wazner

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.

Wazner avatar May 04 '17 20:05 Wazner

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

chaplin89 avatar Jun 30 '17 13:06 chaplin89