<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/87641>87641</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Incorrect behavior when promoting bit-field of bit-precise type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Halalaluyafail3
      </td>
    </tr>
</table>

<pre>
    Clang promotes to the incorrect type when applying integer promotions to bit-fields of bit-precise type, for example:
```c
#include<stdio.h>
int main(void){
        puts(_Generic(
                +(struct{unsigned _BitInt(7)x:2;}){}.x,
                unsigned _BitInt(2):"A",unsigned _BitInt(7):"B",int:"C"
        ));
}
```
This program should output "B", but clang outputs "C".
> The value from a bit-field of a bit-precise integer type is converted to the corresponding bit-precise
integer type. If the original type is not a bit-precise integer type (6.2.5): if an int can represent all
values of the original type (as restricted by the width, for a bit-field), the value is converted to an
int; otherwise, it is converted to an unsigned int. These are called the integer promotions. All
other types are unchanged by the integer promotions
>
> (footnote) E.g. unsigned _BitInt(7): 2 is a bit-field that can hold the values 0, 1, 2, 3, and converts to unsigned _BitInt(7).

The promoted type of `unsigned _BitInt(7)x:2` isn't `int`, it should be `unsigned _BitInt(7)` as the footnote says.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VE1zqzoM_TVmoykDgvCxYNEk7Xvd3_0dAwL8xrEZ27TNv39jQ0hvb9vEIeOxjsTRORa3VoyKqGGHIzucI764SZvmXy79d7nygQuZRa3ur81JcjXCbPRFO7LgNLiJQKhOG0OdA3edCd4mUsDnWV6FGkEoRyOZDSS0CrBWuIdBkOwt6CHsZkOdsBRSMDzBoA3QO7_Mklj2yJIzSx5Zkayr2_aYCdXJpSeWnazrhY4nlj2th0I5uHChGFavWvQMa1YeN1xSz4uzDKvf_5AiIzqG1X7kFx4ZVtaZpXOsPC4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