llvm / llvm/llvm-project

[SystemZ] constexpr variable promoted to global does not minimum alignment

Open
#224,008 4 comments 0 reactions 0 assignees View on GitHub
backend:SystemZ clang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```cpp
char test(unsigned n) {
constexpr char digits[] = "foobar";
return digits[n];
}
```
`clang --target=s390x-unknown-linux-gnu -S -emit-llvm -o - -O2 test.cpp` produces:
```llvm
@__const._Z4testj.digits = private unnamed_addr constant [7 x i8] c"foobar\00", align 1
```
Because it does not have the minimum global alignment of 2, it gets lowered to this GOT reference:
```
lgrl %r1, .L__const._Z4testj.digits@GOT
```

This is probably not supposed to happen? I expect either Clang should emit this with align 2, or the backend should raise the alignment (it has private linkage), or both.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided clang --target=s390x-unknown-linux-gnu -S -emit-llvm -O2 command and inspect the emitted global alignment and subsequent SystemZ GOT lowering. Trace whether Clang's constexpr promotion or the backend handles alignment, then verify that the private constant receives the required minimum alignment or avoids the unnecessary GOT reference.

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
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.