-
Notifications
You must be signed in to change notification settings - Fork 167
Fix missing type casts when using bitfields with remapped types (and some other cases) #626
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
Fix missing type casts when using bitfields with remapped types (and some other cases) #626
Conversation
This case doesn't compile nor does it match the comments in VisitBitfieldDecl. However this means the test case now fails.
Not completely verified yet and the conditions are named a bit inconsistently.
Will add a few variants for Windows to ensure that enum signedness is handled properly.
Ready for review. Since I changed the indentation, it's easier to see the changes if you ignore whitespace in your diff viewer. |
var needsParenFirst = !isSmallType && isUnsignedToSigned; | ||
var needsParenSecond = !needsParenFirst || isRemappedToSelf; | ||
// Check if field/backing types match | ||
var isTypeMismatch = type != typeBacking; |
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.
Why the comparison against typeBacking
rather than buildinTypeBacking
? Won't that be meaningful for certain typedefs or enums?
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'm going to take a look at this in more detail. I don't remember deciding against builtinTypeBacking
, so it's likely something I missed when I was writing the condition. Changing typeBacking
to builtinTypeBacking
also doesn't affect the tests on either Linux nor Windows, so this probably is an untested case.
I'll draft the PR for now and undraft when I have an answer.
sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs
Outdated
Show resolved
Hide resolved
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.
Overall LGTM. Just a minor nit and a question that I don't remember the answer to off the top of my head
Co-authored-by: Tanner Gooding <[email protected]>
This case is when typeBacking is not the same as builtinTypeBacking
…edefs and similar cases
Good catch. Using I've added a test case and changed the code to use |
This PR fixes #618 and some other issues that I identified as I was looking to understand the code.
#618 explains the two main cases fixed (missing type casts when remapping and incorrect sbyte case).
I also changed the
uint/int
case, mainly as an implementation detail. It doesn't matter if the cast happens before or after the left shift. It just has to happen before the right shift. This keeps the behavior consistent across cases.Edit: I only changed the comment. The previous behavior already matches the current and the comment.
You'll notice the code has changed a significant amount. This is because I rewrote most of the conditions and grouped the code together to make it a bit more readable. Because it was hard to track scopes, such as where each matching opening/closing parentheses were located, I added variables identifying the purpose and conditions for each scope.
Remaining tasks
char
is abyte
orsbyte
on Linux ARM.