comparing pointers inside builtins.c

Mark Mitchell mark@codesourcery.com
Fri Jun 9 18:50:00 GMT 2000


>>>>> "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.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


More information about the Gcc mailing list