* How to decide the what type is currently being used in tree_node?
@ 2021-02-19 5:01 Shuai Wang
2021-02-19 8:54 ` Prathamesh Kulkarni
0 siblings, 1 reply; 3+ messages in thread
From: Shuai Wang @ 2021-02-19 5:01 UTC (permalink / raw)
To: GCC Development
Hello,
I noticed that tree_node is implemented as a union (
https://code.woboq.org/gcc/gcc/tree-core.h.html#tree_node). However, I
cannot find a way of checking whether the current tree_node is really a
base or type.
For instance, currently when I am using:
is_gimple_constant(v)
Given `v` as a tree type but NOT base type, the above statement would
crash. I am thinking there should be a method like:
is_tree_base(v) == false
or something like this; however, I couldn't find one. Can anyone shed some
lights on this? Thank you very much!
best,
Shuai
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to decide the what type is currently being used in tree_node?
2021-02-19 5:01 How to decide the what type is currently being used in tree_node? Shuai Wang
@ 2021-02-19 8:54 ` Prathamesh Kulkarni
2021-02-19 14:54 ` Shuai Wang
0 siblings, 1 reply; 3+ messages in thread
From: Prathamesh Kulkarni @ 2021-02-19 8:54 UTC (permalink / raw)
To: Shuai Wang; +Cc: GCC Development
On Fri, 19 Feb 2021 at 10:31, Shuai Wang via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hello,
>
> I noticed that tree_node is implemented as a union (
> https://code.woboq.org/gcc/gcc/tree-core.h.html#tree_node). However, I
> cannot find a way of checking whether the current tree_node is really a
> base or type.
>
> For instance, currently when I am using:
>
> is_gimple_constant(v)
>
> Given `v` as a tree type but NOT base type, the above statement would
> crash. I am thinking there should be a method like:
>
> is_tree_base(v) == false
>
> or something like this; however, I couldn't find one. Can anyone shed some
> lights on this? Thank you very much!
If you want to ascertain which class the tree node belongs to, you can
use either TREE_CODE, or one of the _P macros
defined in tree.h. If you use an accessor that needs tree node
belonging to a certain class, then you need to check for it before
hand.
For example before using DECL_NAME on a tree node, you need to
explicitly check if it's indeed a decl_node using DECL_P.
For is_gimple_constant(v), it will return true if v is a one of the
constant nodes (*_CST), and false otherwise, so I don't see how it
will crash if you
pass a non-constant node ?
Thanks,
Prathamesh
>
> best,
> Shuai
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to decide the what type is currently being used in tree_node?
2021-02-19 8:54 ` Prathamesh Kulkarni
@ 2021-02-19 14:54 ` Shuai Wang
0 siblings, 0 replies; 3+ messages in thread
From: Shuai Wang @ 2021-02-19 14:54 UTC (permalink / raw)
To: Prathamesh Kulkarni; +Cc: GCC Development
Hello!
Thank you for the information. I am also quite confused with this issue. I
note that it seems that given the following statement:
m_pstSwtmrCBArray.27_1 = m_pstSwtmrCBArray;
where m_pstSwtmrCBArray is a global variable (a pointer). When passing a
tree pointer `v` referring to m_pstSwtmrCBArray to the following statement:
auto temp = TREE_CODE(v);
It will cause a segmentation fault of my GIMPLE pass. Not sure what's
actually going on here...
Best,
Shuai
On Fri, Feb 19, 2021 at 4:54 PM Prathamesh Kulkarni <
prathamesh.kulkarni@linaro.org> wrote:
> On Fri, 19 Feb 2021 at 10:31, Shuai Wang via Gcc <gcc@gcc.gnu.org> wrote:
> >
> > Hello,
> >
> > I noticed that tree_node is implemented as a union (
> > https://code.woboq.org/gcc/gcc/tree-core.h.html#tree_node). However, I
> > cannot find a way of checking whether the current tree_node is really a
> > base or type.
> >
> > For instance, currently when I am using:
> >
> > is_gimple_constant(v)
> >
> > Given `v` as a tree type but NOT base type, the above statement would
> > crash. I am thinking there should be a method like:
> >
> > is_tree_base(v) == false
> >
> > or something like this; however, I couldn't find one. Can anyone shed
> some
> > lights on this? Thank you very much!
> If you want to ascertain which class the tree node belongs to, you can
> use either TREE_CODE, or one of the _P macros
> defined in tree.h. If you use an accessor that needs tree node
> belonging to a certain class, then you need to check for it before
> hand.
> For example before using DECL_NAME on a tree node, you need to
> explicitly check if it's indeed a decl_node using DECL_P.
> For is_gimple_constant(v), it will return true if v is a one of the
> constant nodes (*_CST), and false otherwise, so I don't see how it
> will crash if you
> pass a non-constant node ?
>
> Thanks,
> Prathamesh
> >
> > best,
> > Shuai
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-19 14:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 5:01 How to decide the what type is currently being used in tree_node? Shuai Wang
2021-02-19 8:54 ` Prathamesh Kulkarni
2021-02-19 14:54 ` Shuai Wang
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).