llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.03k stars 11.58k forks source link

Wrong size of arrays with over-aligned elements #48131

Open mahkoh opened 3 years ago

mahkoh commented 3 years ago
Bugzilla Link 48787
Version 11.0
OS Linux
CC @DougGregor,@zygoloid

Extended Description

Consider

__declspec(align(8)) typedef int Int[3];

struct Y {
    Int y[3];
    int i;
};

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

msvc returns 40, clang returns 48 for the x86_64-pc-windows-msvc target. Presumably because [1] rounds up the size to the alignment.

[1] https://github.com/llvm/llvm-project/blob/689aaba7acf5778bfe96bfd7bc4f1f3ceed20dc8/clang/lib/AST/ASTContext.cpp#L1926-L1928

llvmbot commented 5 months ago

@llvm/issue-subscribers-clang-frontend

Author: None (mahkoh)

| | | | --- | --- | | Bugzilla Link | [48787](https://llvm.org/bz48787) | | Version | 11.0 | | OS | Linux | | CC | @DougGregor,@zygoloid | ## Extended Description Consider ```cpp __declspec(align(8)) typedef int Int[3]; struct Y { Int y[3]; int i; }; int f(void) { return sizeof(struct Y); } ``` msvc returns 40, clang returns 48 for the x86_64-pc-windows-msvc target. Presumably because [1] rounds up the size to the alignment. [1] https://github.com/llvm/llvm-project/blob/689aaba7acf5778bfe96bfd7bc4f1f3ceed20dc8/clang/lib/AST/ASTContext.cpp#L1926-L1928