Skip to content

Conversation

@axd1x8a
Copy link

@axd1x8a axd1x8a commented May 26, 2025

Add Support for C23 Enum Types and Refine Sizing

Key changes:

  • C23 Underlying Type Parsing: The parser now correctly handles enum : <type> syntax.
  • Enum Resizing:
    • For enums with an explicit C23 underlying type, the size is determined by that type (validated to be 1, 2, 4, or 8 bytes), or the minimum size required by its members, whichever is larger
    • For enums without an explicit type, the size is now set to the minimum length required by their members, like it done by compilers
      Enums with __attribute__((__packed__)) or [[packed]] attributes and without an explicit type will be resized to fit largest member.

FIxes:

@axd1x8a
Copy link
Author

axd1x8a commented May 26, 2025

Oh, I just read the comments in the original issue, maybe automatic resizing should be removed?

@axd1x8a
Copy link
Author

axd1x8a commented May 27, 2025

I've added handling for __attribute__((__packed__)) and [[packed]] attributes (supported by GCC/Clang) for more explicit enum sizing, instead of always resizing. I also added tests for negative values in these enums, as I saw some issues for this.

Could you please link any relevant issues? I think there are more of them than I found.

@axd1x8a axd1x8a changed the title Add C23 enum types support for C parser Add C23 enum types and packing attributes support for C parser May 27, 2025
@ryanmkurtz ryanmkurtz added Feature: C-Parser Status: Triage Information is being gathered labels May 27, 2025
@antoniovazquezblanco
Copy link
Contributor

The following PR is related to a similar issue.

#6780

Referenced for tracking.

I hope this helps @emteere.

Thanks!

@axd1x8a
Copy link
Author

axd1x8a commented May 30, 2025

Oh, I was unaware that a separate PR existed for packed attributes.
I hope it won't take as long to merge this as the previous one

@antoniovazquezblanco
Copy link
Contributor

I hope so but things here move slowly...

@axd1x8a axd1x8a force-pushed the cparser-c23-enums branch 2 times, most recently from 397eff7 to fe019f4 Compare August 23, 2025 08:54
@Zeranoe
Copy link

Zeranoe commented Oct 10, 2025

I missed this when I opened #8539, which adds the type support. It appears we independently arrived at roughly the same code, though I used TypeName() instead of BuiltInTypeSpecifier() because it will properly handle things like enum _PROOF_OF_POSSESSION_FLAGS : DWORD (#8495).

@axd1x8a
Copy link
Author

axd1x8a commented Nov 16, 2025

Could someone review any of these PRs? The option to specify the size of an enum is useful when generating C code for Ghidra to parse, but having to build a custom version every time I need to do so is very troublesome

@ryanmkurtz ryanmkurtz added Status: Prioritize This is currently being prioritized and removed Status: Triage Information is being gathered labels Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature: C-Parser Status: Prioritize This is currently being prioritized

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants