Issue 469: Semantically invalid IR statements due to bad Subregister Substitution #470
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It was observed that the Subregister Substitution may produce expressions that are semantically malformed. This happens when assignments are made to the lower bytes of a full register and this subregister has no special name.
It was noticed since evaluating a SUBPIECE expression of size zero over the PI abstract domain lead to panics (#469).
Note: The relevant patch is in the first commit. I snuck in some more debugging patches here ... just don't mind them :)
Fix
The underlying issue is that when assigning to the lower bytes of registers the miss-translated pcode does not use special subregister names (or there simple are no such names), but rather used the full register with a smaller size. In those cases the old code would end up thinking that the subregister had the same size as the full register and the SUBPIECE expression over the old register value that is needed to build a sill-size assignment would end up being of size zero.
This is corrected by setting the register size of the full register to the size of the variable being assigned. If the register size is already correct, this should be a no-op. The fix is in the first commit.
Examples
Here are some examples of previously malformed expressions that are corrected by this patch:
lxvd2x
on ppc64lebecomes
cvt.s.L
on mips64elbecomes
sel
on armbecomes
Numbers
Here are the numbers of corrected lines for each program in our minimal test suite. All changes were manually verified to be correct.