This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: comparing pointers inside builtins.c
On Fri, Jun 09, 2000 at 06:50:27PM -0700, Mark Mitchell wrote:
> >>>>> "Zack" == Zack Weinberg <zack@wolery.cumb.org> writes:
>
> Zack> A number of the builtins - e.g. memcpy, strcmp - could
> Zack> benefit from knowing whether their pointer arguments are
> Zack> equal: the same constant or the same variable. Inside
> Zack> builtins.c, we're looking at trees. What is the appropriate
> Zack> way, given two pointers as trees, to decide whether we know
> Zack> they point to the same address?
>
> Address equality is the only language-independent safe comparison for
> a DECL. I.e., two VAR_DECLs denote the same object if they are
> actually the same VAR_DECL. (You could theoretically check
> DECL_ASSEMBLER_NAME as well -- two things with the same
> DECL_ASSEMBLER_NAME are the same object, even if they are not the same
> VAR_DECL. However, I would rather you didn't; this is only going to
> win rarely, and is risky if we ever figure out how to be lazy with
> name-mangling.)
>
> For string constants, you can peek inside them and use strncmp.
> (STRING_CSTs can contain embedded NULs, so you must use strncmp.)
>
> For integer constants use tree_int_cst_equal. It would be nice if you
> packaged this logic into a `tree_equal_p' routine.
Looking a bit more deeply, we already have simple_cst_equal. This
unfortunately does not do what I want; it treats all DECLs as
different, whether they are or not. I'm not sure why. It's a shame,
because otherwise that routine does exactly what I want - I may try
changing it and see if anything breaks.
zw