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: new __builtin_choose_type (patch) (new builtin_equal_types patch)


> From: Aldy Hernandez <aldyh@redhat.com>
> To: Magnus Fromreide <magfr@lysator.liu.se>
> Cc: gcc@gcc.gnu.org
> Date: 03 Oct 2001 23:19:45 -0400

> On Wed, 2001-10-03 at 04:15, Magnus Fromreide wrote:
> > It is my feeling that it would be more general and cleaner to do something
> > along the lines of
> > 
> > _Bool __builtin_equal_types(arg|type, arg|type)
> > 
> > that doesn't evaluate the arguments if they are expressions and answers
> > the question of wether they are of the same type.

> is everyone ok with this approach?

I like it...  A simple extension, easy to document and understand,
possibly generally useful, trivial to maintain.

> + static rtx
> + expand_builtin_equal_types (exp, target)
> +      tree exp;
> +      rtx target;
> + {
> +   tree arg = TREE_OPERAND (exp, 1);
> +   tree chain;
> +   enum machine_mode exp0_mode, exp1_mode;
> + 
> +   if (!arg)
> +     return const0_rtx;
> + 
> +   chain = TREE_CHAIN (arg);
> +   arg = TREE_VALUE (arg);
> + 
> +   /* Strip off all NOPs.  */
> +   while (TREE_CODE (arg) == NOP_EXPR
> + 	 || TREE_CODE (arg) == CONVERT_EXPR
> + 	 || TREE_CODE (arg) == NON_LVALUE_EXPR
> + 	 || TREE_CODE (arg) == INDIRECT_REF)
> +     arg = TREE_OPERAND (arg, 0);
> + 
> +   /* Get <exp0> type.  */
> +   exp0_mode = TYPE_MODE (TREE_TYPE (arg));

In a frontend, we never play with modes...  The type can be found in
TREE_TYPE, and you should just use it.  This is frontend code.

> +   /* Get <exp1> type.  */
> +   arg = TREE_VALUE (chain);
> +   if (!arg)
> +     error ("missing argument in `__builtin_equal_types'");
> +   /* Strip off all NOPs.  */
> +   while (TREE_CODE (arg) == NOP_EXPR
> + 	 || TREE_CODE (arg) == CONVERT_EXPR
> + 	 || TREE_CODE (arg) == NON_LVALUE_EXPR
> + 	 || TREE_CODE (arg) == INDIRECT_REF)
> +     arg = TREE_OPERAND (arg, 0);

Again, this is wrong.  We don't peek under peoples dresses.  The type
can be found in TREE_TYPE of arg, that is is't type, no other value
is, or is as good.  The tree type inside one of these things need not
match the outer type.

> +   exp1_mode = TYPE_MODE (TREE_TYPE (arg));

Again, no modes in frontend code.


Now, the hard part, which someone eluded to, is a const int == int?
If the are !=, the you want to just compare the types.  If they are
==, then you want to use TYPE_MAIN_VARIANT on them both before
comparing.  Also, the comparison will be tricky, see
cp/typeck.c:comptypes for all the hair for one language.  You might
have to have a callback for it, as the backend is kinda stupid.

Also, since each frontend can have a different notion of same type,
you'll have to come up with enough documentation to exactly describe
what you mean.


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