Issue 61608
Summary [Clang] Clang misbehaves with some huge alignment values specified in `alignas`
Labels new issue
Assignees
Reporter frederick-vs-ja
    Clang currently accept the following code but it should not ([Godbolt link](https://godbolt.org/z/5hvejToG4)).
```C++
// Weaker alignments are also correctly supported
struct alignas(0x1000'0000) B {};
static_assert(sizeof(B) == 0x1000'0000);

// Wrong cases
struct alignas(0x2000'0000) B1 {};
static_assert(sizeof(B1) == 0x1);

struct alignas(0x4000'0000) B2 {};
static_assert(sizeof(B2) == 0x1);

struct alignas(0x8000'0000) B3 {};
static_assert(sizeof(B3) == 0x1);

struct alignas(0x1'0000'0000) B4 {};
static_assert(sizeof(B4) == 0x1);
```

Four alignment values (0x20000000, 0x40000000, 0x80000000, and 0x100000000) are silently accepted but not correctly supported. We should decide either to correctly support these alignment values or to reject them.

----
A similar issue occurs for C's `_Alignas` ([Godbolt link](https://godbolt.org/z/3MrYbbK4T)):
```C
// Weaker alignments are also correctly supported
struct  B {
    _Alignas(0x10000000) char ch;
};
_Static_assert(sizeof(struct B) == 0x10000000, "");

// Wrong cases
struct B1 {
    _Alignas(0x20000000) char ch;
};
_Static_assert(sizeof(struct B1) == 0x1, "");

struct B2 {
    _Alignas(0x40000000) char ch;
};
_Static_assert(sizeof(struct B2) == 0x1, "");

struct B3 {
    _Alignas(0x80000000) char ch;
};
_Static_assert(sizeof(struct B3) == 0x1, "");

struct B4 {
    _Alignas(0x100000000) char ch;
};
_Static_assert(sizeof(struct B4) == 0x1, "");
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to