LLVM_MARK_AS_BITMASK_ENUM lets you opt in an individual enum type so you can perform bitwise operations on it without putting static_cast everywhere.
Declared in <llvm/ADT/BitmaskEnum.h>
#define LLVM_MARK_AS_BITMASK_ENUM(LargestValue)
enum MyEnum {
E1 = 1, E2 = 2, E3 = 4, E4 = 8,
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ E4)
};
void Foo() {
MyEnum A = (E1 | E2) & E3 ^ ~E4; // Look, ma: No static_cast!
}
Normally when you do a bitwise operation on an enum value, you get back an instance of the underlying type (e.g. int). But using this macro, bitwise ops on your enum will return you back instances of the enum. This is particularly useful for enums which represent a combination of flags.
The parameter to LLVM_MARK_AS_BITMASK_ENUM should be the largest individual value in your enum.
All of the enum's values must be non-negative.