[LLVMbugs] [Bug 21040] New: Assertion failed in CGRecordLayoutBuilder.cpp:526 (Prior->Kind == MemberInfo::Field && !Prior->FD && "Only storage fields have tail padding!)
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Sep 23 03:27:04 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=21040
Bug ID: 21040
Summary: Assertion failed in CGRecordLayoutBuilder.cpp:526
(Prior->Kind == MemberInfo::Field && !Prior->FD &&
"Only storage fields have tail padding!)
Product: clang
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: andrea.dibiagio at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
To reproduce the assertion failure,
//////
struct A {
int a0[0]; // zero-length array.
};
struct B : private A { // assertion failure!
int b;
};
B bb;
//////
CGrecordLayoutBuilder.cpp:526: void
{anonymous}::CGRecordLowering::clipTailPadding(): Assertion `Prior->Kind ==
MemberInfo::Field && !Prior->FD && "Only storage fields have tail padding!"
failed.
Note that if we replace the zero-length array within struct A with a C99-style
flexible array, then the compiler doesn't assert. Instead, it emits the
following " error: base class 'A' has a flexible array member'.
Example:
//////
struct A {
int a0[]; // c99 style flexible array.
};
struct B : private A { // expected diagnostic error.
int b;
};
B bb;
//////
The error is raised by Sema (see SemaDeclCXX.cpp at around line 1457). The
comments in the code say that: "A class which contains a flexible array member
is not suitable for use as a base class". The motivation in this case is: "if
the layout determines that a base comes before the derived class, the flexible
array member would index into the derived class".
My opinion is that we should treat zero-length arrays the same way as flexible
arrays for the purpose of layout. This is because zero-length arrays are an
alternative (deprecated) way to specify flexible arrays (see
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html for further details).
At the very least, clang shouldn't assert.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140923/ffb19204/attachment.html>
More information about the llvm-bugs
mailing list