Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alignment not respected in containers for over-aligned enumeration types #41741

Closed
mclow opened this issue Jun 25, 2019 · 2 comments
Closed

Alignment not respected in containers for over-aligned enumeration types #41741

mclow opened this issue Jun 25, 2019 · 2 comments
Labels
bugzilla Issues migrated from bugzilla invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@mclow
Copy link
Contributor

mclow commented Jun 25, 2019

Bugzilla Link 42396
Resolution INVALID
Resolved on Jun 25, 2019 15:41
Version unspecified
OS All
Attachments Reproducer
CC @dwblaikie,@mclow,@zygoloid

Extended Description

Inspired by: https://stackoverflow.com/questions/56760874/discrepancy-in-c-between-over-aligned-struct-and-enum-within-container

Given an enumeration type with a specified alignment, the elements in a vector of such a type should be aligned correctly. This appears not to be the case - and can lead to UBSAN going off.

In the reproducer, I also check the size of a 16-element array of these two types.
Clang says they're different sizes - that suggests to me that there's a clang problem here.

The alignment in the containers bit could be related to #23008 . (might even be the same bug)

@mclow
Copy link
Contributor Author

mclow commented Jun 25, 2019

Now I'm very confused.

====
struct alignas(16) byte_struct {std::uint8_t value;};
enum alignas(16) byte_enum : std::uint8_t { one=1, two, three };

int main() {
std::cout << "struct: " << sizeof(byte_struct) << std::endl;
std::cout << "enum: " << sizeof(byte_enum ) << std::endl;
std::cout << "01 structs: " << sizeof(byte_struct[1]) << std::endl;
std::cout << "01 enums: " << sizeof(byte_enum [1]) << std::endl;
std::cout << "02 structs: " << sizeof(byte_struct[2]) << std::endl;
std::cout << "02 enums: " << sizeof(byte_enum [2]) << std::endl;
std::cout << "16 structs: " << sizeof(byte_struct[16]) << std::endl;
std::cout << "16 enums: " << sizeof(byte_enum [16]) << std::endl;
}

prints (with a reasonably recent clang):

struct: 16
enum: 1
01 structs: 16
01 enums: 16
02 structs: 32
02 enums: 16
16 structs: 256
16 enums: 16

@mclow
Copy link
Contributor Author

mclow commented Jun 25, 2019

Richard pointed out (on SO) that this is core issue 2354. Extended alignment and object representation, which was resolved in Kona by removing the ability to put 'alignas' on enumeration types.

Closing as invalid.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

1 participant