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

            Bug ID: 114756
           Summary: [14] RISC-V rv32imc miscompile with -fdata-sections
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick at rivosinc dot com
  Target Milestone: ---

Testcase:
#pragma pack(push)
#pragma pack(1)
struct a
{
        long long b;
        char c;
        long long d;
        int e;
        int f;
        long long g;
        char h;
};
#pragma pack(pop)
struct i
{
        unsigned c;
        unsigned d;
        unsigned h;
};
int j;
int k;
short l;
int m;
static struct a n = {0xBBCB58D824AE4D28};
static long long *s = &n.b;
struct a o = {1};
struct a p[32] = {{4}};
struct a aa = {6};
struct i ab[3] = {{108}};
int ac[8] = {4};
short ad;
short *ae[] = {&ad, &ad, &ad, &ad, &ad, &ad};
struct a q = {9};
int *r[24] = {&m};
struct a t = {4073709551615};
int *u[3] = {&j};
short v[64] = {6};
struct a x = {4073709551611};
struct a y = {4073709551607};
char z[60] = {4};
struct i af = {5};
struct i ag = {11};
short *ai[] = {&l, &l, &l, &l, &l};
int *aj[32] = {&k};
struct a ak = {4073709551615};
struct a al = {1};
struct a am = {12};
struct i an = {5};
struct a ao[216] = {{4073709551615}};
struct i ap = {3};
long long aq[] = {6, 0, 6, 6, 0, 6, 6};
struct a ar = {4};
struct a as[10] = {{13}};
struct a at = {4073709551615};
struct a au = {3};
struct a av = {6};
struct a aw = {7};
struct i ax = {4};
struct i ay = {4};
struct i az = {4};
struct i ba = {1};
struct a bb[8] = {{4073709551615}};
int main() { __builtin_printf("%llX\n", *s); }

Commands:
> /scratch/tc-testing/tc-apr-9/build-rv32gcv/bin/riscv64-unknown-linux-gnu-gcc 
> -O1 -mabi=ilp32 -march=rv32imc -fdata-sections red.c -o user-config.out 
> -fsigned-char -fno-strict-aliasing -static
> /scratch/tc-testing/tc-apr-15/build-rv64gcv/bin/qemu-riscv32 user-config.out
24AE4D28

without -fdata-sections
> /scratch/tc-testing/tc-apr-9/build-rv32gcv/bin/riscv64-unknown-linux-gnu-gcc 
> -O1 -mabi=ilp32 -march=rv32imc red.c -o user-config.out -fsigned-char 
> -fno-strict-aliasing -static
> /scratch/tc-testing/tc-apr-15/build-rv64gcv/bin/qemu-riscv32 user-config.out
BBCB58D824AE4D28

Found via fuzzer.

Reply via email to