Bug 1669489 - GCC 9 introduces false positive in -Wjump-misses-init
Summary: GCC 9 introduces false positive in -Wjump-misses-init
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 31
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2019-01-25 13:03 UTC by Daniel Berrangé
Modified: 2019-08-13 19:13 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed:

Attachments (Terms of Use)

System ID Priority Status Summary Last Updated
GNU Compiler Collection 89061 None None None 2019-02-25 15:04:38 UTC

Description Daniel Berrangé 2019-01-25 13:03:36 UTC
Description of problem:
There is a regression caused by GCC 9 affecting libvirt builds in F30.

The following demo program illustrates the problem in a self-contained format

$ cat demo.c

#include <stdlib.h>

struct demo {
    const char *cmd;

int main(void)
  struct demo demo = {0};

  if ((demo.cmd = getenv("FOO")) == NULL) {
    goto cleanup;

  demo = (struct demo) { .cmd = "foo" };

  return 0;

Results in new false positive warnings with GCC 9

$ gcc -Wjump-misses-init  -o demo demo.c
demo.c: In function ‘main’:
demo.c:13:5: warning: jump skips variable initialization [-Wjump-misses-init]
   13 |     goto cleanup;
      |     ^~~~
demo.c:18:2: note: label ‘cleanup’ defined here
   18 |  cleanup:
      |  ^~~~~~~
demo.c:16:24: note: ‘({anonymous})’ declared here
   16 |   demo = (struct demo) { .cmd = "foo" };
      |                        ^

'demo' is fully initialized at every step of the program, even taking into account the jumps.

It appears to be triggered by the full struct assignment.  If I change

  demo = (struct demo) { .cmd = "foo" };


  demo.cmd = "foo";

then it no longer triggers the false positive warning. 

Version-Release number of selected component (if applicable):

Comment 1 Daniel Berrangé 2019-01-31 10:15:30 UTC
FYI, I built myself a custom GCC rpm in rawhide using the patch referenced on the upstream commit, and confirmed that it fixes the warnings we saw with libvirt.

Comment 2 Ben Cotton 2019-08-13 17:04:16 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to '31'.

Comment 3 Ben Cotton 2019-08-13 19:13:35 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to 31.

Note You need to log in before you can comment on or make changes to this bug.