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

            Bug ID: 127518
           Summary: [14 Regression] -Wmaybe-uninitialized false positive
                    with inlined copy_to_user
           Product: gcc
           Version: 14.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lyican53 at sjtu dot edu.cn
  Target Milestone: ---

We found this bug through a workaround in the Linux kernel. Kernel commit
af7e23c6 moves two assignments a few lines earlier for no other reason than to
silence this GCC warning. The kernel commit message itself calls it a
"false-positive ... from gcc".

The warning may be wrong: the variable input_cert_chain_address is always
assigned before it is used. GCC thinks it might be uninitialized only because
the use sits inside copy_to_user(), which is inlined from a header file.

The exact warning:

  In function 'copy_to_user',
      inlined from 'sev_ioctl_do_pdh_export' at sev-dev.c:2036:7,
      inlined from 'sev_ioctl' at sev-dev.c:2249:9:
  include/linux/uaccess.h:225:16: warning: 'input_cert_chain_address'
  may be used uninitialized [-Wmaybe-uninitialized]

To reproduce it, we took the kernel source from just before the workaround,
preprocessed sev-dev.c with its normal build setup, and compiled it. The
warning appears. When we apply the kernel's workaround to the same file, the
warning disappears with the same command. Both files are attached
(testcase_before.i and testcase_after.i -- they differ only by that one
change).

Reproduce (x86_64):

  gcc -O2 -Wall -Wextra -c testcase_before.i -o /dev/null

  (-Wextra is needed to enable the warning)

Versions tested:

  11.3.0  warning     12.5.0  warning     13.4.0  no warning
  14.4.0  warning     15.3.0  no warning

So the warning exists in 11/12 and 14, is gone in 13, comes back in 14, and is
gone again in 15.

Kernel commit: https://github.com/torvalds/linux/commit/af7e23c6

Reply via email to