This is an archive of the discontinued LLVM Phabricator instance.

[BPF] fix a bug in __builtin_preserve_field_info() with FIELD_BYTE_SIZE
ClosedPublic

Authored by yonghong-song on Nov 3 2019, 7:33 AM.

Details

Summary

During deriving proper bitfield access FIELD_BYTE_SIZE,
function Member->getStorageOffsetInBits() is used to
get llvm IR type storage offset in bits so that
the byte size can permit aligned loads/stores with previously
derived FIELD_BYTE_OFFSET.

The function should only be used with bitfield members and it will
assert if ASSERT is turned on during cmake build.

Constant *getStorageOffsetInBits() const {
  assert(getTag() == dwarf::DW_TAG_member && isBitField());
  if (auto *C = cast_or_null<ConstantAsMetadata>(getExtraData()))
    return C->getValue();
  return nullptr;
}

This patch fixed the issue by using Member->isBitField()
directly and a test case is added to cover this missing case.
This issue is discovered when running Andrii's linux kernel CO-RE
tests.

Diff Detail

Event Timeline

yonghong-song created this revision.Nov 3 2019, 7:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2019, 7:33 AM
ast accepted this revision.Nov 3 2019, 8:09 AM
This revision is now accepted and ready to land.Nov 3 2019, 8:09 AM
This revision was automatically updated to reflect the committed changes.