LCOV - code coverage report
Current view: top level - gcc/c - c-fold.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 406 417 97.4 %
Date: 2020-03-28 11:57:23 Functions: 4 6 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Support for fully folding sub-trees of an expression for C compiler.
       2                 :            :    Copyright (C) 1992-2020 Free Software Foundation, Inc.
       3                 :            : 
       4                 :            : This file is part of GCC.
       5                 :            : 
       6                 :            : GCC is free software; you can redistribute it and/or modify it under
       7                 :            : the terms of the GNU General Public License as published by the Free
       8                 :            : Software Foundation; either version 3, or (at your option) any later
       9                 :            : version.
      10                 :            : 
      11                 :            : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :            : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :            : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :            : for more details.
      15                 :            : 
      16                 :            : You should have received a copy of the GNU General Public License
      17                 :            : along with GCC; see the file COPYING3.  If not see
      18                 :            : <http://www.gnu.org/licenses/>.  */
      19                 :            : 
      20                 :            : #include "config.h"
      21                 :            : #include "system.h"
      22                 :            : #include "coretypes.h"
      23                 :            : #include "target.h"
      24                 :            : #include "function.h"
      25                 :            : #include "bitmap.h"
      26                 :            : #include "c-tree.h"
      27                 :            : #include "intl.h"
      28                 :            : #include "gimplify.h"
      29                 :            : 
      30                 :            : static tree c_fully_fold_internal (tree expr, bool, bool *, bool *, bool,
      31                 :            :                                    bool);
      32                 :            : 
      33                 :            : /* If DISABLE is true, stop issuing warnings.  This is used when
      34                 :            :    parsing code that we know will not be executed.  This function may
      35                 :            :    be called multiple times, and works as a stack.  */
      36                 :            : 
      37                 :            : static void
      38                 :     678225 : c_disable_warnings (bool disable)
      39                 :            : {
      40                 :          0 :   if (disable)
      41                 :            :     {
      42                 :      39281 :       ++c_inhibit_evaluation_warnings;
      43                 :      39281 :       fold_defer_overflow_warnings ();
      44                 :            :     }
      45                 :          0 : }
      46                 :            : 
      47                 :            : /* If ENABLE is true, reenable issuing warnings.  */
      48                 :            : 
      49                 :            : static void
      50                 :     678225 : c_enable_warnings (bool enable)
      51                 :            : {
      52                 :          0 :   if (enable)
      53                 :            :     {
      54                 :      39281 :       --c_inhibit_evaluation_warnings;
      55                 :      39281 :       fold_undefer_and_ignore_overflow_warnings ();
      56                 :            :     }
      57                 :          0 : }
      58                 :            : 
      59                 :            : /* Try to fold ARRAY_REF ary[index] if possible and not handled by
      60                 :            :    normal fold, return NULL_TREE otherwise.  */
      61                 :            : 
      62                 :            : static tree
      63                 :        799 : c_fold_array_ref (tree type, tree ary, tree index)
      64                 :            : {
      65                 :        799 :   if (TREE_CODE (ary) != STRING_CST
      66                 :        792 :       || TREE_CODE (index) != INTEGER_CST
      67                 :        792 :       || TREE_OVERFLOW (index)
      68                 :        791 :       || TREE_CODE (TREE_TYPE (ary)) != ARRAY_TYPE
      69                 :       1590 :       || !tree_fits_uhwi_p (index))
      70                 :            :     return NULL_TREE;
      71                 :            : 
      72                 :        790 :   tree elem_type = TREE_TYPE (TREE_TYPE (ary));
      73                 :        790 :   unsigned elem_nchars = (TYPE_PRECISION (elem_type)
      74                 :        790 :                           / TYPE_PRECISION (char_type_node));
      75                 :        790 :   unsigned len = (unsigned) TREE_STRING_LENGTH (ary) / elem_nchars;
      76                 :        790 :   tree nelts = array_type_nelts (TREE_TYPE (ary));
      77                 :        790 :   bool dummy1 = true, dummy2 = true;
      78                 :        790 :   nelts = c_fully_fold_internal (nelts, true, &dummy1, &dummy2, false, false);
      79                 :        790 :   unsigned HOST_WIDE_INT i = tree_to_uhwi (index);
      80                 :        790 :   if (!tree_int_cst_le (index, nelts)
      81                 :        789 :       || i >= len
      82                 :       1579 :       || i + elem_nchars > len)
      83                 :            :     return NULL_TREE;
      84                 :            : 
      85                 :        789 :   if (elem_nchars == 1)
      86                 :        789 :     return build_int_cst (type, TREE_STRING_POINTER (ary)[i]);
      87                 :            : 
      88                 :          0 :   const unsigned char *ptr
      89                 :          0 :     = ((const unsigned char *)TREE_STRING_POINTER (ary) + i * elem_nchars);
      90                 :          0 :   return native_interpret_expr (type, ptr, elem_nchars);
      91                 :            : }
      92                 :            : 
      93                 :            : /* Fully fold EXPR, an expression that was not folded (beyond integer
      94                 :            :    constant expressions and null pointer constants) when being built
      95                 :            :    up.  If IN_INIT, this is in a static initializer and certain
      96                 :            :    changes are made to the folding done.  Clear *MAYBE_CONST if
      97                 :            :    MAYBE_CONST is not NULL and EXPR is definitely not a constant
      98                 :            :    expression because it contains an evaluated operator (in C99) or an
      99                 :            :    operator outside of sizeof returning an integer constant (in C90)
     100                 :            :    not permitted in constant expressions, or because it contains an
     101                 :            :    evaluated arithmetic overflow.  (*MAYBE_CONST should typically be
     102                 :            :    set to true by callers before calling this function.)  Return the
     103                 :            :    folded expression.  Function arguments have already been folded
     104                 :            :    before calling this function, as have the contents of SAVE_EXPR,
     105                 :            :    TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
     106                 :            :    C_MAYBE_CONST_EXPR.  LVAL is true if it should be treated as an
     107                 :            :    lvalue.  */
     108                 :            : 
     109                 :            : tree
     110                 :  150281000 : c_fully_fold (tree expr, bool in_init, bool *maybe_const, bool lval)
     111                 :            : {
     112                 :  150281000 :   tree ret;
     113                 :  150281000 :   tree eptype = NULL_TREE;
     114                 :  150281000 :   bool dummy = true;
     115                 :  150281000 :   bool maybe_const_itself = true;
     116                 :  150281000 :   location_t loc = EXPR_LOCATION (expr);
     117                 :            : 
     118                 :  150281000 :   if (!maybe_const)
     119                 :  131278000 :     maybe_const = &dummy;
     120                 :  150281000 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
     121                 :            :     {
     122                 :         62 :       eptype = TREE_TYPE (expr);
     123                 :         62 :       expr = TREE_OPERAND (expr, 0);
     124                 :            :     }
     125                 :  150281000 :   ret = c_fully_fold_internal (expr, in_init, maybe_const,
     126                 :            :                                &maybe_const_itself, false, lval);
     127                 :  150281000 :   if (eptype)
     128                 :         62 :     ret = fold_convert_loc (loc, eptype, ret);
     129                 :  150281000 :   *maybe_const &= maybe_const_itself;
     130                 :  150281000 :   return ret;
     131                 :            : }
     132                 :            : 
     133                 :            : /* Internal helper for c_fully_fold.  EXPR and IN_INIT are as for
     134                 :            :    c_fully_fold.  *MAYBE_CONST_OPERANDS is cleared because of operands
     135                 :            :    not permitted, while *MAYBE_CONST_ITSELF is cleared because of
     136                 :            :    arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from
     137                 :            :    both evaluated and unevaluated subexpressions while
     138                 :            :    *MAYBE_CONST_ITSELF is carried from only evaluated
     139                 :            :    subexpressions).  FOR_INT_CONST indicates if EXPR is an expression
     140                 :            :    with integer constant operands, and if any of the operands doesn't
     141                 :            :    get folded to an integer constant, don't fold the expression itself.
     142                 :            :    LVAL indicates folding of lvalue, where we can't replace it with
     143                 :            :    an rvalue.  */
     144                 :            : 
     145                 :            : static tree
     146                 :  274845000 : c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
     147                 :            :                        bool *maybe_const_itself, bool for_int_const, bool lval)
     148                 :            : {
     149                 :  274845000 :   tree ret = expr;
     150                 :  274845000 :   enum tree_code code = TREE_CODE (expr);
     151                 :  274845000 :   enum tree_code_class kind = TREE_CODE_CLASS (code);
     152                 :  274845000 :   location_t loc = EXPR_LOCATION (expr);
     153                 :  274845000 :   tree op0, op1, op2, op3;
     154                 :  274845000 :   tree orig_op0, orig_op1, orig_op2;
     155                 :  274845000 :   bool op0_const = true, op1_const = true, op2_const = true;
     156                 :  274845000 :   bool op0_const_self = true, op1_const_self = true, op2_const_self = true;
     157                 :  274845000 :   bool nowarning = TREE_NO_WARNING (expr);
     158                 :  274845000 :   bool unused_p;
     159                 :  274845000 :   bool op0_lval = false;
     160                 :  274845000 :   source_range old_range;
     161                 :            : 
     162                 :            :   /* Constants, declarations, statements, errors, and anything else not
     163                 :            :      counted as an expression cannot usefully be folded further at this
     164                 :            :      point.  */
     165                 :  274845000 :   if (!IS_EXPR_CODE_CLASS (kind) || kind == tcc_statement)
     166                 :            :     {
     167                 :            :       /* Except for variables which we can optimize to its initializer.  */
     168                 :  129142000 :       if (VAR_P (expr) && !lval && (optimize || in_init))
     169                 :            :         {
     170                 :    6763840 :           if (in_init)
     171                 :        351 :             ret = decl_constant_value_1 (expr, true);
     172                 :            :           else
     173                 :            :             {
     174                 :    6763480 :               ret = decl_constant_value (expr);
     175                 :    6763480 :               if (ret != expr
     176                 :    6777670 :                   && (TYPE_MODE (TREE_TYPE (ret)) == BLKmode
     177                 :      12591 :                       || TREE_CODE (TREE_TYPE (ret)) == ARRAY_TYPE))
     178                 :            :                 return expr;
     179                 :            :             }
     180                 :            :           /* Avoid unwanted tree sharing between the initializer and current
     181                 :            :              function's body where the tree can be modified e.g. by the
     182                 :            :              gimplifier.  */
     183                 :    6761940 :           if (ret != expr && TREE_STATIC (expr))
     184                 :       5491 :             ret = unshare_expr (ret);
     185                 :    6761940 :           return ret;
     186                 :            :         }
     187                 :            :       return expr;
     188                 :            :     }
     189                 :            : 
     190                 :  145703000 :   if (IS_EXPR_CODE_CLASS (kind))
     191                 :  145703000 :     old_range = EXPR_LOCATION_RANGE (expr);
     192                 :            : 
     193                 :            :   /* Operands of variable-length expressions (function calls) have
     194                 :            :      already been folded, as have __builtin_* function calls, and such
     195                 :            :      expressions cannot occur in constant expressions.  */
     196                 :  145703000 :   if (kind == tcc_vl_exp)
     197                 :            :     {
     198                 :   27274900 :       *maybe_const_operands = false;
     199                 :   27274900 :       ret = fold (expr);
     200                 :   27274900 :       goto out;
     201                 :            :     }
     202                 :            : 
     203                 :  118428000 :   if (code == C_MAYBE_CONST_EXPR)
     204                 :            :     {
     205                 :    2542810 :       tree pre = C_MAYBE_CONST_EXPR_PRE (expr);
     206                 :    2542810 :       tree inner = C_MAYBE_CONST_EXPR_EXPR (expr);
     207                 :    2542810 :       if (C_MAYBE_CONST_EXPR_NON_CONST (expr))
     208                 :     604248 :         *maybe_const_operands = false;
     209                 :    2542810 :       if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr))
     210                 :            :         {
     211                 :       1525 :           *maybe_const_itself = false;
     212                 :       1525 :           inner = c_fully_fold_internal (inner, in_init, maybe_const_operands,
     213                 :            :                                          maybe_const_itself, true, lval);
     214                 :            :         }
     215                 :    2542810 :       if (pre && !in_init)
     216                 :        295 :         ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr), pre, inner);
     217                 :            :       else
     218                 :            :         ret = inner;
     219                 :    2542810 :       goto out;
     220                 :            :     }
     221                 :            : 
     222                 :            :   /* Assignment, increment, decrement, function call and comma
     223                 :            :      operators, and statement expressions, cannot occur in constant
     224                 :            :      expressions if evaluated / outside of sizeof.  (Function calls
     225                 :            :      were handled above, though VA_ARG_EXPR is treated like a function
     226                 :            :      call here, and statement expressions are handled through
     227                 :            :      C_MAYBE_CONST_EXPR to avoid folding inside them.)  */
     228                 :  115885000 :   switch (code)
     229                 :            :     {
     230                 :    2901990 :     case MODIFY_EXPR:
     231                 :    2901990 :     case PREDECREMENT_EXPR:
     232                 :    2901990 :     case PREINCREMENT_EXPR:
     233                 :    2901990 :     case POSTDECREMENT_EXPR:
     234                 :    2901990 :     case POSTINCREMENT_EXPR:
     235                 :    2901990 :     case COMPOUND_EXPR:
     236                 :    2901990 :       *maybe_const_operands = false;
     237                 :    2901990 :       break;
     238                 :            : 
     239                 :     120166 :     case VA_ARG_EXPR:
     240                 :     120166 :     case TARGET_EXPR:
     241                 :     120166 :     case BIND_EXPR:
     242                 :     120166 :     case OBJ_TYPE_REF:
     243                 :     120166 :       *maybe_const_operands = false;
     244                 :     120166 :       ret = fold (expr);
     245                 :     120166 :       goto out;
     246                 :            : 
     247                 :            :     default:
     248                 :            :       break;
     249                 :            :     }
     250                 :            : 
     251                 :            :   /* Fold individual tree codes as appropriate.  */
     252                 :  115765000 :   switch (code)
     253                 :            :     {
     254                 :     482465 :     case COMPOUND_LITERAL_EXPR:
     255                 :            :       /* Any non-constancy will have been marked in a containing
     256                 :            :          C_MAYBE_CONST_EXPR; there is no more folding to do here.  */
     257                 :     482465 :       goto out;
     258                 :            : 
     259                 :    2173780 :     case COMPONENT_REF:
     260                 :    2173780 :       orig_op0 = op0 = TREE_OPERAND (expr, 0);
     261                 :    2173780 :       op1 = TREE_OPERAND (expr, 1);
     262                 :    2173780 :       op2 = TREE_OPERAND (expr, 2);
     263                 :    2173780 :       op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
     264                 :            :                                    maybe_const_itself, for_int_const, lval);
     265                 :    2173780 :       STRIP_TYPE_NOPS (op0);
     266                 :    2173780 :       if (op0 != orig_op0)
     267                 :       9555 :         ret = build3 (COMPONENT_REF, TREE_TYPE (expr), op0, op1, op2);
     268                 :    2173780 :       if (ret != expr)
     269                 :            :         {
     270                 :       9555 :           TREE_READONLY (ret) = TREE_READONLY (expr);
     271                 :       9555 :           TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
     272                 :            :         }
     273                 :    2173780 :       if (!lval)
     274                 :    1592070 :         ret = fold (ret);
     275                 :    2173780 :       goto out;
     276                 :            : 
     277                 :    1746960 :     case ARRAY_REF:
     278                 :    1746960 :       orig_op0 = op0 = TREE_OPERAND (expr, 0);
     279                 :    1746960 :       orig_op1 = op1 = TREE_OPERAND (expr, 1);
     280                 :    1746960 :       op2 = TREE_OPERAND (expr, 2);
     281                 :    1746960 :       op3 = TREE_OPERAND (expr, 3);
     282                 :    1746960 :       op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
     283                 :            :                                    maybe_const_itself, for_int_const, lval);
     284                 :    1746960 :       STRIP_TYPE_NOPS (op0);
     285                 :    1746960 :       op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands,
     286                 :            :                                    maybe_const_itself, for_int_const, false);
     287                 :    1748920 :       STRIP_TYPE_NOPS (op1);
     288                 :            :       /* Fold "foo"[2] in initializers.  */
     289                 :    1746960 :       if (!lval && in_init)
     290                 :            :         {
     291                 :        799 :           ret = c_fold_array_ref (TREE_TYPE (expr), op0, op1);
     292                 :        799 :           if (ret)
     293                 :        789 :             goto out;
     294                 :            :           ret = expr;
     295                 :            :         }
     296                 :    1746170 :       if (op0 != orig_op0 || op1 != orig_op1)
     297                 :      74402 :         ret = build4 (ARRAY_REF, TREE_TYPE (expr), op0, op1, op2, op3);
     298                 :    1746170 :       if (ret != expr)
     299                 :            :         {
     300                 :      74402 :           TREE_READONLY (ret) = TREE_READONLY (expr);
     301                 :      74402 :           TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr);
     302                 :      74402 :           TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
     303                 :            :         }
     304                 :    1746170 :       if (!lval)
     305                 :    1354910 :         ret = fold (ret);
     306                 :    1746170 :       goto out;
     307                 :            : 
     308                 :    2724470 :     case MODIFY_EXPR:
     309                 :    2724470 :     case PREDECREMENT_EXPR:
     310                 :    2724470 :     case PREINCREMENT_EXPR:
     311                 :    2724470 :     case POSTDECREMENT_EXPR:
     312                 :    2724470 :     case POSTINCREMENT_EXPR:
     313                 :    2724470 :       op0_lval = true;
     314                 :            :       /* FALLTHRU */
     315                 :    8850200 :     case COMPOUND_EXPR:
     316                 :    8850200 :     case PLUS_EXPR:
     317                 :    8850200 :     case MINUS_EXPR:
     318                 :    8850200 :     case MULT_EXPR:
     319                 :    8850200 :     case POINTER_PLUS_EXPR:
     320                 :    8850200 :     case POINTER_DIFF_EXPR:
     321                 :    8850200 :     case TRUNC_DIV_EXPR:
     322                 :    8850200 :     case CEIL_DIV_EXPR:
     323                 :    8850200 :     case FLOOR_DIV_EXPR:
     324                 :    8850200 :     case TRUNC_MOD_EXPR:
     325                 :    8850200 :     case RDIV_EXPR:
     326                 :    8850200 :     case EXACT_DIV_EXPR:
     327                 :    8850200 :     case LSHIFT_EXPR:
     328                 :    8850200 :     case RSHIFT_EXPR:
     329                 :    8850200 :     case BIT_IOR_EXPR:
     330                 :    8850200 :     case BIT_XOR_EXPR:
     331                 :    8850200 :     case BIT_AND_EXPR:
     332                 :    8850200 :     case LT_EXPR:
     333                 :    8850200 :     case LE_EXPR:
     334                 :    8850200 :     case GT_EXPR:
     335                 :    8850200 :     case GE_EXPR:
     336                 :    8850200 :     case EQ_EXPR:
     337                 :    8850200 :     case NE_EXPR:
     338                 :    8850200 :     case COMPLEX_EXPR:
     339                 :    8850200 :     case TRUTH_AND_EXPR:
     340                 :    8850200 :     case TRUTH_OR_EXPR:
     341                 :    8850200 :     case TRUTH_XOR_EXPR:
     342                 :    8850200 :     case UNORDERED_EXPR:
     343                 :    8850200 :     case ORDERED_EXPR:
     344                 :    8850200 :     case UNLT_EXPR:
     345                 :    8850200 :     case UNLE_EXPR:
     346                 :    8850200 :     case UNGT_EXPR:
     347                 :    8850200 :     case UNGE_EXPR:
     348                 :    8850200 :     case UNEQ_EXPR:
     349                 :    8850200 :     case MEM_REF:
     350                 :            :       /* Binary operations evaluating both arguments (increment and
     351                 :            :          decrement are binary internally in GCC).  */
     352                 :    8850200 :       orig_op0 = op0 = TREE_OPERAND (expr, 0);
     353                 :    8850200 :       orig_op1 = op1 = TREE_OPERAND (expr, 1);
     354                 :    8850200 :       op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
     355                 :            :                                    maybe_const_itself, for_int_const,
     356                 :            :                                    op0_lval);
     357                 :   10255900 :       STRIP_TYPE_NOPS (op0);
     358                 :            :       /* The RHS of a MODIFY_EXPR was fully folded when building that
     359                 :            :          expression for the sake of conversion warnings.  */
     360                 :    8850200 :       if (code != MODIFY_EXPR)
     361                 :    6778430 :         op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands,
     362                 :            :                                      maybe_const_itself, for_int_const, false);
     363                 :   10069100 :       STRIP_TYPE_NOPS (op1);
     364                 :            : 
     365                 :    8850200 :       if (for_int_const && (TREE_CODE (op0) != INTEGER_CST
     366                 :       1069 :                             || TREE_CODE (op1) != INTEGER_CST))
     367                 :        221 :         goto out;
     368                 :            : 
     369                 :    8849980 :       if (op0 != orig_op0 || op1 != orig_op1 || in_init)
     370                 :    1875840 :         ret = in_init
     371                 :    1879970 :           ? fold_build2_initializer_loc (loc, code, TREE_TYPE (expr), op0, op1)
     372                 :    1871700 :           : fold_build2_loc (loc, code, TREE_TYPE (expr), op0, op1);
     373                 :            :       else
     374                 :    6974150 :         ret = fold (expr);
     375                 :     262133 :       if (TREE_OVERFLOW_P (ret)
     376                 :         69 :           && !TREE_OVERFLOW_P (op0)
     377                 :    8850010 :           && !TREE_OVERFLOW_P (op1))
     378                 :         27 :         overflow_warning (EXPR_LOC_OR_LOC (expr, input_location), ret, expr);
     379                 :    8849980 :       if (code == LSHIFT_EXPR
     380                 :     225478 :           && TREE_CODE (orig_op0) != INTEGER_CST
     381                 :     173800 :           && TREE_CODE (TREE_TYPE (orig_op0)) == INTEGER_TYPE
     382                 :     173446 :           && TREE_CODE (op0) == INTEGER_CST
     383                 :        166 :           && c_inhibit_evaluation_warnings == 0
     384                 :    8850040 :           && tree_int_cst_sgn (op0) < 0)
     385                 :          6 :         warning_at (loc, OPT_Wshift_negative_value,
     386                 :            :                     "left shift of negative value");
     387                 :    8849980 :       if ((code == LSHIFT_EXPR || code == RSHIFT_EXPR)
     388                 :     326879 :           && TREE_CODE (orig_op1) != INTEGER_CST
     389                 :      71666 :           && TREE_CODE (op1) == INTEGER_CST
     390                 :         63 :           && TREE_CODE (TREE_TYPE (orig_op1)) == INTEGER_TYPE
     391                 :    8850040 :           && c_inhibit_evaluation_warnings == 0)
     392                 :            :         {
     393                 :         56 :           if (tree_int_cst_sgn (op1) < 0)
     394                 :         29 :             warning_at (loc, OPT_Wshift_count_negative,
     395                 :            :                         (code == LSHIFT_EXPR
     396                 :            :                          ? G_("left shift count is negative")
     397                 :            :                          : G_("right shift count is negative")));
     398                 :         39 :           else if ((TREE_CODE (TREE_TYPE (orig_op0)) == INTEGER_TYPE
     399                 :         12 :                     || TREE_CODE (TREE_TYPE (orig_op0)) == FIXED_POINT_TYPE)
     400                 :         66 :                    && compare_tree_int (op1,
     401                 :         27 :                                         TYPE_PRECISION (TREE_TYPE (orig_op0)))
     402                 :            :                       >= 0)
     403                 :          6 :             warning_at (loc, OPT_Wshift_count_overflow,
     404                 :            :                         (code == LSHIFT_EXPR
     405                 :            :                          ? G_("left shift count >= width of type")
     406                 :            :                          : G_("right shift count >= width of type")));
     407                 :         35 :           else if (TREE_CODE (TREE_TYPE (orig_op0)) == VECTOR_TYPE
     408                 :         47 :                    && compare_tree_int (op1,
     409                 :         12 :                                         TYPE_PRECISION (TREE_TYPE (TREE_TYPE (orig_op0))))
     410                 :            :                       >= 0)
     411                 :          9 :             warning_at (loc, OPT_Wshift_count_overflow,
     412                 :            :                         code == LSHIFT_EXPR
     413                 :            :                         ? G_("left shift count >= width of vector element")
     414                 :            :                         : G_("right shift count >= width of vector element"));
     415                 :            :         }
     416                 :    8849980 :       if (code == LSHIFT_EXPR
     417                 :            :           /* If either OP0 has been folded to INTEGER_CST...  */
     418                 :     225478 :           && ((TREE_CODE (orig_op0) != INTEGER_CST
     419                 :     173800 :                && TREE_CODE (TREE_TYPE (orig_op0)) == INTEGER_TYPE
     420                 :     173446 :                && TREE_CODE (op0) == INTEGER_CST)
     421                 :            :               /* ...or if OP1 has been folded to INTEGER_CST...  */
     422                 :     225312 :               || (TREE_CODE (orig_op1) != INTEGER_CST
     423                 :      61004 :                   && TREE_CODE (TREE_TYPE (orig_op1)) == INTEGER_TYPE
     424                 :      60810 :                   && TREE_CODE (op1) == INTEGER_CST))
     425                 :    8850170 :           && c_inhibit_evaluation_warnings == 0)
     426                 :            :         /* ...then maybe we can detect an overflow.  */
     427                 :         87 :         maybe_warn_shift_overflow (loc, op0, op1);
     428                 :    8849980 :       if ((code == TRUNC_DIV_EXPR
     429                 :            :            || code == CEIL_DIV_EXPR
     430                 :    8849980 :            || code == FLOOR_DIV_EXPR
     431                 :    8849980 :            || code == EXACT_DIV_EXPR
     432                 :    8817270 :            || code == TRUNC_MOD_EXPR)
     433                 :      77146 :           && TREE_CODE (orig_op1) != INTEGER_CST
     434                 :       9421 :           && TREE_CODE (op1) == INTEGER_CST
     435                 :         30 :           && (TREE_CODE (TREE_TYPE (orig_op0)) == INTEGER_TYPE
     436                 :          0 :               || TREE_CODE (TREE_TYPE (orig_op0)) == FIXED_POINT_TYPE)
     437                 :    8850010 :           && TREE_CODE (TREE_TYPE (orig_op1)) == INTEGER_TYPE)
     438                 :         30 :         warn_for_div_by_zero (loc, op1);
     439                 :    8849980 :       if (code == MEM_REF
     440                 :    8849980 :           && ret != expr
     441                 :          7 :           && TREE_CODE (ret) == MEM_REF)
     442                 :            :         {
     443                 :          7 :           TREE_READONLY (ret) = TREE_READONLY (expr);
     444                 :          7 :           TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr);
     445                 :          7 :           TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
     446                 :            :         }
     447                 :    8849980 :       goto out;
     448                 :            : 
     449                 :   29376000 :     case ADDR_EXPR:
     450                 :   29376000 :       op0_lval = true;
     451                 :   29376000 :       goto unary;
     452                 :   55217600 :     case REALPART_EXPR:
     453                 :   55217600 :     case IMAGPART_EXPR:
     454                 :   55217600 :     case VIEW_CONVERT_EXPR:
     455                 :   55217600 :       op0_lval = lval;
     456                 :            :       /* FALLTHRU */
     457                 :  101771000 :     case INDIRECT_REF:
     458                 :  101771000 :     case FIX_TRUNC_EXPR:
     459                 :  101771000 :     case FLOAT_EXPR:
     460                 :  101771000 :     CASE_CONVERT:
     461                 :  101771000 :     case ADDR_SPACE_CONVERT_EXPR:
     462                 :  101771000 :     case NON_LVALUE_EXPR:
     463                 :  101771000 :     case NEGATE_EXPR:
     464                 :  101771000 :     case BIT_NOT_EXPR:
     465                 :  101771000 :     case TRUTH_NOT_EXPR:
     466                 :  101771000 :     case CONJ_EXPR:
     467                 :  101771000 :     unary:
     468                 :            :       /* Unary operations.  */
     469                 :  101771000 :       orig_op0 = op0 = TREE_OPERAND (expr, 0);
     470                 :  101771000 :       op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
     471                 :            :                                    maybe_const_itself, for_int_const,
     472                 :            :                                    op0_lval);
     473                 :  102067000 :       STRIP_TYPE_NOPS (op0);
     474                 :            : 
     475                 :  101771000 :       if (for_int_const && TREE_CODE (op0) != INTEGER_CST)
     476                 :         14 :         goto out;
     477                 :            : 
     478                 :            :       /* ??? Cope with user tricks that amount to offsetof.  The middle-end is
     479                 :            :          not prepared to deal with them if they occur in initializers.  */
     480                 :  101771000 :       if (op0 != orig_op0
     481                 :  101771000 :           && code == ADDR_EXPR
     482                 :        485 :           && (op1 = get_base_address (op0)) != NULL_TREE
     483                 :        485 :           && INDIRECT_REF_P (op1)
     484                 :  101771000 :           && TREE_CONSTANT (TREE_OPERAND (op1, 0)))
     485                 :        102 :         ret = fold_offsetof (op0, TREE_TYPE (expr));
     486                 :  101770000 :       else if (op0 != orig_op0 || in_init)
     487                 :    3274820 :         ret = in_init
     488                 :    6165450 :           ? fold_build1_initializer_loc (loc, code, TREE_TYPE (expr), op0)
     489                 :     384189 :           : fold_build1_loc (loc, code, TREE_TYPE (expr), op0);
     490                 :            :       else
     491                 :   98495600 :         ret = fold (expr);
     492                 :  101771000 :       if (code == INDIRECT_REF
     493                 :  101771000 :           && ret != expr
     494                 :      19822 :           && INDIRECT_REF_P (ret))
     495                 :            :         {
     496                 :      19802 :           TREE_READONLY (ret) = TREE_READONLY (expr);
     497                 :      19802 :           TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr);
     498                 :      19802 :           TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr);
     499                 :            :         }
     500                 :  101771000 :       switch (code)
     501                 :            :         {
     502                 :            :         case FIX_TRUNC_EXPR:
     503                 :            :         case FLOAT_EXPR:
     504                 :            :         CASE_CONVERT:
     505                 :            :           /* Don't warn about explicit conversions.  We will already
     506                 :            :              have warned about suspect implicit conversions.  */
     507                 :            :           break;
     508                 :            : 
     509                 :   87180000 :         default:
     510                 :   87180000 :           if (TREE_OVERFLOW_P (ret) && !TREE_OVERFLOW_P (op0))
     511                 :          0 :             overflow_warning (EXPR_LOCATION (expr), ret, op0);
     512                 :            :           break;
     513                 :            :         }
     514                 :  101771000 :       goto out;
     515                 :            : 
     516                 :     358867 :     case TRUTH_ANDIF_EXPR:
     517                 :     358867 :     case TRUTH_ORIF_EXPR:
     518                 :            :       /* Binary operations not necessarily evaluating both
     519                 :            :          arguments.  */
     520                 :     358867 :       orig_op0 = op0 = TREE_OPERAND (expr, 0);
     521                 :     358867 :       orig_op1 = op1 = TREE_OPERAND (expr, 1);
     522                 :     358867 :       op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self,
     523                 :            :                                    for_int_const, false);
     524                 :     359055 :       STRIP_TYPE_NOPS (op0);
     525                 :            : 
     526                 :     717734 :       unused_p = (op0 == (code == TRUTH_ANDIF_EXPR
     527                 :     358867 :                           ? truthvalue_false_node
     528                 :            :                           : truthvalue_true_node));
     529                 :     358867 :       c_disable_warnings (unused_p);
     530                 :     358867 :       op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self,
     531                 :            :                                    for_int_const, false);
     532                 :     359199 :       STRIP_TYPE_NOPS (op1);
     533                 :     358867 :       c_enable_warnings (unused_p);
     534                 :            : 
     535                 :     358867 :       if (for_int_const
     536                 :         50 :           && (TREE_CODE (op0) != INTEGER_CST
     537                 :            :               /* Require OP1 be an INTEGER_CST only if it's evaluated.  */
     538                 :         36 :               || (!unused_p && TREE_CODE (op1) != INTEGER_CST)))
     539                 :         40 :         goto out;
     540                 :            : 
     541                 :     358827 :       if (op0 != orig_op0 || op1 != orig_op1 || in_init)
     542                 :     351298 :         ret = in_init
     543                 :     351313 :           ? fold_build2_initializer_loc (loc, code, TREE_TYPE (expr), op0, op1)
     544                 :     351283 :           : fold_build2_loc (loc, code, TREE_TYPE (expr), op0, op1);
     545                 :            :       else
     546                 :       7529 :         ret = fold (expr);
     547                 :     358827 :       *maybe_const_operands &= op0_const;
     548                 :     358827 :       *maybe_const_itself &= op0_const_self;
     549                 :     282841 :       if (!(flag_isoc99
     550                 :     358827 :             && op0_const
     551                 :     282841 :             && op0_const_self
     552                 :            :             && (code == TRUTH_ANDIF_EXPR
     553                 :      90382 :                 ? op0 == truthvalue_false_node
     554                 :     192459 :                 : op0 == truthvalue_true_node)))
     555                 :     351261 :         *maybe_const_operands &= op1_const;
     556                 :     644019 :       if (!(op0_const
     557                 :     285192 :             && op0_const_self
     558                 :            :             && (code == TRUTH_ANDIF_EXPR
     559                 :      90493 :                 ? op0 == truthvalue_false_node
     560                 :     194699 :                 : op0 == truthvalue_true_node)))
     561                 :     351243 :         *maybe_const_itself &= op1_const_self;
     562                 :     358827 :       goto out;
     563                 :            : 
     564                 :     159679 :     case COND_EXPR:
     565                 :     159679 :       orig_op0 = op0 = TREE_OPERAND (expr, 0);
     566                 :     159679 :       orig_op1 = op1 = TREE_OPERAND (expr, 1);
     567                 :     159679 :       orig_op2 = op2 = TREE_OPERAND (expr, 2);
     568                 :     159679 :       op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self,
     569                 :            :                                    for_int_const, false);
     570                 :            : 
     571                 :     159679 :       STRIP_TYPE_NOPS (op0);
     572                 :     159679 :       c_disable_warnings (op0 == truthvalue_false_node);
     573                 :     159679 :       op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self,
     574                 :            :                                    for_int_const, false);
     575                 :     177280 :       STRIP_TYPE_NOPS (op1);
     576                 :     159679 :       c_enable_warnings (op0 == truthvalue_false_node);
     577                 :            : 
     578                 :     159679 :       c_disable_warnings (op0 == truthvalue_true_node);
     579                 :     159679 :       op2 = c_fully_fold_internal (op2, in_init, &op2_const, &op2_const_self,
     580                 :            :                                    for_int_const, false);
     581                 :     211642 :       STRIP_TYPE_NOPS (op2);
     582                 :     159679 :       c_enable_warnings (op0 == truthvalue_true_node);
     583                 :            : 
     584                 :     159679 :       if (for_int_const
     585                 :         76 :           && (TREE_CODE (op0) != INTEGER_CST
     586                 :            :               /* Only the evaluated operand must be an INTEGER_CST.  */
     587                 :         41 :               || (op0 == truthvalue_true_node
     588                 :         14 :                   ? TREE_CODE (op1) != INTEGER_CST
     589                 :         27 :                   : TREE_CODE (op2) != INTEGER_CST)))
     590                 :         62 :         goto out;
     591                 :            : 
     592                 :     159617 :       if (op0 != orig_op0 || op1 != orig_op1 || op2 != orig_op2)
     593                 :     145024 :         ret = fold_build3_loc (loc, code, TREE_TYPE (expr), op0, op1, op2);
     594                 :            :       else
     595                 :      14593 :         ret = fold (expr);
     596                 :     159617 :       *maybe_const_operands &= op0_const;
     597                 :     159617 :       *maybe_const_itself &= op0_const_self;
     598                 :     265027 :       if (!(flag_isoc99
     599                 :     159617 :             && op0_const
     600                 :     105410 :             && op0_const_self
     601                 :     105410 :             && op0 == truthvalue_false_node))
     602                 :     146156 :         *maybe_const_operands &= op1_const;
     603                 :     159617 :       if (!(op0_const
     604                 :     106040 :             && op0_const_self
     605                 :     106040 :             && op0 == truthvalue_false_node))
     606                 :     145808 :         *maybe_const_itself &= op1_const_self;
     607                 :     159617 :       if (!(flag_isoc99
     608                 :     158962 :             && op0_const
     609                 :     105410 :             && op0_const_self
     610                 :     105410 :             && op0 == truthvalue_true_node))
     611                 :     142202 :         *maybe_const_operands &= op2_const;
     612                 :     159617 :       if (!(op0_const
     613                 :     106040 :             && op0_const_self
     614                 :     106040 :             && op0 == truthvalue_true_node))
     615                 :     142106 :         *maybe_const_itself &= op2_const_self;
     616                 :     159617 :       goto out;
     617                 :            : 
     618                 :      76904 :     case VEC_COND_EXPR:
     619                 :      76904 :       orig_op0 = op0 = TREE_OPERAND (expr, 0);
     620                 :      76904 :       orig_op1 = op1 = TREE_OPERAND (expr, 1);
     621                 :      76904 :       orig_op2 = op2 = TREE_OPERAND (expr, 2);
     622                 :      76904 :       op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
     623                 :            :                                    maybe_const_itself, for_int_const, false);
     624                 :      76904 :       STRIP_TYPE_NOPS (op0);
     625                 :      76904 :       op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands,
     626                 :            :                                    maybe_const_itself, for_int_const, false);
     627                 :      76904 :       STRIP_TYPE_NOPS (op1);
     628                 :      76904 :       op2 = c_fully_fold_internal (op2, in_init, maybe_const_operands,
     629                 :            :                                    maybe_const_itself, for_int_const, false);
     630                 :      76904 :       STRIP_TYPE_NOPS (op2);
     631                 :            : 
     632                 :      76904 :       if (op0 != orig_op0 || op1 != orig_op1 || op2 != orig_op2)
     633                 :        324 :         ret = fold_build3_loc (loc, code, TREE_TYPE (expr), op0, op1, op2);
     634                 :            :       else
     635                 :      76580 :         ret = fold (expr);
     636                 :      76904 :       goto out;
     637                 :            : 
     638                 :          0 :     case EXCESS_PRECISION_EXPR:
     639                 :            :       /* Each case where an operand with excess precision may be
     640                 :            :          encountered must remove the EXCESS_PRECISION_EXPR around
     641                 :            :          inner operands and possibly put one around the whole
     642                 :            :          expression or possibly convert to the semantic type (which
     643                 :            :          c_fully_fold does); we cannot tell at this stage which is
     644                 :            :          appropriate in any particular case.  */
     645                 :          0 :       gcc_unreachable ();
     646                 :            : 
     647                 :     139671 :     case SAVE_EXPR:
     648                 :            :       /* Make sure to fold the contents of a SAVE_EXPR exactly once.  */
     649                 :     139671 :       op0 = TREE_OPERAND (expr, 0);
     650                 :     139671 :       if (!SAVE_EXPR_FOLDED_P (expr))
     651                 :            :         {
     652                 :      67156 :           op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
     653                 :            :                                        maybe_const_itself, for_int_const,
     654                 :            :                                        false);
     655                 :      67156 :           TREE_OPERAND (expr, 0) = op0;
     656                 :      67156 :           SAVE_EXPR_FOLDED_P (expr) = true;
     657                 :            :         }
     658                 :            :       /* Return the SAVE_EXPR operand if it is invariant.  */
     659                 :     139671 :       if (tree_invariant_p (op0))
     660                 :       3544 :         ret = op0;
     661                 :     139671 :       goto out;
     662                 :            : 
     663                 :       6118 :     default:
     664                 :            :       /* Various codes may appear through folding built-in functions
     665                 :            :          and their arguments.  */
     666                 :       6118 :       goto out;
     667                 :            :     }
     668                 :            : 
     669                 :  145703000 :  out:
     670                 :            :   /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
     671                 :            :      have been done by this point, so remove them again.  */
     672                 :  145703000 :   nowarning |= TREE_NO_WARNING (ret);
     673                 :  160666000 :   STRIP_TYPE_NOPS (ret);
     674                 :  145703000 :   if (nowarning && !TREE_NO_WARNING (ret))
     675                 :            :     {
     676                 :       8585 :       if (!CAN_HAVE_LOCATION_P (ret))
     677                 :        796 :         ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
     678                 :       8585 :       TREE_NO_WARNING (ret) = 1;
     679                 :            :     }
     680                 :  145703000 :   if (ret != expr)
     681                 :            :     {
     682                 :    9228560 :       protected_set_expr_location (ret, loc);
     683                 :    9228560 :       if (IS_EXPR_CODE_CLASS (kind))
     684                 :    9228560 :         set_source_range (ret, old_range.m_start, old_range.m_finish);
     685                 :            :     }
     686                 :            :   return ret;
     687                 :            : }
     688                 :            : 
     689                 :            : /* Fold X for consideration by one of the warning functions when checking
     690                 :            :    whether an expression has a constant value.  */
     691                 :            : 
     692                 :            : tree
     693                 :   70352600 : fold_for_warn (tree x)
     694                 :            : {
     695                 :            :   /* The C front-end has already folded X appropriately.  */
     696                 :   70352600 :   return x;
     697                 :            : }

Generated by: LCOV version 1.0

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto --enable-host-shared. GCC test suite is run with the built compiler.