This is an archive of the discontinued LLVM Phabricator instance.

[NFC][MSan] Round up OffsetPtr in PoisonMembers
ClosedPublic

Authored by vitalybuka on Dec 6 2020, 12:09 AM.

Details

Summary

getFieldOffset(layoutStartOffset) is expected to point to the first trivial
field or the one which follows non-trivial. So it must be byte aligned already.
However this is not obvious without assumptions about callers.
This patch will avoid the need in such assumptions.

Depends on D92727.

Diff Detail

Event Timeline

vitalybuka requested review of this revision.Dec 6 2020, 12:09 AM
vitalybuka created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2020, 12:09 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
morehouse added inline comments.Dec 7 2020, 8:14 AM
clang/lib/CodeGen/CGClass.cpp
1742

How does this interact with bit fields?

Don't you want to similarly align down PoisonEnd?

But if this is something that should never happen, as your comment rightly suggests, wouldn't it be better to add an assert()?
The same in the case when PoisonSize < 0 - it should never happen.

vitalybuka retitled this revision from [NFC][MSan] Round up OffsetPtr in PoisonMembersgetFieldOffset(layoutStartOffset) for current calleds is expected topoint to the first trivial field or the one which follows non-trivial.So it must be byte aligned. However this is not obvious... to [NFC][MSan] Round up OffsetPtr in PoisonMembers.Dec 7 2020, 1:42 PM
vitalybuka edited the summary of this revision. (Show Details)

Don't you want to similarly align down PoisonEnd?

But if this is something that should never happen, as your comment rightly suggests, wouldn't it be better to add an assert()?
The same in the case when PoisonSize < 0 - it should never happen.

clang/lib/CodeGen/CGClass.cpp
1742

I guess existing code work because is bit fields are trivial and the one aligned to the char is going to be layoutStartOffset
I assume if we call this function for layoutStartOffset pointing to the bitfield in the middle of char it will poison entire byte which is incorrect.
With the patch it will not poison such chars: now it will be either all bits or nothing which I believe better.

1742

toCharUnitsFromBits already down aligns by definition: it's just a bitsoffset/charwidth

regarding assert: I am not 100% that this is not possible, maybe some corner-case in language allows that.
if so, it's better not to poison partial byte at all than poison it completely.

eugenis accepted this revision.Dec 7 2020, 2:51 PM

LGTM

clang/lib/CodeGen/CGClass.cpp
1742

I assume if we call this function for layoutStartOffset pointing to the bitfield in the middle of char it will poison entire byte which is incorrect.

Right. We never do this, of course, because the previous non-trivial field can not possibly end in the middle of a char.

This revision is now accepted and ready to land.Dec 7 2020, 2:51 PM
This revision was landed with ongoing or failed builds.Dec 7 2020, 8:19 PM
This revision was automatically updated to reflect the committed changes.