llvm / llvm/llvm-project

Members are left unintialized in very large class

Open
#219,366 8 comments 0 reactions 0 assignees View on GitHub
clang:frontend crash-on-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Came across this issue in generated code I work with. When there is a very, very large number of member variables, newer clangs seem to not initialize all members in the class. Built with `-std=c++23 -Wall -Werror`.

Clang 17, 19 init all members. Clang >=20 seem to have this issue.

E.g.

https://godbolt.org/z/s9YGK5rTr

```cpp
#include

struct W {
unsigned m;
};

#define M1(x) W x{1};
#define M4(p) M1(p##0) M1(p##1) M1(p##2) M1(p##3)
#define M16(p) M4(p##0) M4(p##1) M4(p##2) M4(p##3)
#define M64(p) M16(p##0) M16(p##1) M16(p##2) M16(p##3)
#define M256(p) M64(p##0) M64(p##1) M64(p##2) M64(p##3)
#define M1K(p) M256(p##0) M256(p##1) M256(p##2) M256(p##3)
#define M4K(p) M1K(p##0) M1K(p##1) M1K(p##2) M1K(p##3)
#define M16K(p) M4K(p##0) M4K(p##1) M4K(p##2) M4K(p##3)
#define M64K(p) M16K(p##0) M16K(p##1) M16K(p##2) M16K(p##3)

class Big {
public:
M64K(a)
unsigned value;

explicit Big(unsigned initialValue);
};

Big::Big(unsigned initialValue) : value{initialValue} {}

int main()
{
Big big{0x1234};
std::printf("previous member = %#x\n", big.a33333333.m); // All these members should be 1, right?
std::printf("value = %#x\n", big.value); // and value should be 0x1234?

return big.value == 0x1234 ? 0 : 1;
}
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided Godbolt reproducer with -std=c++23 -Wall -Werror across Clang 17, 19, and 20 or newer. Compare whether the large class members remain initialized and whether value remains 0x1234; the issue is done when the newer Clang behavior matches the expected output without regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.