[llvm-bugs] [Bug 48776] New: Wrong alignment of __declspec(align)ed structs

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jan 16 15:15:09 PST 2021


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

            Bug ID: 48776
           Summary: Wrong alignment of __declspec(align)ed structs
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ju.orth at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Consider

__declspec(align(2)) struct X {
        int a;
};

#pragma pack(1)

struct Y {
        struct X x;
};

int f(void) {
    return _Alignof(struct Y);
}

msvc returns 2, clang returns 4 on the x86_64-pc-windows-msvc target.
Presumably because of [1]. If a struct has _any_ alignment attribute, the
branch is taken and the overall alignment of the struct is considered required.
I do not know the actual behavior of msvc, but I figure that the fix is to
exclude RecordType fields from this branch because their required alignment is
already handled in [2]. This bug seems to have been introduced in [3].


[1]
https://github.com/llvm-mirror/clang/blob/aa231e4be75ac4759c236b755c57876f76e3cf05/lib/AST/RecordLayoutBuilder.cpp#L2447-L2449
[2]
https://github.com/llvm-mirror/clang/blob/aa231e4be75ac4759c236b755c57876f76e3cf05/lib/AST/RecordLayoutBuilder.cpp#L2456-L2462
[3] https://reviews.llvm.org/D4714

-- 
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/20210116/913255be/attachment.html>


More information about the llvm-bugs mailing list