This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix calculating offset for fields with an empty type
ClosedPublic

Authored by jubnzv on Jun 11 2021, 1:26 AM.

Details

Summary

Fix offset calculation routines in padding checker to avoid assertion errors described in the following issue: https://bugs.llvm.org/show_bug.cgi?id=50426.
The fields that are subojbects of zero size, marked with [[no_unique_address]] or empty bitfields will be excluded from the padding calculation routines.

Diff Detail

Event Timeline

jubnzv created this revision.Jun 11 2021, 1:26 AM
jubnzv requested review of this revision.Jun 11 2021, 1:26 AM
jubnzv updated this revision to Diff 351423.Jun 11 2021, 5:53 AM
NoQ accepted this revision.Jun 14 2021, 9:13 PM

This looks correct, thanks!

I think there are some weird rules with respect to [[no_unique_address]] on two consecutive fields when there's only one other field in the structure, eg.

struct S {
    char c;
    [[no_unique_address]] Empty e1, e2;
};

will have a size of two bytes according to https://en.cppreference.com/w/cpp/language/attributes/no_unique_address.

It's probably worth a test case to see if we still calculate padding correctly in such cases but I don't insist.

This revision is now accepted and ready to land.Jun 14 2021, 9:13 PM
jubnzv updated this revision to Diff 352361.Jun 16 2021, 12:43 AM

Added two tests that check whether we still calculate padding correctly for structs with [[no_unique_address]] on two consecutive fields