Skip to content

[lldb][DWARFASTParserClang] Prevent unnamed bitfield creation in the presence of overlapping fields #10591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: swift/release/6.2
Choose a base branch
from

Conversation

Michael137
Copy link

@Michael137 Michael137 commented Apr 30, 2025

Because Clang doesn't emit DW_TAG_members for unnamed bitfields, LLDB
has to make an educated guess about whether they existed in the source.
It does so by checking whether there is a gap between where the last
field ended and the currently parsed field starts. In the example test
case, the empty field padding was folded into the storage of data.
Because the bit_offset of padding is 0x0 and its DW_AT_byte_size
is 0x1, LLDB thinks the field ends at 0x1 (not quite because we
first round the size to a word size, but this is an implementation
detail), erroneously deducing that there's a gap between flag and
padding.

This patch adds the notion of "effective field end", which accounts for
fields that share storage. It is set to the end of the storage that the
two fields occupy. Then we use this to check for gaps in the unnamed
bitfield creation logic.

(cherry picked from commit a6a547f)

@Michael137 Michael137 requested a review from a team as a code owner April 30, 2025 17:56
@Michael137
Copy link
Author

@swift-ci test

@Michael137
Copy link
Author

@swift-ci test

@Michael137
Copy link
Author

@swift-ci test Windows

… into helper (llvm#108196)

This logic will need adjusting soon for
llvm#108155

This patch pulls out the logic for detecting/creating unnamed bitfields
out of `ParseSingleMember` to make the latter (in my opinion) more
readable. Otherwise we have a large number of similarly named variables
in scope.

(cherry picked from commit f0c6d30)
@Michael137 Michael137 force-pushed the lldb/unnamed-bitfields-to-6.2 branch from 01f6adc to 32be8c9 Compare May 1, 2025 08:29
@Michael137
Copy link
Author

@swift-ci test

@Michael137 Michael137 changed the title [lldb][DWARFASTParserClang][NFC] Factor out unnamed bitfield creation into helper [lldb][DWARFASTParserClang] Prevent unnamed bitfield creation in the presence of overlapping fields May 1, 2025
@adrian-prantl
Copy link

@swift-ci test

@Michael137
Copy link
Author

@swift-ci test macos

Michael137 added 2 commits May 1, 2025 18:03
…presence of overlapping fields (llvm#108343)

This bug surfaced after llvm#105865
(currently reverted, but blocked on this to be relanded).

Because Clang doesn't emit `DW_TAG_member`s for unnamed bitfields, LLDB
has to make an educated guess about whether they existed in the source.
It does so by checking whether there is a gap between where the last
field ended and the currently parsed field starts. In the example test
case, the empty field `padding` was folded into the storage of `data`.
Because the `bit_offset` of `padding` is `0x0` and its `DW_AT_byte_size`
is `0x1`, LLDB thinks the field ends at `0x1` (not quite because we
first round the size to a word size, but this is an implementation
detail), erroneously deducing that there's a gap between `flag` and
`padding`.

This patch adds the notion of "effective field end", which accounts for
fields that share storage. It is set to the end of the storage that the
two fields occupy. Then we use this to check for gaps in the unnamed
bitfield creation logic.

(cherry picked from commit a6a547f)
@Michael137 Michael137 force-pushed the lldb/unnamed-bitfields-to-6.2 branch from 32be8c9 to 374b6f2 Compare May 1, 2025 17:04
@Michael137
Copy link
Author

@swift-ci test

@Michael137
Copy link
Author

@swift-ci test macos

@Michael137
Copy link
Author

@swift-ci test windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants