8261578: jextract crashes with Crossing storage unit boundaries #451
This patch overhauls the logic for bitfield detection, after discovering a number of related failures. The current logic attempts to find a unique container size for a bunch of adjacent bitfields (either 8, 16, 32 or 64 bits) and then allocates the bitfields into subsequent containers of same size.
The fact that the container size is decided once and for all at the beginning of parsing of the bitfield sequence is problematic, and breaks down in cases where containers are used only partially, or where padding is inserted.
To overcome these issues, I've now switched to a more flexible algorithm which, instead of fixing a container size before hands, just emits a new container whenever the cumulative offset of adjacent bitfield has reached a word boundary (either 8, 16, 32, 64 bits).
This makes the algorithm less strict, and less prone to crashes. However, since we're still reverse engineering bitfield information (as libclang doesn't give us that information), the solution will probably require more tweaks, especially in order to support packed structures, in which compilers emit bitfields which happily span across a word boundary.
For this reason, I did not included some of the examples listed in JDK-8261578 which make use of the
As for testing, I followed what other tests in this area did in the past - but I believe at some point we probably need to write better tests which use the jextract API to query bitfield offsets and sizes, because the tests, as currently written, do not assert much, other than that jextract is not failing badly.
The text was updated successfully, but these errors were encountered:
@mcimadamore This change now passes all automated pre-integration checks.
After integration, the commit message for the final commit will be:
At the time when this comment was updated there had been no new commits pushed to the