This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: comparing pointers inside builtins.c


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]