Skip to content

[clang][AVR] Alignment discrepancies between clang and avr-gcc for short, long long, and double #102172

Closed
@alexrp

Description

@alexrp

Not sure if this is intentional on the clang side, but I thought I'd at least open an issue to find out. 🙂

avr-gcc --version
avr-gcc (GCC) 5.4.0clang --version
clang version 18.1.8avr-gcc -fsyntax-only avr.ccat avr.c
_Static_assert(sizeof(char) == 1, "sizeof(char) == 1");
_Static_assert(_Alignof(char) == 1, "_Alignof(char) == 1");
_Static_assert(__alignof(char) == 1, "__alignof(char) == 1");

_Static_assert(sizeof(short) == 2, "sizeof(short) == 2");
_Static_assert(_Alignof(short) == 1, "_Alignof(short) == 1");
_Static_assert(__alignof(short) == 1, "__alignof(short) == 1");

_Static_assert(sizeof(unsigned short) == 2, "sizeof(unsigned short) == 2");
_Static_assert(_Alignof(unsigned short) == 1, "_Alignof(unsigned short) == 1");
_Static_assert(__alignof(unsigned short) == 1, "__alignof(unsigned short) == 1");

_Static_assert(sizeof(int) == 2, "sizeof(int) == 2");
_Static_assert(_Alignof(int) == 1, "_Alignof(int) == 1");
_Static_assert(__alignof(int) == 1, "__alignof(int) == 1");

_Static_assert(sizeof(unsigned int) == 2, "sizeof(unsigned int) == 2");
_Static_assert(_Alignof(unsigned int) == 1, "_Alignof(unsigned int) == 1");
_Static_assert(__alignof(unsigned int) == 1, "__alignof(unsigned int) == 1");

_Static_assert(sizeof(long) == 4, "sizeof(long) == 4");
_Static_assert(_Alignof(long) == 1, "_Alignof(long) == 1");
_Static_assert(__alignof(long) == 1, "__alignof(long) == 1");

_Static_assert(sizeof(unsigned long) == 4, "sizeof(unsigned long) == 4");
_Static_assert(_Alignof(unsigned long) == 1, "_Alignof(unsigned long) == 1");
_Static_assert(__alignof(unsigned long) == 1, "__alignof(unsigned long) == 1");

_Static_assert(sizeof(long long) == 8, "sizeof(long long) == 8");
_Static_assert(_Alignof(long long) == 1, "_Alignof(long long) == 1");
_Static_assert(__alignof(long long) == 1, "__alignof(long long) == 1");

_Static_assert(sizeof(unsigned long long) == 8, "sizeof(unsigned long long) == 8");
_Static_assert(_Alignof(unsigned long long) == 1, "_Alignof(unsigned long long) == 1");
_Static_assert(__alignof(unsigned long long) == 1, "__alignof(unsigned long long) == 1");

_Static_assert(sizeof(float) == 4, "sizeof(float) == 4");
_Static_assert(_Alignof(float) == 1, "_Alignof(float) == 1");
_Static_assert(__alignof(float) == 1, "__alignof(float) == 1");

_Static_assert(sizeof(double) == 4, "sizeof(double) == 4");
_Static_assert(_Alignof(double) == 1, "_Alignof(double) == 1");
_Static_assert(__alignof(double) == 1, "__alignof(double) == 1");

_Static_assert(sizeof(long double) == 4, "sizeof(long double) == 4");
_Static_assert(_Alignof(long double) == 1, "_Alignof(long double) == 1");
_Static_assert(__alignof(long double) == 1, "__alignof(long double) == 1");clang --target=avr -fsyntax-only avr.c
clang: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=<mcu name> [-Wavr-rtlib-linking-quirks]
avr.c:6:16: error: static assertion failed due to requirement '_Alignof(short) == 1': _Alignof(short) == 1
    6 | _Static_assert(_Alignof(short) == 1, "_Alignof(short) == 1");
      |                ^~~~~~~~~~~~~~~~~~~~
avr.c:6:32: note: expression evaluates to '2 == 1'
    6 | _Static_assert(_Alignof(short) == 1, "_Alignof(short) == 1");
      |                ~~~~~~~~~~~~~~~~^~~~
avr.c:7:16: error: static assertion failed due to requirement '__alignof(short) == 1': __alignof(short) == 1
    7 | _Static_assert(__alignof(short) == 1, "__alignof(short) == 1");
      |                ^~~~~~~~~~~~~~~~~~~~~
avr.c:7:33: note: expression evaluates to '2 == 1'
    7 | _Static_assert(__alignof(short) == 1, "__alignof(short) == 1");
      |                ~~~~~~~~~~~~~~~~~^~~~
avr.c:10:16: error: static assertion failed due to requirement '_Alignof(unsigned short) == 1': _Alignof(unsigned short) == 1
   10 | _Static_assert(_Alignof(unsigned short) == 1, "_Alignof(unsigned short) == 1");
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
avr.c:10:41: note: expression evaluates to '2 == 1'
   10 | _Static_assert(_Alignof(unsigned short) == 1, "_Alignof(unsigned short) == 1");
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
avr.c:11:16: error: static assertion failed due to requirement '__alignof(unsigned short) == 1': __alignof(unsigned short) == 1
   11 | _Static_assert(__alignof(unsigned short) == 1, "__alignof(unsigned short) == 1");
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
avr.c:11:42: note: expression evaluates to '2 == 1'
   11 | _Static_assert(__alignof(unsigned short) == 1, "__alignof(unsigned short) == 1");
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
avr.c:31:16: error: static assertion failed due to requirement '__alignof(long long) == 1': __alignof(long long) == 1
   31 | _Static_assert(__alignof(long long) == 1, "__alignof(long long) == 1");
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~
avr.c:31:37: note: expression evaluates to '8 == 1'
   31 | _Static_assert(__alignof(long long) == 1, "__alignof(long long) == 1");
      |                ~~~~~~~~~~~~~~~~~~~~~^~~~
avr.c:35:16: error: static assertion failed due to requirement '__alignof(unsigned long long) == 1': __alignof(unsigned long long) == 1
   35 | _Static_assert(__alignof(unsigned long long) == 1, "__alignof(unsigned long long) == 1");
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
avr.c:35:46: note: expression evaluates to '8 == 1'
   35 | _Static_assert(__alignof(unsigned long long) == 1, "__alignof(unsigned long long) == 1");
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
avr.c:43:16: error: static assertion failed due to requirement '__alignof(double) == 1': __alignof(double) == 1
   43 | _Static_assert(__alignof(double) == 1, "__alignof(double) == 1");
      |                ^~~~~~~~~~~~~~~~~~~~~~
avr.c:43:34: note: expression evaluates to '4 == 1'
   43 | _Static_assert(__alignof(double) == 1, "__alignof(double) == 1");
      |                ~~~~~~~~~~~~~~~~~~^~~~
7 errors generated.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions