This is an archive of the discontinued LLVM Phabricator instance.

Non-POD unions with bit-fields causes an assertion failure at clang/lib/AST/RecordLayoutBuilder.cpp:754
ClosedPublic

Authored by eastig on Oct 14 2014, 8:34 AM.

Details

Reviewers
majnemer
Summary

The following program:

union A {

int f1: 3;
A();

};

A::A() {}

causes the failure of the assertion "DataSize % Context.getCharWidth() == 0" at clang/lib/AST/RecordLayoutBuilder.cpp:754.

It happens because '2.4 Non-POD Class Types/II. Allocation of Members Other Than Virtual Bases/1. bit-fileds' of C++ ABI (http://mentorembedded.github.io/cxx-abi/abi.html#class-types) is implemented incorrectly: dsize(C) is not updated to include the last byte containing (part of) the bitfield.

Diff Detail

Event Timeline

eastig updated this revision to Diff 14870.Oct 14 2014, 8:34 AM
eastig retitled this revision from to Non-POD unions with bit-fields causes an assertion failure at clang/lib/AST/RecordLayoutBuilder.cpp:754.
eastig updated this object.
eastig edited the test plan for this revision. (Show Details)
eastig added a subscriber: Unknown Object (MLST).

I don't think there is much need to run the test for both x86-64 and aarch64, I'd just run the x86-64 one.

I think it's unneccesary to have two different files here, one file for both tests is sufficient. Just rename one of the A classes to B.

Please match the existing convention in test/Layout, rename union_regular_bit_field.cpp to include 'itanium' somewhere in there and please use dashes instead of underscores. Perhaps itanium-x86-union-bitfield.

lib/AST/RecordLayoutBuilder.cpp
1350–1351

Functions start with a lower case character.

I would just call this roundUpSizeToCharAlignment. This name, while more generic, is less confusing if we chose to use it in other places of record layout.

const uint64_t looks abnormal compared to most of clang's code, I would just go with uint64_t here.

test/Layout/union_regular_bit_field.cpp
1–4

These triples are not specific enough. Make sure you specify the itanium ABI somehow.

13–14

Please include more CHECK lines so that more tests can easily be added to this file.

test/Layout/union_wide_bit_field.cpp
1–4

Likewise.

ABataev added inline comments.
test/Layout/union_regular_bit_field.cpp
1–4

You can use %itanium_abi_triple as a triple in tests

eastig updated this revision to Diff 14999.Oct 16 2014, 2:41 AM

Updated the patch according to comments.

majnemer accepted this revision.Oct 16 2014, 9:34 AM
majnemer added a reviewer: majnemer.

LGTM

This revision is now accepted and ready to land.Oct 16 2014, 9:34 AM
eastig closed this revision.Oct 17 2014, 10:03 AM

Committed to revisions: 220031, 220032