git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH/RFC] reflog: silence -O3 -Wuninitialized warning
Date: Tue, 15 Mar 2011 22:22:57 -0700	[thread overview]
Message-ID: <7vfwqnabbi.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20110316024959.GA24932@elie> (Jonathan Nieder's message of "Tue, 15 Mar 2011 21:49:59 -0500")

Jonathan Nieder <jrnieder@gmail.com> writes:

> Date: Fri, 04 Mar 2011 00:54:53 -0600
>
> Starting with gcc 4.5 (r147852, Pretty-ipa merge: Inliner heruistics
> reorg, 2009-05-25), gcc -O3 -Wall warns when building
> reflog_expire_config:
>
>     warning: 'expire' may be used uninitialized in this function [-Wuninitialized]
>
> The cause: starting with that version, gcc realizes it can inline the
> call to parse_expire_cfg_value.  In the error case, 'expire' is not
> initialized and the function returns early, but gcc does not have
> enough information to figure out that this is an error return.
> ...
> Anyway, maybe this can provide some amusement.

It actually provides only puzzlement.  That is obviously a buggy compiler
whose warning cannot be trusted.

I am not suggesting to work this around on the caller side, but I wonder
what effect the usual workaround to tell the compiler that we know it
doesn't understand the validity of this variable by saying:

	unsigned long expire = expire;

have on this?

We obviously do not want to work the compiler bug around in the callee
side by assigning to the variable when we didn't parse anything, but the
change to inline config_error_nonbool() to force this particular version
of the compiler to see the callchain through is _too_ subtle for my taste.
The call-chain horizon the next version of the compiler may stop looking
may be different, potentially shifting the compiler bug around.

I see two solutions (1) do not use -Wunitialized if the compiler is known
to be broken, or (2) initialize the variable to 0 (not the fake "x = x")
on the caller side at the place of the definition (yes, we would waste one
real assignment) if we really need to work this around, or (3) take this
patch.

We could obviously do (2) or (3), but the thing is, I don't think we can
have much confidence on -Wuninitialized warnings from this compiler once
we go down that route.  Is it _guaranteed_ that the compiler bug _always_
err on the false-positive side?

IOW, I'd very much prefer (1) for this particular case and if somebody
really cares (2).

Well, it indeed turned out to be amusing, at least for some definition of
the word ;-). I was starting to feel somewhat depressed watching news
programs from Japan on ustream.

  parent reply	other threads:[~2011-03-16  5:23 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-16  2:49 [PATCH/RFC] reflog: silence -O3 -Wuninitialized warning Jonathan Nieder
2011-03-16  3:42 ` [PATCH nd/struct-pathspec] declare 1-bit bitfields to be unsigned Jonathan Nieder
2011-03-16  5:38   ` Junio C Hamano
2011-03-16 14:20   ` Nguyen Thai Ngoc Duy
2011-03-16  5:22 ` Junio C Hamano [this message]
2011-03-16  6:28   ` [PATCH/RFC] reflog: silence -O3 -Wuninitialized warning Jonathan Nieder
2011-03-16  9:09   ` Johannes Sixt
2011-03-16  9:47     ` Jonathan Nieder
2011-03-16  9:54       ` Johannes Sixt
2011-03-16 10:57         ` Jonathan Nieder
2011-03-16 11:35           ` [RFC/PATCH 0/6] silence -Wuninitialized warnings that previously used the a = a trick Jonathan Nieder
2011-03-16 11:36             ` [PATCH 1/6] match-trees: kill off remaining -Wuninitialized warning Jonathan Nieder
2011-03-16 11:36             ` [PATCH 2/6] run-command: initialize failed_errno to 0 Jonathan Nieder
2011-03-16 11:37             ` [PATCH 3/6] diff --submodule: suppress -Wuninitialized warning by initializing to NULL Jonathan Nieder
2011-03-16 11:37             ` [PATCH 4/6] rsync transport: clarify insert_packed_refs Jonathan Nieder
2011-03-16 11:37             ` [PATCH 5/6] wt-status: protect against invalid change_type Jonathan Nieder
2011-03-16 11:38             ` [PATCH 6/6] fast-import: suppress -Wuninitialized warning by initializing to NULL Jonathan Nieder
2011-03-16  6:53 ` [PATCH 0/8] more warnings and cleanups Jonathan Nieder
2011-03-16  6:59   ` [PATCH 1/8] enums: omit trailing comma for portability Jonathan Nieder
2011-03-16  7:00   ` [PATCH 2/8] compat: make gcc bswap an inline function Jonathan Nieder
2011-03-16  9:21     ` Johannes Sixt
2011-03-16  9:31       ` Jonathan Nieder
2011-03-16 19:44         ` Junio C Hamano
2011-03-16  7:01   ` [PATCH 3/8] svn-fe: do not use "return" for tail call returning void Jonathan Nieder
2011-03-16  7:02   ` [PATCH 4/8] vcs-svn: remove spurious semicolons Jonathan Nieder
2011-03-16 19:47     ` Junio C Hamano
2011-03-16 20:03       ` Jonathan Nieder
2011-03-16  7:08   ` [PATCH 5/8] standardize brace placement in struct definitions Jonathan Nieder
2011-03-18  7:25     ` Junio C Hamano
2011-03-16  7:10   ` [PATCH 6/8] branch: split off function that writes tracking info and commit subject Jonathan Nieder
2011-03-16  7:12   ` [PATCH 7/8] cherry: split off function to print output lines Jonathan Nieder
2011-03-16  7:14   ` [PATCH 8/8] diff --submodule: split into bite-sized pieces Jonathan Nieder
2011-03-16 18:43     ` Jens Lehmann
2011-03-16 19:33       ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vfwqnabbi.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).