From 156c8da33c53f680f7455f53e9e7d6003427ca87 Mon Sep 17 00:00:00 2001 From: Pavel Tikhomirov Date: Tue, 7 Mar 2023 15:33:59 +0800 Subject: [PATCH] make: disable '-Wdangling-pointer' warning with gcc 12 The patch is similar to what has been done in linux kernel, as this warning effectively prevents us from adding list elements to local list head. See https://github.com/torvalds/linux/commit/49beadbd47c2 Else we have: CC criu/mount.o In file included from criu/include/cr_options.h:7, from criu/mount.c:13: In function '__list_add', inlined from 'list_add' at include/common/list.h:41:2, inlined from 'mnt_tree_for_each' at criu/mount.c:1977:2: include/common/list.h:35:19: error: storing the address of local variable 'postpone' in '((struct list_head *)((char *)start + 8))[24].prev' [-Werror=dangling-pointer=] 35 | new->prev = prev; | ~~~~~~~~~~^~~~~~ criu/mount.c: In function 'mnt_tree_for_each': criu/mount.c:1972:19: note: 'postpone' declared here 1972 | LIST_HEAD(postpone); | ^~~~~~~~ Signed-off-by: Pavel Tikhomirov --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 24318d692..7d0f2350a 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,15 @@ DEFINES += -D_GNU_SOURCE WARNINGS := -Wall -Wformat-security -Wdeclaration-after-statement -Wstrict-prototypes +# -Wdangling-pointer results in false warning when we add a list element to +# local list head variable. It is false positive because before leaving the +# function we always check that local list head variable is empty, thus +# insuring that pointer to it is not dangling anywhere, but gcc can't +# understand it. +# Note: There is similar problem with kernel list, where this warning is also +# disabled: https://github.com/torvalds/linux/commit/49beadbd47c2 +WARNINGS += -Wno-dangling-pointer -Wno-unknown-warning-option + CFLAGS-GCOV := --coverage -fno-exceptions -fno-inline -fprofile-update=atomic export CFLAGS-GCOV