This is an archive of the discontinued LLVM Phabricator instance.

[clang] Add simple utils to ensure static assert on bit count of DeclContext
Changes PlannedPublic

Authored by danix800 on Aug 18 2023, 11:33 AM.

Details

Summary

Manually counting bits for DeclContext is error-prone. These two are still out-dated:

  1. NumObjCMethodDeclBits (25, not 24)
  2. NumBlockDeclBits (6, not 5)

Although no harm at this moment but it's still misleading and might cause problem
for the future.

Two simple reflection-like utilities countBits & countFields are added for auto-
updating these bits at compile time and static assert on syncing with any changes.

Static assert on bit count is preserved since it's informative.

Bitfields cannot be listed at compile time easily, but assert on countFields can still
catch errors if fields are added/removed.

Diff Detail

Event Timeline

danix800 created this revision.Aug 18 2023, 11:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 11:33 AM
danix800 requested review of this revision.Aug 18 2023, 11:33 AM
danix800 edited the summary of this revision. (Show Details)Aug 19 2023, 3:08 AM
danix800 updated this revision to Diff 551737.Aug 19 2023, 4:01 AM

Remove ununsed code.

danix800 updated this revision to Diff 551738.Aug 19 2023, 4:02 AM

Apply git-clang-format

danix800 planned changes to this revision.Aug 19 2023, 10:39 PM