Bug 1018422 - Spurious(?) "may be used uninitialized" warning -- only with -Os
Spurious(?) "may be used uninitialized" warning -- only with -Os
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
19
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-11 19:33 EDT by Ian Pilcher
Modified: 2013-10-14 17:29 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-10-14 17:29:31 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
raid.c (26.30 KB, text/plain)
2013-10-11 19:33 EDT, Ian Pilcher
no flags Details
freecusd.h (4.21 KB, text/plain)
2013-10-11 19:34 EDT, Ian Pilcher
no flags Details


External Trackers
Tracker ID Priority Status Summary Last Updated
GNU Compiler Collection 58698 None None None Never

  None (edit)
Description Ian Pilcher 2013-10-11 19:33:20 EDT
Created attachment 811465 [details]
raid.c

Description of problem:
When compiling the (soon to be) attached file with -Os, I receive the following warning:

[pilcher@ian freecusd2]$ gcc -Os -W -Wall -Wextra -lpthread -c -o /dev/null raid.c
raid.c: In function ‘fcd_raid_fn’:
raid.c:694:20: warning: ‘array’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  array->ideal_devs = atoi(c + matches[4].rm_so);
                    ^
raid.c:642:25: note: ‘array’ was declared here
  struct fcd_raid_array *array;
                         ^

I don't get this warning with -O0, -O1, -O2, or -O3.

(array is initialized by the call to fcd_find_array at line 651; that function can be found at line 371.)

Version-Release number of selected component (if applicable):
gcc-4.8.1-1.fc19.x86_64
Comment 1 Ian Pilcher 2013-10-11 19:34:05 EDT
Created attachment 811466 [details]
freecusd.h
Comment 2 Jeff Law 2013-10-14 12:58:27 EDT
See analysis in upstream bug report.

Executive summary: -Os throttles certain optimizations and as a result we lose precision in the analysis in the uninitialized variable warning.

This is unlikely to be fixed.
Comment 3 Ian Pilcher 2013-10-14 15:31:48 EDT
(In reply to Jeff Law from comment #2)
> Executive summary: -Os throttles certain optimizations and as a result we
> lose precision in the analysis in the uninitialized variable warning.
> 
> This is unlikely to be fixed.

Hmm.  So it seems like the best option is to ensure that fcd_find_array really does unconditionally initialize 'array', even in the error path where it will never be used:

	name_len = match->rm_eo - match->rm_so;
	if (name_len >= FCD_RAID_DEVNAME_SIZE - 1) {
		FCD_WARN("RAID device name '%.*s' too long\n", (int)name_len,
			 buf + match->rm_so);
#ifdef __OPTIMIZE_SIZE__
		/* See https://bugzilla.redhat.com/show_bug.cgi?id=1018422 */
		*array = NULL;
#endif
		return -1;
	}

Is there a better alternative that I'm missing?
Comment 4 Jeff Law 2013-10-14 17:18:24 EDT
Seems fairly reasonable.

I like that you're annotating the initialization -- there's always some chance things will change in the future and we'll have a better way to deal with this kind of problem in GCC and if you've got the "bogus" initializations marked, they're much easier to find and remove.  I wish we'd done the same in GCC itself when we first decided to make it -Wuninitialized clean.

Anyway, I think we'll keep the upstream report open and attach it to whatever meta bug we have for -Wuninitialized as well as the jump threading metabug so folks working in those areas will periodically review the bug.
Comment 5 Ian Pilcher 2013-10-14 17:29:31 EDT
(In reply to Jeff Law from comment #4)
> Anyway, I think we'll keep the upstream report open and attach it to
> whatever meta bug we have for -Wuninitialized as well as the jump threading
> metabug so folks working in those areas will periodically review the bug.

Sounds like a plan.  Closing UPSTREAM.

Note You need to log in before you can comment on or make changes to this bug.