-
Notifications
You must be signed in to change notification settings - Fork 519
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
Incorrect implicit underlying type for enums #1883
Comments
Took a bit but was able to fish out the logic from Clang: https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDecl.cpp#L17248 Specifically this part seems relevant:
Maybe we need to implement this on our side due to this? Though presumably there is some other code in Clang that detects the actual size through the underlying enum entries values, but I've not been able to find that yet, maybe it's only done in code generation. |
Alright, so this seems to stem from a MSVC bug https://developercommunity.visualstudio.com/t/underlying-type-of-an-unscoped-enum/524018. The line you linked allowed me to fix this on the consumer side by just specifying a non-MSVC triple in After some digging I found the method responsible: The question is whether there is some sort of hook in clang that would allow us to maybe reset the type before the items are processed here, or if there's some way to reset and re-determine the type and regenerate the values. The alternative would be effectively having to redo exactly what that method does, reparsing all values and determining the correct type from them.. Another question is also whether this may be somewhat desired behavior (at least as an option)? Considering that a DLL compiled under MSVC without the necessary flag would produce the same, incorrect values and incorrect size. P.S.: Regarding the solution using the |
Good find on the actual logic in Clang and The documentation page mentions So is this just an issue maybe of detecting the actual VS version on the system and potentially passing that to Clang so it assumes the new behaviour?
This should be possible with calling |
Well, Clang doesn't actually seem to take into account the updated logic in >= 17.4. Maybe the first step would be to contribute or request a fix for this from their side. And in the meanwhile, workaround this from our side in C# when targetting the recent versions of VS. |
The erroneous behavior is still the standard in the latest preleases for VS as far as I can see. 17.4 only introduced the compiler flag to fix it and the patch notes explicitly mention it being off by default. The I'm currently looking into getting support for Fortunately my use case (currently working on a wrapper for assimp) does not require this, as no value is large enough to cause information to be lost, thus it's sufficient to simply manually set the enum types correctly as a workaround. Edit: Upstream issue has been established: llvm/llvm-project#120759 |
Brief Description
When a header includes an enum with an implicit value representation such as the following:
The
BuiltinType
of the generatedEnumeration
declaration is erroneouslyint
and the correpsonding item is incorrect (it's(ulong)(int)0xffffffff
).After some digging, it appears the code responsible for setting the type is:
CppSharp/src/CppParser/Parser.cpp
Lines 2990 to 2994 in 166e45e
int
is returned bygetIntegerType
and the items are being incorrectly represented as above.It appears
EnumDecl
is a type directly provided by clang, so this appears to be a bug in clang?Explicitly specifying the value representation makes everything work as expected.
This is especially odd considering that the clang compiler correctly increases the underlying type's size (and uses
unsigned int
unless negative values are present):https://godbolt.org/z/K8neMYrYT
OS: Windows 10
Target: MSVC
The text was updated successfully, but these errors were encountered: