[all-commits] [llvm/llvm-project] 18baeb: [ADT] Alternative way to declare enum type as bitmask

Serge Pavlov via All-commits all-commits at lists.llvm.org
Mon Feb 20 22:45:55 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 18baeb89b566a1c0011c6a9960f402bd151224dd
      https://github.com/llvm/llvm-project/commit/18baeb89b566a1c0011c6a9960f402bd151224dd
  Author: Serge Pavlov <sepavloff at gmail.com>
  Date:   2023-02-21 (Tue, 21 Feb 2023)

  Changed paths:
    M llvm/include/llvm/ADT/BitmaskEnum.h
    M llvm/unittests/ADT/BitmaskEnumTest.cpp

  Log Message:
  -----------
  [ADT] Alternative way to declare enum type as bitmask

If an enumeration represents a set of bit flags, using the macro
LLVM_MARK_AS_BITMASK_ENUM can make operations with such enumeration more
convenient. It however brings problems if the enumeration is non-scoped.
As the macro adds an item LLVM_BITMASK_LARGEST_ENUMERATOR to the
enumeration type, only one such type may be declared as bitmask. This
problem could be solved by convertion of the enumeration to scoped, but
it requires static_casts in new places and the convenience can be
eliminated.

This change introduces a new macro LLVM_DECLARE_ENUM_AS_BITMASK, which
allows non-invasive convertion of an enumeration into bitmask. It
provides specialization to trait classes, which previously were built
based on presence of LLVM_BITMASK_LARGEST_ENUMERATOR in the enumeration.
The macro must be specified in global or llvm namespace because the
trait classes are declared in llvm namespace.

Differential Revision: https://reviews.llvm.org/D144202




More information about the All-commits mailing list