Skip to content

Commit 6ad914b

Browse files
committed
[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.
1 parent d9b1500 commit 6ad914b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lld/ELF/Arch/Cheri.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,15 @@ static uint64_t getTargetSize(const CheriCapRelocLocation &location,
310310

311311
template <class ELFT>
312312
struct CaptablePermissions {
313-
static const uint64_t function =
314-
UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - 1);
315-
static const uint64_t readOnly =
316-
UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - 2);
317-
static const uint64_t indirect =
318-
UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - 3);
313+
static constexpr uint64_t permissionBit(uint64_t bit) {
314+
return UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - bit);
315+
}
316+
317+
// clang-format off
318+
static const uint64_t function = permissionBit(1);
319+
static const uint64_t readOnly = permissionBit(2);
320+
static const uint64_t indirect = permissionBit(3);
321+
// clang-format on
319322
};
320323

321324
template <class ELFT>

0 commit comments

Comments
 (0)