Repository navigation
clangparser: Fix issue with duplicate defition of typedef'd enum - #158
Open
tkeeffe-cacdsp wants to merge 1 commit into
Open
tkeeffe-cacdsp wants to merge 1 commit into
tkeeffe-cacdsp wants to merge 1 commit into
Conversation
When an enum of the form `typedef enum { A, B, C } abc_t` is parsed as
part of a source file that is listed in the clang2py's arguments, the
enum is parsed registered first, independently from the typedef, then
the typedef is parsed completely after the enum is done. This doesn't
cause issues because the TYPEDEF_DECL handler checks for a cached type
first. However, when parsed as part of an included header, the typedef
is parsed first and the enum is parsed as a result of the typedef being
parsed. This happens *after* the cache check happens, but before the
typedef is registered. Thus when the typedef is registered, a
DuplicateDefinitionException is raised.
Note that this behavior is different than structs because untagged enums
that are part of a typedef do NOT have an .name or .spelling field like
an anonymous struct would. Clang inserts the typedef name into the enum
declaration for quality of life or debugging purposes or something.
Further, is_anonymous() doesn't work on enums, only structs and unions.
The fix is to allow the register() call to return the registered enum
when called with a typedef where the typedef'd object is the same as the
enum object. The added test (test_enum_typedef) ensures that the output
of the bug reproduction (test/data/test-enum-typedef.{c,h}) is identical
whether the header is parsed directly from the argument list or as an
include.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When an enum of the form
typedef enum { A, B, C } abc_tis parsed as part of a source file that is listed in the clang2py's arguments, the enum is parsed registered first, independently from the typedef, then the typedef is parsed completely after the enum is done. This doesn't cause issues because the TYPEDEF_DECL handler checks for a cached type first. However, when parsed as part of an included header, the typedef is parsed first and the enum is parsed as a result of the typedef being parsed. This happens after the cache check happens, but before the typedef is registered. Thus when the typedef is registered, a DuplicateDefinitionException is raised.Note that this behavior is different than structs because untagged enums that are part of a typedef do NOT have an empty .name or .spelling field like an anonymous struct would. Clang inserts the typedef name into the enum declaration for quality of life or debugging purposes or something. Further, is_anonymous() doesn't work on enums (always returns False), only structs and unions.
The fix is to allow the register() call to return the registered enum when called with a typedef where the typedef'd object is the same as the enum object. The added test (test_enum_typedef) ensures that the output of the bug reproduction (test/data/test-enum-typedef.{c,h}) is identical whether the header is parsed directly from the argument list or as an include.