This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] "constify" parse_exp_1


On 03/08/2013 12:27 PM, Pedro Alves wrote:
> Do we really need it?  Does this:
>
> -	      exp = parse_exp_1 (&p, loc->address,
> +	      exp = parse_exp_1 ((const char **) &p, loc->address,
>
> break strict aliasing rules?

Joseph Meyers confirmed this is indeed not valid in C.

> BTW, over lunch I just had an epiphany.  :-)
> This is perfectly fine:
> 
>  	  for (loc = t->base.loc; loc; loc = loc->next)
>  	    {
> -	      p = tmp_p;
> +	      const char *q;
> +
> +	      q = tmp_p;
> -	      exp = parse_exp_1 (&p, loc->address,
> +	      exp = parse_exp_1 (&q, loc->address,
> 				 block_for_pc (loc->address), 1);
> +	      p = (char *) q;
> 
> It's perfectly valid, as we know Q on output must point within
> the object/string TMP_P pointed at on entry.
> This reads much more intuitively to me, no funny arithmetic, and
> gets rid of the aliasing issue with the other suggestion, and
> no new function necessary.

And confirmed this approach is valid.

-- 
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]