LCOV - code coverage report
Current view: top level - gcc/c-family - c-semantics.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 72 80 90.0 %
Date: 2020-03-28 11:57:23 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* This file contains subroutine used by the C front-end to construct GENERIC.
       2                 :            :    Copyright (C) 2000-2020 Free Software Foundation, Inc.
       3                 :            :    Written by Benjamin Chelf (chelf@codesourcery.com).
       4                 :            : 
       5                 :            : This file is part of GCC.
       6                 :            : 
       7                 :            : GCC is free software; you can redistribute it and/or modify it under
       8                 :            : the terms of the GNU General Public License as published by the Free
       9                 :            : Software Foundation; either version 3, or (at your option) any later
      10                 :            : version.
      11                 :            : 
      12                 :            : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :            : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :            : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :            : for more details.
      16                 :            : 
      17                 :            : You should have received a copy of the GNU General Public License
      18                 :            : along with GCC; see the file COPYING3.  If not see
      19                 :            : <http://www.gnu.org/licenses/>.  */
      20                 :            : 
      21                 :            : #include "config.h"
      22                 :            : #include "system.h"
      23                 :            : #include "coretypes.h"
      24                 :            : #include "c-common.h"
      25                 :            : #include "tree-iterator.h"
      26                 :            : 
      27                 :            : /* Create an empty statement tree rooted at T.  */
      28                 :            : 
      29                 :            : tree
      30                 :  109346000 : push_stmt_list (void)
      31                 :            : {
      32                 :  109346000 :   tree t;
      33                 :  109346000 :   t = alloc_stmt_list ();
      34                 :  109346000 :   vec_safe_push (stmt_list_stack, t);
      35                 :  109346000 :   return t;
      36                 :            : }
      37                 :            : 
      38                 :            : /* Return TRUE if, after I, there are any nondebug stmts.  */
      39                 :            : 
      40                 :            : static inline bool
      41                 :   11224500 : only_debug_stmts_after_p (tree_stmt_iterator i)
      42                 :            : {
      43                 :   14064500 :   for (tsi_next (&i); !tsi_end_p (i); tsi_next (&i))
      44                 :    5753520 :     if (TREE_CODE (tsi_stmt (i)) != DEBUG_BEGIN_STMT)
      45                 :            :       return false;
      46                 :            :   return true;
      47                 :            : }
      48                 :            : 
      49                 :            : /* Finish the statement tree rooted at T.  */
      50                 :            : 
      51                 :            : tree
      52                 :  107547000 : pop_stmt_list (tree t)
      53                 :            : {
      54                 :  107547000 :   tree u = NULL_TREE;
      55                 :            : 
      56                 :            :   /* Pop statement lists until we reach the target level.  The extra
      57                 :            :      nestings will be due to outstanding cleanups.  */
      58                 :  109345000 :   while (1)
      59                 :            :     {
      60                 :  109345000 :       u = stmt_list_stack->pop ();
      61                 :  109345000 :       if (!stmt_list_stack->is_empty ())
      62                 :            :         {
      63                 :   69153500 :           tree x = stmt_list_stack->last ();
      64                 :   69153500 :           STATEMENT_LIST_HAS_LABEL (x) |= STATEMENT_LIST_HAS_LABEL (u);
      65                 :            :         }
      66                 :  109345000 :       if (t == u)
      67                 :            :         break;
      68                 :            :     }
      69                 :            : 
      70                 :  107547000 :   gcc_assert (u != NULL_TREE);
      71                 :            : 
      72                 :            :   /* If the statement list is completely empty, just return it.  This is
      73                 :            :      just as good small as build_empty_stmt, with the advantage that
      74                 :            :      statement lists are merged when they appended to one another.  So
      75                 :            :      using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
      76                 :            :      statements.  */
      77                 :  107547000 :   if (TREE_SIDE_EFFECTS (t))
      78                 :            :     {
      79                 :  100618000 :       tree_stmt_iterator i = tsi_start (t);
      80                 :            : 
      81                 :            :       /* If the statement list contained exactly one statement, then
      82                 :            :          extract it immediately.  */
      83                 :  100618000 :       if (tsi_one_before_end_p (i))
      84                 :            :         {
      85                 :   80639600 :           u = tsi_stmt (i);
      86                 :   80639600 :           tsi_delink (&i);
      87                 :   80639600 :           free_stmt_list (t);
      88                 :   80639600 :           t = u;
      89                 :            :         }
      90                 :            :       /* If the statement list contained a debug begin stmt and a
      91                 :            :          statement list, move the debug begin stmt into the statement
      92                 :            :          list and return it.  */
      93                 :   19978500 :       else if (!tsi_end_p (i)
      94                 :   19978500 :                && TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT)
      95                 :            :         {
      96                 :   11224600 :           u = tsi_stmt (i);
      97                 :   11224600 :           tsi_next (&i);
      98                 :   22449300 :           if (tsi_one_before_end_p (i)
      99                 :    8121870 :               && TREE_CODE (tsi_stmt (i)) == STATEMENT_LIST)
     100                 :            :             {
     101                 :          0 :               tree l = tsi_stmt (i);
     102                 :          0 :               tsi_prev (&i);
     103                 :          0 :               tsi_delink (&i);
     104                 :          0 :               tsi_delink (&i);
     105                 :          0 :               i = tsi_start (l);
     106                 :          0 :               free_stmt_list (t);
     107                 :          0 :               t = l;
     108                 :          0 :               tsi_link_before (&i, u, TSI_SAME_STMT);
     109                 :            :             }
     110                 :   11598300 :           while (!tsi_end_p (i)
     111                 :   11598300 :                  && TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT)
     112                 :     373697 :             tsi_next (&i);
     113                 :            :           /* If there are only debug stmts in the list, without them
     114                 :            :              we'd have an empty stmt without side effects.  If there's
     115                 :            :              only one nondebug stmt, we'd have extracted the stmt and
     116                 :            :              dropped the list, and we'd take TREE_SIDE_EFFECTS from
     117                 :            :              that statement.  In either case, keep the list's
     118                 :            :              TREE_SIDE_EFFECTS in sync.  */
     119                 :   11224600 :           if (tsi_end_p (i))
     120                 :        119 :             TREE_SIDE_EFFECTS (t) = 0;
     121                 :   22449000 :           else if (only_debug_stmts_after_p (i))
     122                 :    8310960 :             TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (tsi_stmt (i));
     123                 :            :         }
     124                 :            :     }
     125                 :            : 
     126                 :  107547000 :   return t;
     127                 :            : }
     128                 :            : 
     129                 :            : /* Build a generic statement based on the given type of node and
     130                 :            :    arguments. Similar to `build_nt', except that we set
     131                 :            :    EXPR_LOCATION to LOC. */
     132                 :            : /* ??? This should be obsolete with the lineno_stmt productions
     133                 :            :    in the grammar.  */
     134                 :            : 
     135                 :            : tree
     136                 :   67594800 : build_stmt (location_t loc, enum tree_code code, ...)
     137                 :            : {
     138                 :   67594800 :   tree ret;
     139                 :   67594800 :   int length, i;
     140                 :   67594800 :   va_list p;
     141                 :   67594800 :   bool side_effects;
     142                 :            : 
     143                 :            :   /* This function cannot be used to construct variably-sized nodes.  */
     144                 :   67594800 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
     145                 :            : 
     146                 :   67594800 :   va_start (p, code);
     147                 :            : 
     148                 :   67594800 :   ret = make_node (code);
     149                 :   67594800 :   TREE_TYPE (ret) = void_type_node;
     150                 :   67594800 :   length = TREE_CODE_LENGTH (code);
     151                 :   67594800 :   SET_EXPR_LOCATION (ret, loc);
     152                 :            : 
     153                 :            :   /* TREE_SIDE_EFFECTS will already be set for statements with
     154                 :            :      implicit side effects.  Here we make sure it is set for other
     155                 :            :      expressions by checking whether the parameters have side
     156                 :            :      effects.  */
     157                 :            : 
     158                 :   67594800 :   side_effects = false;
     159                 :  157990000 :   for (i = 0; i < length; i++)
     160                 :            :     {
     161                 :   90395500 :       tree t = va_arg (p, tree);
     162                 :   90395500 :       if (t && !TYPE_P (t))
     163                 :   62671700 :         side_effects |= TREE_SIDE_EFFECTS (t);
     164                 :   90395500 :       TREE_OPERAND (ret, i) = t;
     165                 :            :     }
     166                 :            : 
     167                 :   67594800 :   TREE_SIDE_EFFECTS (ret) |= side_effects;
     168                 :            : 
     169                 :   67594800 :   va_end (p);
     170                 :   67594800 :   return ret;
     171                 :            : }
     172                 :            : 
     173                 :            : /* Build a REALPART_EXPR or IMAGPART_EXPR, according to CODE, from ARG.  */
     174                 :            : 
     175                 :            : tree
     176                 :     305984 : build_real_imag_expr (location_t location, enum tree_code code, tree arg)
     177                 :            : {
     178                 :     305984 :   tree ret;
     179                 :     305984 :   tree arg_type = TREE_TYPE (arg);
     180                 :            : 
     181                 :     305984 :   gcc_assert (code == REALPART_EXPR || code == IMAGPART_EXPR);
     182                 :            : 
     183                 :     305984 :   if (TREE_CODE (arg_type) == COMPLEX_TYPE)
     184                 :            :     {
     185                 :     298220 :       ret = build1 (code, TREE_TYPE (TREE_TYPE (arg)), arg);
     186                 :     298220 :       SET_EXPR_LOCATION (ret, location);
     187                 :            :     }
     188                 :       7764 :   else if (INTEGRAL_TYPE_P (arg_type) || SCALAR_FLOAT_TYPE_P (arg_type))
     189                 :            :     {
     190                 :       7752 :       ret = (code == REALPART_EXPR
     191                 :       7752 :              ? arg
     192                 :       3871 :              : omit_one_operand_loc (location, arg_type,
     193                 :            :                                      integer_zero_node, arg));
     194                 :            :     }
     195                 :            :   else
     196                 :            :     {
     197                 :         18 :       error_at (location, "wrong type argument to %s",
     198                 :            :                 code == REALPART_EXPR ? "__real" : "__imag");
     199                 :         12 :       ret = error_mark_node;
     200                 :            :     }
     201                 :            : 
     202                 :     305984 :   return ret;
     203                 :            : }

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.