public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "ed at catmur dot co.uk" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug exp/17904] New: "Cannot access memory at address 0x0" for function returning reference evaluated within EVAL_AVOID_SIDE_EFFECTS
Date: Thu, 29 Jan 2015 18:33:00 -0000	[thread overview]
Message-ID: <bug-17904-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=17904

            Bug ID: 17904
           Summary: "Cannot access memory at address 0x0" for function
                    returning reference evaluated within
                    EVAL_AVOID_SIDE_EFFECTS
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: exp
          Assignee: unassigned at sourceware dot org
          Reporter: ed at catmur dot co.uk

Given a function returning a reference:

    int& g() { static int i; return i; }

Evaluating the function within a EVAL_AVOID_SIDE_EFFECTS context gives an
error:

    (gdb) p 0 || +g()
    Cannot access memory at address 0x0

A workaround is to convert the reference to a pointer and indirect it:

    (gdb) p 0 || +*&g()
    $1 = true

This appears to be because OP_FUNCALL with EVAL_AVOID_SIDE_EFFECTS calls
allocate_value(), which for reference types returns a value with
location.address = 0; promotion on the reference argument then calls
coerce_ref() which gives a lazy value pointing to 0x0.

I'm not sure of a fix other than going through evaluate_subexp_standard()
putting in checks for noside == EVAL_AVOID_SIDE_EFFECTS.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


             reply	other threads:[~2015-01-29 18:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-29 18:33 ed at catmur dot co.uk [this message]
2015-01-30 13:40 ` [Bug exp/17904] " ed at catmur dot co.uk

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=bug-17904-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).