LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 48776 - Wrong alignment of __declspec(align)ed structs
Summary: Wrong alignment of __declspec(align)ed structs
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: C (show other bugs)
Version: 11.0
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-16 15:15 PST by ju.orth
Modified: 2021-01-19 10:12 PST (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ju.orth 2021-01-16 15:15:09 PST
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