xcoffread.c: Fix -Werror=dangling-pointer= issue with main_subfile.
authorMark Wielaard <mark@klomp.org>
Sat, 29 Apr 2023 20:46:11 +0000 (22:46 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 2 May 2023 15:43:31 +0000 (17:43 +0200)
commit433e8364fedffb394d5cac29691f2bb0480369a4
tree39e2e80485e229116c36f29611f5a144907a4101
parent69330acb2014b3b520206f53a244815226897f9b
xcoffread.c: Fix -Werror=dangling-pointer= issue with main_subfile.

GCC 13 points out that main_subfile has local function scope, but a
pointer to it is assigned to the global inclTable array subfile
element field:

In function ‘void process_linenos(CORE_ADDR, CORE_ADDR)’,
    inlined from ‘void aix_process_linenos(objfile*)’ at xcoffread.c:727:19,
    inlined from ‘void aix_process_linenos(objfile*)’ at xcoffread.c:720:1:
xcoffread.c:629:37: error: storing the address of local variable ‘main_subfile’ in ‘*inclTable.19_45 + _28._inclTable::subfile’ [-Werror=dangling-pointer=]
  629 |               inclTable[ii].subfile = &main_subfile;
      |               ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
xcoffread.c: In function ‘void aix_process_linenos(objfile*)’:
xcoffread.c:579:18: note: ‘main_subfile’ declared here
  579 |   struct subfile main_subfile;
      |                  ^~~~~~~~~~~~
xcoffread.c:496:19: note: ‘inclTable’ declared here
  496 | static InclTable *inclTable;    /* global include table */
      |                   ^~~~~~~~~

Fix this by making main_subfile file static. And allocate and
deallocated together with inclTable in allocate_include_entry and
xcoff_symfile_finish. Adjust the use of main_subfile in
process_linenos to take a pointer to the subfile.
gdb/xcoffread.c