[PATCH] Fix uninitialized use warning in c-parser.c
Jakub Jelinek
jakub@redhat.com
Fri Oct 17 14:40:00 GMT 2008
On Fri, Oct 17, 2008 at 02:56:35PM +0200, Andreas Krebbel wrote:
> I see an "variable might be used uninitialized" warning for binary_loc
> in c-parser.c. The variable is used in the cleanup code of the
> function at the out: label without assigning to it before.
>
> The attached patch fixes this for me.
This looks wrong, c_parser_peek_token (parser)->location
certainly isn't constant throughout the function. If I understand the code
right, the warning is just a false positive, as if binary_loc hasn't
been assigned yet, sp is 0 and POP won't be invoked.
So I think you want to initialize
location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */
and keep the other line as is.
> 2008-10-17 Andreas Krebbel <krebbel1@de.ibm.com>
>
> * c-parser.c (c_parser_binary_expression): binary_loc must be
> initialized since it is read in the cleanup code of the
> function before assigning to it.
>
> Index: gcc/c-parser.c
> ===================================================================
> --- gcc/c-parser.c.orig 2008-10-17 13:56:21.000000000 +0200
> +++ gcc/c-parser.c 2008-10-17 14:10:56.000000000 +0200
> @@ -4583,7 +4583,7 @@ c_parser_binary_expression (c_parser *pa
> } stack[NUM_PRECS];
> int sp;
> /* Location of the binary operator. */
> - location_t binary_loc;
> + location_t binary_loc = c_parser_peek_token (parser)->location;
> #define POP \
> do { \
> switch (stack[sp].op) \
> @@ -4696,7 +4696,6 @@ c_parser_binary_expression (c_parser *pa
> expression. */
> goto out;
> }
> - binary_loc = c_parser_peek_token (parser)->location;
> c_parser_consume_token (parser);
> while (oprec <= stack[sp].prec)
> POP;
Jakub
More information about the Gcc-patches
mailing list