Bug 2056613

Summary: gcc-12.0.1-0.8.fc36 gives wrong -Wdangling-pointer warnings related to `for(;;)`
Product: [Fedora] Fedora Reporter: Thomas Haller <thaller>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 36CC: aoliva, dmalcolm, fweimer, jakub, jwakely, law, mpolacek, msebor, nickc, sipoyare
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: gcc-12.0.1-0.12.fc36 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-03-09 20:07:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Thomas Haller 2022-02-21 15:23:22 UTC
gcc-12.0.1-0.8.fc36 gives wrong dangling-pointer warnings (with unreachable code `for(;;)`).


This can be seen when building NetworkManager:
Run `podman run -it --privileged fedora:36`


Then:

```
dnf upgrade -y

dnf install git -y

git clone https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git/
cd NetworkManager

git checkout -B test 47ff99515f0ecbc791851f3c1a1c61fb7efc234c

./contrib/fedora/REQUIRED_PACKAGES

CFLAGS='-O2' ./autogen.sh

make src/libnm-glib-aux/libnm_glib_aux_la-nm-shared-utils.lo
```




Compiler failure:
```
In file included from /usr/include/glib-2.0/glib.h:62,
                 from ./src/libnm-glib-aux/nm-default-glib.h:18,
                 from ./src/libnm-glib-aux/nm-default-glib-i18n-lib.h:13,
                 from src/libnm-glib-aux/nm-shared-utils.c:6:
src/libnm-glib-aux/nm-shared-utils.c: In function ‘nm_utils_parse_inaddr_bin_full’:
src/libnm-glib-aux/nm-shared-utils.c:1145:26: error: dangling pointer to ‘error’ may be used [-Werror=dangling-pointer=]
 1145 |                     error->message);
      |                          ^~
/usr/include/glib-2.0/glib/gmessages.h:343:32: note: in definition of macro ‘g_error’
  343 |                                __VA_ARGS__);         \
      |                                ^~~~~~~~~~~
src/libnm-glib-aux/nm-shared-utils.c:1133:31: note: ‘error’ declared here
 1133 |         gs_free_error GError *error = NULL;
      |                               ^~~~~
/usr/include/glib-2.0/glib/gmessages.h:341:25: error: dangling pointer to ‘addrbin’ may be used [-Werror=dangling-pointer=]
  341 |                         g_log (G_LOG_DOMAIN,         \
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  342 |                                G_LOG_LEVEL_ERROR,    \
      |                                ~~~~~~~~~~~~~~~~~~~~~~~
  343 |                                __VA_ARGS__);         \
      |                                ~~~~~~~~~~~~
src/libnm-glib-aux/nm-shared-utils.c:1141:13: note: in expansion of macro ‘g_error’
 1141 |             g_error("unexpected assertion failure: could parse \"%s\" as %s, but not accepted by "
      |             ^~~~~~~
src/libnm-glib-aux/nm-shared-utils.c:1112:14: note: ‘addrbin’ declared here
 1112 |     NMIPAddr addrbin;
      |              ^~~~~~~
cc1: all warnings being treated as errors
```

which happens here: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/47ff99515f0ecbc791851f3c1a1c61fb7efc234c/src/libnm-glib-aux/nm-shared-utils.c#L1141



There are several other failures. Just type `make` in above reproducer.



They are related to glib's `g_error()` macro, which is defined here: https://gitlab.gnome.org/GNOME/glib/-/blob/60e8b48be9f2c1cc3f8212ebfaee58f0750a2754/glib/gmessages.h#L344

```
#define g_error(...)  G_STMT_START {                 \
                        g_log (G_LOG_DOMAIN,         \
                               G_LOG_LEVEL_ERROR,    \
                               __VA_ARGS__);         \
                        for (;;) ;                   \
                      } G_STMT_END
```

The `for(;;)` trips gcc up.

Comment 1 Thomas Haller 2022-02-21 21:13:02 UTC
it seems easy to reproduce. Just build upstream glib.

Most calls of `g_error()` don't trigger the problem, but many do.

Comment 2 Martin Sebor 2022-02-24 00:32:45 UTC
We need either a test case or a preprocessing translation unit and the full GCC command line to reproduce the problem.   You can obtain a preprocessing translation unit by compiling the affected source file with the -E option and saving the output to a file.  Please attach this file to the report.

Comment 3 Jakub Jelinek 2022-03-09 20:07:24 UTC
gcc-12.0.1-0.12.fc37 in rawhide should fix this, f36 version still building...

Comment 4 Fedora Update System 2022-03-10 08:31:09 UTC
FEDORA-2022-9fb66de66d has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2022-9fb66de66d

Comment 5 Fedora Update System 2022-03-11 19:25:15 UTC
FEDORA-2022-42ea499a7d has been pushed to the Fedora 36 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2022-42ea499a7d`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2022-42ea499a7d

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 6 Fedora Update System 2022-03-17 17:10:13 UTC
FEDORA-2022-42ea499a7d has been pushed to the Fedora 36 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2022-42ea499a7d`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2022-42ea499a7d

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 7 Fedora Update System 2022-03-17 18:37:25 UTC
FEDORA-2022-42ea499a7d has been pushed to the Fedora 36 stable repository.
If problem still persists, please make note of it in this bug report.