Skip to content

Commit 529e2be

Browse files
jrtc27resistor
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.
1 parent b86ac3b commit 529e2be

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
@@ -314,12 +314,15 @@ static uint64_t getTargetSize(Ctx &ctx, const CheriCapRelocLocation &location,
314314

315315
template <class ELFT>
316316
struct CaptablePermissions {
317-
static const uint64_t function = UINT64_C(1)
318-
<< ((sizeof(typename ELFT::uint) * 8) - 1);
319-
static const uint64_t readOnly = UINT64_C(1)
320-
<< ((sizeof(typename ELFT::uint) * 8) - 2);
321-
static const uint64_t indirect = UINT64_C(1)
322-
<< ((sizeof(typename ELFT::uint) * 8) - 3);
317+
static constexpr uint64_t permissionBit(uint64_t bit) {
318+
return UINT64_C(1) << ((sizeof(typename ELFT::uint) * 8) - bit);
319+
}
320+
321+
// clang-format off
322+
static const uint64_t function = permissionBit(1);
323+
static const uint64_t readOnly = permissionBit(2);
324+
static const uint64_t indirect = permissionBit(3);
325+
// clang-format on
323326
};
324327

325328
template <class ELFT>

0 commit comments

Comments
 (0)