This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: comparing pointers inside builtins.c
- To: zack at wolery dot cumb dot org
- Subject: Re: comparing pointers inside builtins.c
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Fri, 09 Jun 2000 18:50:27 -0700
- Cc: gcc at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <20000609182847.Q16815@wolery.cumb.org>
>>>>> "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