Skip to content

Commit 9641c3a

Browse files
jrtc27veselypeta
authored andcommitted
[NFC][ELF][CHERI] Make CaptablePermissions a bit less ugly
Note that the clang-format directives are in anticipation of future additions, where we will still want to keep the equals signs, and thus bit numbers, aligned to make it easier to read.
2 parents ece7406 + 6ad914b commit 9641c3a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lld/ELF/Arch/Cheri.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,16 @@ static uint64_t getTargetSize(const CheriCapRelocLocation &location,
395395

396396
template <class ELFT>
397397
struct CaptablePermissions {
398-
static const uint64_t function =
399-
UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - 1);
400-
static const uint64_t readOnly =
401-
UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - 2);
402-
static const uint64_t indirect =
403-
UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - 3);
404-
static const uint64_t dontSeal =
405-
UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - 4);
398+
static constexpr uint64_t permissionBit(uint64_t bit) {
399+
return UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - bit);
400+
}
401+
402+
// clang-format off
403+
static const uint64_t function = permissionBit(1);
404+
static const uint64_t readOnly = permissionBit(2);
405+
static const uint64_t indirect = permissionBit(3);
406+
static const uint64_t dontSeal = permissionBit(4);
407+
// clang-format on
406408
};
407409

408410
template <class ELFT>

0 commit comments

Comments
 (0)