[CIR][CodeGen] fixes access to globals with bitfields #1244
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.
This PR adds a bitcast when we rewrite globals type. Previously we just set a new type and it worked.
But recently I started to test ClangIR with CSmith in order to find some run time bugs and faced with the next problem.
The output for this program is ... 127 but not 254!
The reason is that first global var is created with the type of struct
S, thenget_memberoperation is generated with index1and then after, the type of the global is rewritten - I assume because of the anon struct created on the right side in the initialization.
But the
get_memberoperation still wants to access to the field at index1and get a wrong byte.If we change the
ytype tointwe will fail on the verification stage. But in the example above it's a run time error!This is why I suggest to add a bitcast once we have to rewrite the global type.