https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127457

            Bug ID: 127457
           Summary: Wrong wide string literal alignment
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lnicoara at thinkoid dot org
  Target Milestone: ---

GCC merges a wide string literal with an earlier narrow string literal
having the same byte representation, but does not preserve the alignment
required.

Test case:

❯ gcc --version | head -n 1; cat t.c; gcc -S t.c && cat t.s | head -n 10; gcc
-O0 t.c && ./a.out
gcc (GCC) 16.2.1 20260810
#include <stdio.h>
#include <stdint.h>
#include <wchar.h>

void f(const void*);

int main(void) {
        f("x");
        f("\0\0\0");
        f(L"");
}

void f(const void* p)
{
        printf ("alignment=%zu remainder=%zu\n",
                alignof(wchar_t), (size_t)((uintptr_t)p % alignof(wchar_t)));
}
        .file   "t.c"
        .text
        .section        .rodata
.LC0:
        .string "x"
.LC1:
        .base64 "AAAAAA=="
        .text
        .globl  main
        .type   main, @function
alignment=4 remainder=0
alignment=4 remainder=2
alignment=4 remainder=2

Reply via email to