This is an archive of the discontinued LLVM Phabricator instance.

[AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when an external layout is used
ClosedPublic

Authored by aleksandr.urakov on Oct 22 2018, 6:48 AM.

Details

Summary

The patch removes alignment of virtual bases when an external layout is used. We have two cases:

  • the external layout source has an information about virtual bases offsets, so we just use them;
  • the external source has no information about virtual bases offsets. In this case we can't predict where the base will be located. If we will align it but there will be something like #pragma pack(push, 1) really, then likely our layout will not fit into the real structure size, and then some asserts will hit. The asserts look reasonable, so I don't think that we need to remove them. May be it would be better instead don't align fields / bases etc. (so treat it always as #pragma pack(push, 1)) when an external layout source is used but no info about a field location is presented.

This one is related to D49871

Also it seems that MicrosoftRecordLayoutBuilder with an external source and without one differ considerably, may be it is worth to split this and to create two different builders? I think that it would make the logic simpler. What do you think about it?

Diff Detail

Repository
rC Clang

Event Timeline

rnk accepted this revision.Oct 22 2018, 10:21 AM

Also it seems that MicrosoftRecordLayoutBuilder with an external source and without one differ considerably, may be it is worth to split this and to create two different builders? I think that it would make the logic simpler. What do you think about it?

Yes, I recall when reading the Itanium record layout code that it was riddled with extra checks for external layouts. Back then I thought it would be nicer to have a separate code path for external layouts. I appreciated that when we separated out the MS code, it was clean and not filled with these checks. But, of course, now here we are adding them in. If you want to do the work to come up with a separate, more minimal code path that produces ASTRecordLayouts from external layouts, I'd definitely help review it.

This change is pretty small and targeted, so feel free to land it as is first. Thanks!

This revision is now accepted and ready to land.Oct 22 2018, 10:21 AM
This revision was automatically updated to reflect the committed changes.