[llvm] [DebugInfo] Add DW_OP_LLVM_extract_bits (PR #93990)
John Brawn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 08:00:31 PDT 2024
john-brawn-arm wrote:
> Can you explain why the signedness matters?
If we have
```
typedef struct __attribute__((packed)) {
unsigned int x : 4;
signed int y : 4;
} struct_t;
struct_t g = {1, -1};
int main() {
auto [x, y] = g;
return x+y;
}
```
then if y isn't sign-extended, looking at the values in a debugger we have
```
frame #0: 0x00007ffff7fff164 a.out`main at tmp.cpp:10:10
7
8 int main() {
9 auto [x, y] = g;
-> 10 return x+y;
11 }
(lldb) p x
(unsigned int) 1
(lldb) p y
(int) 15
(lldb) p x+y
(unsigned int) 16
```
which is wrong. If it's sign-extended we have
```
frame #0: 0x00007ffff7fff164 a.out`main at tmp.cpp:10:10
7
8 int main() {
9 auto [x, y] = g;
-> 10 return x+y;
11 }
(lldb) p x
(unsigned int) 1
(lldb) p y
(int) -1
(lldb) p x+y
(unsigned int) 0
```
which is correct.
https://github.com/llvm/llvm-project/pull/93990
More information about the llvm-commits
mailing list