In cases where a structured binding declaration is made to a struct with
bitfields:
struct A {
unsigned int x : 16; unsigned int y : 16;
} g;
auto [a, b] = g; // structured binding declaration
Clang assigns the 'unsigned int' DWARF base type to 'a' and 'b' because
this is their deduced C++ type in the structured binding declaration.
However, their actual type in memory is 'unsigned short' as they have 16
bits allocated for each.
This is a problem for debug information consumers: if the debug
information for 'a' has the 'unsigned int' base type, a debugger will
assume it has 4 bytes, whereas it actually has a length of 2, resulting
in a read (or write) past its length.
This patch mimics GCC's behaviour: in case of structured bindings to
bitfields, the binding declaration's DWARF base type is of the target's
integer type with the same bitwidth as the bitfield.
If no suitable integer type is found in the target, no debug information
is emitted anymore in order to prevent wrong debug output.
Can Ty be null? If not then it might be more understandable to return Ty here. If it can be null, does it make sense to fall back to BD->getType() below?