From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23012 invoked by alias); 14 May 2002 19:55:29 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 22964 invoked from network); 14 May 2002 19:55:25 -0000 Received: from unknown (HELO zwingli.cygnus.com) (208.245.165.35) by sources.redhat.com with SMTP; 14 May 2002 19:55:25 -0000 Received: by zwingli.cygnus.com (Postfix, from userid 442) id 800425EA11; Tue, 14 May 2002 14:55:24 -0500 (EST) To: Daniel Berlin Cc: Andrew Cagney , Subject: Re: macrotab.c -Werror References: From: Jim Blandy Date: Tue, 14 May 2002 12:55:00 -0000 In-Reply-To: Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-05/txt/msg00554.txt.bz2 Daniel Berlin writes: > It's an obvious false positive (!best will be true the first time through, > meaning the only time we check best_depth, it's already been set at > least once). > > Here, you can't just initialize best_depth to 0, you have to initialize it > to either INT_MAX, or inclusion_depth (result). > > Sucks. You're going too fast. Here's the whole loop, for the sake of discussion: /* It's not us. Try all our children, and return the lowest. */ { struct macro_source_file *child; struct macro_source_file *best = 0; int best_depth; for (child = source->includes; child; child = child->next_included) { struct macro_source_file *result = macro_lookup_inclusion (child, name); if (result) { int result_depth = inclusion_depth (result); if (! best || result_depth < best_depth) { best = result; best_depth = result_depth; } } } The only reference to `best_depth''s value is in the right operand of `||'. That operand will never be evaluated unless `best' is non-zero. But `best' is initially zero, and is only assigned along with `best_depth'. So `best_depth''s initial value is never used. This means: - the original code is correct (although the compiler doesn't figure that out), and - you can initialize it to anything you want, since its initial value is never used. I don't actually know how many unnecessary initializations there are in GDB to silence the compiler, but it's my impression that the compiler's false positive rate for `var might be used uninitialized' warnings is low enough that it's still a useful sanity check. So I'm happy to add a few unnecessary initializations. What sucks (a bit) is that every one of those unnecessary initializations does end up generating code --- if the compiler could tell it was unnecessary, it wouldn't have printed the warning!