aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg-Johann Lay <avr@gjlay.de>2024-12-07 14:40:28 +0100
committerGeorg-Johann Lay <avr@gjlay.de>2024-12-12 15:02:21 +0100
commitbc565843ea20a616dd376226416777a4ea1959d6 (patch)
tree1e5bdbde329ff635f1a3f321329d48e03c0dcf2f
parentf8a602ce5394ef7e0c56b48e3bd89f97f0411c45 (diff)
downloadgcc-bc565843ea20a616dd376226416777a4ea1959d6.zip
gcc-bc565843ea20a616dd376226416777a4ea1959d6.tar.gz
gcc-bc565843ea20a616dd376226416777a4ea1959d6.tar.bz2
AVR: Assert minimal required bit width of section_common::flags.
gcc/ * config/avr/avr.cc (avr_ctz): New constexpr function. (section_common::flags): Assert minimal bit width.
-rw-r--r--gcc/config/avr/avr.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 97f5fbe..ef23601 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -237,6 +237,35 @@ int n_avr_fuse_add_executed = 0;
static location_t avr_insn_location = UNKNOWN_LOCATION;
+/* Similar to ctz_hwi etc, but as constexpr so we can use it in
+ static_assert. */
+static constexpr int
+avr_ctz (uint64_t x)
+{
+#define TSTB(n) (x & ((uint64_t) 1 << n)) ? n
+ return
+ TSTB (0) : TSTB (1) : TSTB (2) : TSTB (3) : TSTB (4)
+ : TSTB (5) : TSTB (6) : TSTB (7) : TSTB (8) : TSTB (9)
+ : TSTB (10) : TSTB (11) : TSTB (12) : TSTB (13) : TSTB (14)
+ : TSTB (15) : TSTB (16) : TSTB (17) : TSTB (18) : TSTB (19)
+ : TSTB (20) : TSTB (21) : TSTB (22) : TSTB (23) : TSTB (24)
+ : TSTB (25) : TSTB (26) : TSTB (27) : TSTB (28) : TSTB (29)
+ : TSTB (30) : TSTB (31) : TSTB (32) : TSTB (33) : TSTB (34)
+ : TSTB (35) : TSTB (36) : TSTB (37) : TSTB (38) : TSTB (39)
+ : TSTB (40) : TSTB (41) : TSTB (42) : TSTB (43) : TSTB (44)
+ : TSTB (45) : TSTB (46) : TSTB (47) : TSTB (48) : TSTB (49)
+ : TSTB (50) : TSTB (51) : TSTB (52) : TSTB (53) : TSTB (54)
+ : TSTB (55) : TSTB (56) : TSTB (57) : TSTB (58) : TSTB (59)
+ : TSTB (60) : TSTB (61) : TSTB (62) : TSTB (63)
+ : 64;
+#undef TSTB
+}
+
+/* Make sure that there are enough section flags bits. avr allocates 4. */
+static_assert (8 * sizeof (decltype (section_common::flags))
+ >= 4u + avr_ctz (SECTION_MACH_DEP),
+ "section_common::flags is too narrow");
+
/* Transform UP into lowercase and write the result to LO.
You must provide enough space for LO. Return LO. */