gcc-12: disable '-Wdangling-pointer' warning for now 94/294194/1
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 9 Jun 2022 16:41:42 +0000 (09:41 -0700)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 14 Jun 2023 05:40:32 +0000 (14:40 +0900)
commit76600afb094c2994e7d28a9f96c17df9d4fa4071
tree99a4aa7754e9c22950170b01e9fe6cb958abdd8b
parent42adb111d2ca6d285e10d7790169aa85257411e7
gcc-12: disable '-Wdangling-pointer' warning for now

While the concept of checking for dangling pointers to local variables
at function exit is really interesting, the gcc-12 implementation is not
compatible with reality, and results in false positives.

For example, gcc sees us putting things on a local list head allocated
on the stack, which involves exactly those kinds of pointers to the
local stack entry:

  In function ‘__list_add’,
      inlined from ‘list_add_tail’ at include/linux/list.h:102:2,
      inlined from ‘rebuild_snap_realms’ at fs/ceph/snap.c:434:2:
  include/linux/list.h:74:19: warning: storing the address of local variable ‘realm_queue’ in ‘*&realm_27(D)->rebuild_item.prev’ [-Wdangling-pointer=]
     74 |         new->prev = prev;
        |         ~~~~~~~~~~^~~~~~

But then gcc - understandably - doesn't really understand the big
picture how the doubly linked list works, so doesn't see how we then end
up emptying said list head in a loop and the pointer we added has been
removed.

Gcc also complains about us (intentionally) using this as a way to store
a kind of fake stack trace, eg

  drivers/acpi/acpica/utdebug.c:40:38: warning: storing the address of local variable ‘current_sp’ in ‘acpi_gbl_entry_stack_pointer’ [-Wdangling-pointer=]
     40 |         acpi_gbl_entry_stack_pointer = &current_sp;
        |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~

which is entirely reasonable from a compiler standpoint, and we may want
to change those kinds of patterns, but not not.

So this is one of those "it would be lovely if the compiler were to
complain about us leaving dangling pointers to the stack", but not this
way.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[sw0312.kim: backport upstream commit 49beadbd47c2 to resolve gcc-13 build issue]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I1c45cf23149d2bab3cf8104013bd890302a567f6
Makefile