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

            Bug ID: 118821
           Summary: false warning: '__atomic_store_8' writing 8 bytes into
                    a region of size 0 overflows the destination
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikpelinux at gmail dot com
  Target Milestone: ---

Created attachment 60451
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60451&action=edit
test case

The following (also attached) is derived from a module in the Erlang VM, which
triggered an IMO unwarranted warning on aarch64-linux-gnu:

> cat dist.c
typedef struct {
    volatile long value;
} ethr_atomic_t;

static __inline__ void ethr_atomic_set_mb (ethr_atomic_t *var, long val)
{
    // replace this store with "var->value = val;" and the warning goes away
    __atomic_store_n (&var->value, val, 3);
}

struct dist_entry {
    struct dist_entry *next;
    ethr_atomic_t dist_cmd_scheduled;
};

struct erts_port_sd {
    struct dist_entry *data;
};

struct erl_drv_port {
    struct erts_port_sd *psd;
};

static struct dist_entry *
erts_prtsd_get (struct erl_drv_port *prt)
{
    struct erts_port_sd *psd = prt->psd;

    if (!psd)
        return 0;

    return psd->data;
}

int
erts_dist_command (struct erl_drv_port *prt, int reds)
{
    struct dist_entry *dep = erts_prtsd_get (prt);

    ethr_atomic_set_mb (&dep->dist_cmd_scheduled, 0);
    dep->next = 0; // remove this store and the warning goes away
    return 0;
}
> gcc -O2 -Wall -c dist.c
In function 'ethr_atomic_set_mb',
    inlined from 'erts_dist_command' at dist.c:40:5:
dist.c:8:5: warning: '__atomic_store_8' writing 8 bytes into a region of size 0
overflows the destination [-Wstringop-overflow=]
    8 |     __atomic_store_n (&var->value, val, 3);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'erts_dist_command':
cc1: note: destination object is likely at address zero

The original source, the Erlang VM version 27.2.2, only triggered on
aarch64-linux-gnu, but this reduced test case also triggers on
x86_64-linux-gnu.

gcc-10 and 11 do not produce this warning, but gcc-12/13/14/15 do.

I've marked two lines with source changes that don't change the semantics of
the code, but either of those two changes is enough to silence the warning.

Reply via email to