Bug 99340 - -Werror=maybe-uninitialized warning with -fPIE, but not -fPIC
Summary: -Werror=maybe-uninitialized warning with -fPIE, but not -fPIC
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2021-03-02 12:04 UTC by Matthias Klose
Modified: 2021-04-12 19:28 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.2.0
Known to fail: 10.2.1, 11.0
Last reconfirmed: 2021-03-02 00:00:00


Attachments
preprocessed source (173.48 KB, application/x-xz)
2021-03-02 12:46 UTC, Matthias Klose
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2021-03-02 12:04:19 UTC
seen building the gsequencer package.
the warning was not emitted with gcc-10 branch 20210110, but is emitted with 20210228, also emitted with trunk 20210220.

$ cat ags_midi_buffer_util.i
long ags_midi_buffer_util_seek_message_delta_time;
int ags_midi_buffer_util_seek_message_i;
int ags_midi_buffer_util_get_varlength() { return 0; }
char ags_midi_buffer_util_seek_message() {
  long current_delta_time;
  for (; ags_midi_buffer_util_seek_message_i;
       ags_midi_buffer_util_seek_message_i++) {
    ags_midi_buffer_util_get_varlength(&current_delta_time);
    ags_midi_buffer_util_seek_message_delta_time = current_delta_time;
  }
  return 0;
}

$ gcc -std=gnu99 -Wall -Werror=maybe-uninitialized -fstack-protector-strong -fPIE -O1 -c ags_midi_buffer_util.i
ags_midi_buffer_util.i: In function 'ags_midi_buffer_util_seek_message':
ags_midi_buffer_util.i:5:8: error: 'current_delta_time' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    5 |   long current_delta_time;
      |        ^~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Comment 1 Martin Liška 2021-03-02 12:10:24 UTC
I see the warning (with -fPIE) for all releases I have (4.8.0+).
But yes, -fPIC does not report the warning.
Comment 2 Richard Biener 2021-03-02 12:36:26 UTC
PIC allows interposing ags_midi_buffer_util_get_varlength and thus possibly
initializing the argument.  PIE does not allow this so we see it is not
initialized.

I suppose the change on the branch is for some unreduced testcase where
different optimization might trigger the new warning (correctly I think).
Comment 3 Matthias Klose 2021-03-02 12:46:16 UTC
Created attachment 50284 [details]
preprocessed source

original test case before reducing

gcc -std=gnu99 -Werror=uninitialized -Werror=maybe-uninitialized -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wformat -Wno-pointer-sign -Werror=format-security -fstack-protector-strong -fPIC -O2 -c ags_midi_buffer_util_orig.i
Comment 4 Martin Liška 2021-03-02 12:51:49 UTC
(In reply to Matthias Klose from comment #3)
> Created attachment 50284 [details]
> preprocessed source
> 
> original test case before reducing
> 
> gcc -std=gnu99 -Werror=uninitialized -Werror=maybe-uninitialized -Wall
> -Wno-unused-variable -Wno-unused-but-set-variable -Wformat -Wno-pointer-sign
> -Werror=format-security -fstack-protector-strong -fPIC -O2 -c
> ags_midi_buffer_util_orig.i

Using this with -fPIE reports the warning only on gcc-10 branch. All other is fine.
Comment 5 Martin Liška 2021-03-02 13:05:43 UTC
Started on gcc-10 branch with g:eddcb627ccfbd97e025cf366cc3f3bad76211785.
Anyway, the warning contains quite some false positives..
Comment 6 Richard Biener 2021-03-02 13:45:26 UTC
GCC 9 warns as well.  I think this was a false negative which is now fixed.

Note GCC 10.1.0 and GCC 10.2.0 warn for me as well, so something must have regressed this between 10.2.0 and g:eddcb627ccfbd97e025cf366

I'm inclined to mark as INVALID.
Comment 7 Martin Sebor 2021-04-12 19:28:16 UTC
The IL with -fPIC shows a call to ags_midi_buffer_util_get_varlength() while the IL with -fPIE has the call expanded inline, which is what less the warning see current_delta_time is not initialized.   With that, resolving as invalid per c6.