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

            Bug ID: 120872
           Summary: Dovecot test-json-istream test miscompiled with
                    -ftrivial-auto-var-init={zero,pattern}
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: false-positive, wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
  Target Milestone: ---

This comes from Dovecot's testsuite (test-json-istream.c) where it's
miscompiled with -ftrivial-auto-var-init={zero,pattern}. It also shows up as
-Wmaybe-uninitialized with those options.

```
enum { JSON_TYPE_NULL, JSON_TYPE_TEXT } type;
char *data_val;

void frobnicate();

__attribute__((pure)) char *json_node_get_data(long *size_r) {
  *size_r = 0;
  switch (type) {
  case JSON_TYPE_TEXT:
    break;
  case JSON_TYPE_NULL:
    return "";
  default:
    frobnicate();
  }
  return 0;
}

void test_json_istream_read_string() {
  long size_val;

  frobnicate();

  data_val = json_node_get_data(&size_val);
  if (__builtin_memcmp(data_val, 0, size_val))
    frobnicate();
}
```

```
$ gcc test-json-istream.i -O2 -ftrivial-auto-var-init=zero -c
-Werror=uninitialized
test-json-istream.i: In function ‘test_json_istream_read_string’:
test-json-istream.i:25:7: error: ‘size_val’ may be used uninitialized
[-Werror=maybe-uninitialized]
   25 |   if (__builtin_memcmp(data_val, 0, size_val))
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test-json-istream.i:20:8: note: ‘size_val’ was declared here
   20 |   long size_val;
      |        ^~~~~~~~
cc1: some warnings being treated as errors
```

Reply via email to