[Bug tree-optimization/100845] New: [11/12 Regression] False positive for -Werror=maybe-uninitialized since r11-959-gb825a22890740f34

marxin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jun 1 07:02:39 GMT 2021


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

            Bug ID: 100845
           Summary: [11/12 Regression] False positive for
                    -Werror=maybe-uninitialized since
                    r11-959-gb825a22890740f34
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: msebor at gcc dot gnu.org
  Target Milestone: ---

Since the revision, the following simple test-case is affected:

$ cat snippet.c
#include <stdlib.h>

int xor_hash(const char* mem, const size_t n) {
        int hash = 0;
        for(size_t i=0;i<n;i++)
                hash ^= mem[i];
        return hash>=0?hash:-hash;
}

int uninitialized(size_t size) {
        void *mem = malloc(size);
        if(mem == NULL)
                return -1;

        int ret = xor_hash(mem, size);
        free(mem);
        return ret;
}

$ gcc -Werror=all snippet.c -c
snippet.c: In function ‘uninitialized’:
snippet.c:15:19: error: ‘mem’ may be used uninitialized
[-Werror=maybe-uninitialized]
   15 |         int ret = xor_hash(mem, size);
      |                   ^~~~~~~~~~~~~~~~~~~
snippet.c:3:5: note: by argument 1 of type ‘const char *’ to ‘xor_hash’
declared here
    3 | int xor_hash(const char* mem, const size_t n) {
      |     ^~~~~~~~
cc1: some warnings being treated as errors

While using -O2 is fine.


More information about the Gcc-bugs mailing list