This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Suspicious code in fold-const.c


I was trying the ttype prototype for static type checking on fold-const.c to see how long it would take me to convert such a large file, and it choked on this snippet of code in fold_unary_loc, around lines 7690-7711:

suspect code tagged with (*)

         if ((CONVERT_EXPR_CODE_P (code)
               || code == NON_LVALUE_EXPR)
              && TREE_CODE (tem) == COND_EXPR
              && TREE_CODE (TREE_OPERAND (tem, 1)) == code
              && TREE_CODE (TREE_OPERAND (tem, 2)) == code
  (*)          && ! VOID_TYPE_P (TREE_OPERAND (tem, 1))
  (*)          && ! VOID_TYPE_P (TREE_OPERAND (tem, 2))
              && (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (tem, 1), 0))
                  == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (tem, 2), 0)))
              && (! (INTEGRAL_TYPE_P (TREE_TYPE (tem))
                     && (INTEGRAL_TYPE_P
(TREE_TYPE (TREE_OPERAND (TREE_OPERAND (tem, 1), 0))))
                     && TYPE_PRECISION (TREE_TYPE (tem)) <= BITS_PER_WORD)
                  || flag_syntax_only))
            tem = build1_loc (loc, code, type,
                              build3 (COND_EXPR,
                                      TREE_TYPE (TREE_OPERAND
(TREE_OPERAND (tem, 1), 0)),
                                      TREE_OPERAND (tem, 0),
TREE_OPERAND (TREE_OPERAND (tem, 1), 0),
                                      TREE_OPERAND (TREE_OPERAND (tem, 2),
                                                    0)));

and with:
#define VOID_TYPE_P(NODE)  (TREE_CODE (NODE) == VOID_TYPE)

I don't think this is what was intended. it would expand into:

              && TREE_CODE (TREE_OPERAND (tem, 1)) == code
              && TREE_CODE (TREE_OPERAND (tem, 2)) == code
               && ! (TREE_CODE (TREE_OPERAND (tem, 1)) == VOID_TYPE)
               && ! (TREE_CODE (TREE_OPERAND (tem, 2)) == VOID_TYPE)

the latter two would be obviously true if the first 2 were true.

My guess is this is probably suppose to be
&& ! VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (tem, 1)))
 && ! VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (tem, 2)))

but I'm not sure.   Any guesses whats intended here?

Andrew



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