<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/129256>129256</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
wbN: A suffix for specifying the width of a bit-precise integer literal
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
alejandro-colomar
</td>
</tr>
</table>
<pre>
Currently, we have no way of specifying the width of a bit-precise integer literal. We only have the wb suffix, which say "pick the smaller width possible".
That wb suffix is insufficient, as sometimes we need a type wider than the value we're using, if we're going to use for example shifts.
As an example, there's no good way (and by good, I mean something that doesn't involve casts) to create a value of width N (let's use 3 as a small example) where all bits are 1 except for the leftmost (or rightmost) one.
```c
alx@debian:~/tmp$ cat bw.c
int
main(void)
{
unsigned _BitInt(3) i = ~0wb >> 1;
return i;
}
alx@debian:~/tmp$ gcc -Wall -Wextra bw.c
alx@debian:~/tmp$ ./a.out; echo $?
7
alx@debian:~/tmp$ clang -Weverything -Wno-c23-extensions -Wno-bit-int-extension bw.c
bw.c:4:31: warning: implicit conversion changes signedness: '_BitInt(2)' to 'unsigned _BitInt(3)' [-Wsign-conversion]
4 | unsigned _BitInt(3) i = ~0wb >> 1;
| ~ ~~~~~^~~~
1 warning generated.
alx@debian:~/tmp$ ./a.out; echo $?
7
```
It would make sense to be able to write it like this (IMO):
```c
unsigned _BitInt(3) i = ~0wb3u >> 1; // stores the value 5 (0b011).
```
GCC bug: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119058>
Cc: @AaronBallman
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVU-Po7gT_TSVSynI2DAJBw4kPfmpD7_Zy0p9HBlTgKeNHdkmdPbQn31lku4e7e6M9g-Kgim7Xr16VbZlCHqwRDWUBygfNnKOo_O1NPRN2s67rXLGTdJvWtdd6-PsPdlorsCPuBCO8kJoHS7yiq7HcCal-6u2A8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