[llvm-bugs] [Bug 51689] New: Clang introduces invalid padding for empty base classes

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 31 10:16:23 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51689

            Bug ID: 51689
           Summary: Clang introduces invalid padding for empty base
                    classes
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: CUDA
          Assignee: unassignedclangbugs at nondot.org
          Reporter: joachim at joameyer.de
                CC: llvm-bugs at lists.llvm.org

Following up on issues reported in
https://github.com/illuhad/hipSYCL/issues/620#issuecomment-908400489 we tracked
the issue down to an invalid struct layout with multiple empty base classes.

https://godbolt.org/z/xoa9P38vW

The example introduces invalid padding on Windows hosts, thus leading to issues
when using the `has_wrong_size` class in CUDA or similar contexts, where the
layout of the class is of high importance.

Note that the device code has no padding and would compile fine.

#include <stdint.h>

class test0{};
class test1{};
class test2{public: uint64_t s;};

class works : public test0,  public test2{};

static_assert(__builtin_offsetof(works, s) == 0, "offset");

static_assert(sizeof(works) == sizeof(uint64_t), "size wrong");

class has_wrong_size : public test0, public test1, public test2{};
//#ifdef __CUDACC__ // is fine on CUDA
static_assert(__builtin_offsetof(has_wrong_size, s) == 0, "offset");

static_assert(sizeof(has_wrong_size) == sizeof(uint64_t), "size wrong");
//#endif

-- 
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/20210831/4b4e3f65/attachment.html>


More information about the llvm-bugs mailing list