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

Reply via email to