llvm / llvm/llvm-project

[clang] apcs-gnu struct alignment incompatible with gcc

Open
#209,125 0 comments 0 reactions 0 assignees View on GitHub
clang diverges-from:gcc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following test case,
```c
#include

struct S1
{
uint32_t a:8;
uint32_t b:8;
uint32_t c:8;
uint32_t d:8;
uint16_t e:5;
uint16_t f:3;
uint16_t l;
};

struct S2
{
uint16_t e:5;
uint16_t f:3;
};

int foo()
{
return _Alignof(struct S1);
}

int bar()
{
return _Alignof(struct S2);
}
```
Results in an **alignment of 2 and 1** respectively for structs `S1` and `S2` with [clang](https://godbolt.org/z/6P45G339d) while with [gcc](https://godbolt.org/z/PK6MT7fa4) the alignment is **4 for both**.

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided C test case with Clang using the apcs-gnu target and compare its _Alignof results with GCC, using the linked Godbolt examples as a baseline. The work is done when Clang produces alignment 4 for both S1 and S2, matching GCC, with regression coverage for the discrepancy.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.