Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: RFA: fix crash in expression evaluation
Date: Thu, 30 Oct 2008 04:04:00 -0000	[thread overview]
Message-ID: <20081030035443.GB13387@adacore.com> (raw)
In-Reply-To: <m3od22hpue.fsf@fleche.redhat.com>

Hi Tom,

> 2008-10-02  Tom Tromey  <tromey@redhat.com>
> 
> 	* value.c (coerce_array): Use check_typedef.

Almost OK. Just a question...

> 2008-10-02  Tom Tromey  <tromey@redhat.com>
> 
> 	* gdb.base/pointers.exp: Add test.
> 	* gdb.base/pointers.c (k, S): New typedefs.
> 	(instance): New global.

This part looks fine and is OK to commit once we have clarified
my questions.

> @@ -1692,11 +1692,16 @@ coerce_ref (struct value *arg)
>  struct value *
>  coerce_array (struct value *arg)
>  {
> +  struct type *type;

Nit-picking. I think that the general convention here is to separate
local declarations from the rest of the block with an empty line.
I wonder if this is documented anywhere...

>    arg = coerce_ref (arg);
> +  type = check_typedef (value_type (arg));
>    if (current_language->c_style_arrays
> -      && TYPE_CODE (value_type (arg)) == TYPE_CODE_ARRAY)
> -    arg = value_coerce_array (arg);
> -  if (TYPE_CODE (value_type (arg)) == TYPE_CODE_FUNC)
> +      && TYPE_CODE (type) == TYPE_CODE_ARRAY)
> +    {
> +      arg = value_coerce_array (arg);
> +      type = check_typedef (value_type (arg));

I don't think the second line is useful, is it? type should necessarily
be a TYPE_CODE_PTR, if I understand value_coerce_array correctly. So
it goes from being a TYPE_CODE_ARRAY to a TYPE_CODE_PTR. In neither case
will it cause the check just below to be true.

> +    }
> +  if (TYPE_CODE (type) == TYPE_CODE_FUNC)
>      arg = value_coerce_function (arg);
>    return arg;
>  }

Honestly, I think that the code is poorly written. How about using
a case statement or at least a if/else if sequence. Would something
like this work?

    struct type *type;

    arg = coerce_ref (arg);
    type = check_typedef (value_type (arg))

    switch (TYPE_CODE (type))
      {
        case TYPE_CODE_ARRAY:
          if (current_language->c_style_arrays)
            arg = value_coerce_array (arg);
          break;
        case TYPE_CODE_FUNC:
          arg = value_coerce_function (arg);
          break
      }
    return arg;

What do you think?

-- 
Joel

:REVIEWMAIL:


  reply	other threads:[~2008-10-30  3:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-02 17:27 Tom Tromey
2008-10-30  4:04 ` Joel Brobecker [this message]
2008-10-30 21:50   ` Tom Tromey
2008-10-30 21:48     ` Tom Tromey
2008-10-30 21:42       ` Joel Brobecker

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=20081030035443.GB13387@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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