git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC] reflog: silence -O3 -Wuninitialized warning
@ 2011-03-16  2:49 Jonathan Nieder
  2011-03-16  3:42 ` [PATCH nd/struct-pathspec] declare 1-bit bitfields to be unsigned Jonathan Nieder
                   ` (2 more replies)
  0 siblings, 3 replies; 34+ messages in thread
From: Jonathan Nieder @ 2011-03-16  2:49 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King

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.

Squash the warning by letting the optimizer peek at the return value
from config_error_nonbool.  This also decreases the text size by a
tiny (negligible) amount when building with -Os --- before:

    text    data     bss     dec     hex filename
 1002184   24856  316928 1343968  1481e0 git

After:

    text    data     bss     dec     hex filename
 1002120   24856  316928 1343904  1481a0 git

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Hi,

Another patch that was sitting around in my tree.  (I had the somewhat
insane idea of turning on as many warnings as feasible and getting git
to build with -Werror.  The effect on running time for tests was
encouraging but within noise.)

While it might make sense to do something like this for error()
itself, I don't know a clean and portable way to make a variadic macro
or inline function.

Anyway, maybe this can provide some amusement.

 cache.h  |    8 +++++++-
 config.c |    4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index c4ef999..c8ce53a 100644
--- a/cache.h
+++ b/cache.h
@@ -1022,10 +1022,16 @@ extern int check_repository_format_version(const char *var, const char *value, v
 extern int git_env_bool(const char *, int);
 extern int git_config_system(void);
 extern int git_config_global(void);
-extern int config_error_nonbool(const char *);
 extern const char *get_log_output_encoding(void);
 extern const char *get_commit_output_encoding(void);
 
+extern void config_print_error_nonbool(const char *);
+static inline int config_error_nonbool(const char *var)
+{
+	config_print_error_nonbool(var);
+	return -1;
+}
+
 extern const char *config_exclusive_filename;
 
 #define MAX_GITNAME (1000)
diff --git a/config.c b/config.c
index b94de8f..cf41c1c 100644
--- a/config.c
+++ b/config.c
@@ -1506,7 +1506,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
  * Call this to report error for your variable that should not
  * get a boolean value (i.e. "[my] var" means "true").
  */
-int config_error_nonbool(const char *var)
+void config_print_error_nonbool(const char *var)
 {
-	return error("Missing value for '%s'", var);
+	error("Missing value for '%s'", var);
 }
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2011-03-18  7:25 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH/RFC] reflog: silence -O3 -Wuninitialized warning Junio C Hamano
2011-03-16  6:28   ` 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

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).