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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to