From: David Malcolm <dmalcolm@redhat.com>
To: "冠人 王" <guanjen375@yahoo.com.tw>, "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: What is the difference between datatype "const_tree" and "tree" ?
Date: Thu, 05 Jul 2018 13:29:00 -0000 [thread overview]
Message-ID: <1530797353.3068.93.camel@redhat.com> (raw)
In-Reply-To: <1944714078.2881309.1530766716580@mail.yahoo.com>
On Thu, 2018-07-05 at 04:58 +0000, å 人 ç via gcc wrote:
> In the function emit_side_effect_warnings, I find its inputs are
> "location_t loc" and "tree expr".
> And, there is a function warn_if_unused_value called by
> emit_side_effect_warnings:
> emit_side_effect_warnings(location_t loc, tree expr){ ...
> else
> warn_if_unused_value(expr,loc)
> }
>
> To call warn_if_unused_value, we use location_t loc and tree expr as
> inputs
> In the function warn_if_unused_value, I find its inputs are
> "location_t loc" and "const_tree expr"
> warn_if_unused_value(const_tree exp, location_t locus){ ...
> }
> I am confused about the difference between "tree expr" and
> "const_tree expr" since
> if I modify the"const_tree" to "tree", I make failed.
The pertinent typedefs are in gcc/coretypes.h
tree is defined via:
typedef union tree_node *tree;
i.e. "tree" is a "union tree_node *".
const_tree is almost the same:
typedef const union tree_node *const_tree;
i.e. "const_tree" is a "const union tree_node *".
Both are pointers to tree_node union, but const_tree is a pointer to a
const union i.e. it promises not to write to the node.
You didn't show us the error message, so I can only guess the problem,
but my guess is that by changing it from "const_tree" to "tree", the
function is no longer promising not to write to the node, and thus
violating constness of something that calls that function.
> Besides this, I try to use debug_tree function to dump the
> imformation of the node.
> I am successful when I use it in the function
> emit_side_effect_warnings but
> not in the function warn_if_unused_value
I see that debug_tree takes a "tree", rather than a "const_tree". I'm
guessing that that's a bug, and ought to be fixed.
You can probably work around it for now by casting the const_tree back
to a tree:
debug_tree ((const_tree)exp);
or similar.
Hope this is helpful; good luck.
Dave
prev parent reply other threads:[~2018-07-05 13:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1944714078.2881309.1530766716580.ref@mail.yahoo.com>
2018-07-05 4:58 ` å 人 ç via gcc
2018-07-05 13:29 ` David Malcolm [this message]
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=1530797353.3068.93.camel@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=guanjen375@yahoo.com.tw \
/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).