LCOV - code coverage report
Current view: top level - gcc/fortran - convert.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 37 46 80.4 %
Date: 2020-03-28 11:57:23 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Data type conversion
       2                 :            :    Copyright (C) 1987-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                 :            : 
      21                 :            : /* This file contains the functions for converting expressions to
      22                 :            :    different data types for the translation of the gfortran internal
      23                 :            :    representation to GIMPLE.  The only entry point is `convert'.  */
      24                 :            : 
      25                 :            : #include "config.h"
      26                 :            : #include "system.h"
      27                 :            : #include "coretypes.h"
      28                 :            : #include "tree.h"
      29                 :            : #include "fold-const.h"
      30                 :            : #include "convert.h"
      31                 :            : 
      32                 :            : #include "gfortran.h"
      33                 :            : #include "trans.h"
      34                 :            : #include "trans-types.h"
      35                 :            : 
      36                 :            : /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
      37                 :            :    or validate its data type for a GIMPLE `if' or `while' statement.
      38                 :            : 
      39                 :            :    The resulting type should always be `logical_type_node'.  */
      40                 :            : 
      41                 :            : static tree
      42                 :      42875 : truthvalue_conversion (tree expr)
      43                 :            : {
      44                 :      42875 :   switch (TREE_CODE (TREE_TYPE (expr)))
      45                 :            :     {
      46                 :      42461 :     case BOOLEAN_TYPE:
      47                 :      42461 :       if (TREE_TYPE (expr) == logical_type_node)
      48                 :            :         return expr;
      49                 :      40689 :       else if (COMPARISON_CLASS_P (expr))
      50                 :            :         {
      51                 :          0 :           TREE_TYPE (expr) = logical_type_node;
      52                 :          0 :           return expr;
      53                 :            :         }
      54                 :      40689 :       else if (TREE_CODE (expr) == NOP_EXPR)
      55                 :          9 :         return fold_build1_loc (input_location, NOP_EXPR,
      56                 :            :                                 logical_type_node,
      57                 :         18 :                                 TREE_OPERAND (expr, 0));
      58                 :            :       else
      59                 :      40680 :         return fold_build1_loc (input_location, NOP_EXPR,
      60                 :            :                                 logical_type_node,
      61                 :      40680 :                                 expr);
      62                 :            : 
      63                 :        414 :     case INTEGER_TYPE:
      64                 :        414 :       if (TREE_CODE (expr) == INTEGER_CST)
      65                 :          0 :         return integer_zerop (expr) ? logical_false_node
      66                 :            :           : logical_true_node;
      67                 :            :       else
      68                 :        414 :         return fold_build2_loc (input_location, NE_EXPR,
      69                 :            :                                 logical_type_node,
      70                 :        414 :                                 expr, build_int_cst (TREE_TYPE (expr), 0));
      71                 :            : 
      72                 :          0 :     default:
      73                 :          0 :       gcc_unreachable ();
      74                 :            :     }
      75                 :            : }
      76                 :            : 
      77                 :            : /* Create an expression whose value is that of EXPR,
      78                 :            :    converted to type TYPE.  The TREE_TYPE of the value
      79                 :            :    is always TYPE.  This function implements all reasonable
      80                 :            :    conversions; callers should filter out those that are
      81                 :            :    not permitted by the language being compiled.  */
      82                 :            : 
      83                 :            : tree
      84                 :     628450 : convert (tree type, tree expr)
      85                 :            : {
      86                 :     628450 :   tree e = expr;
      87                 :     628450 :   enum tree_code code;
      88                 :            : 
      89                 :     628450 :   if (type == TREE_TYPE (expr))
      90                 :            :     return expr;
      91                 :            : 
      92                 :     355652 :   if (TREE_CODE (type) == ERROR_MARK
      93                 :     355652 :       || TREE_CODE (expr) == ERROR_MARK
      94                 :     711304 :       || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
      95                 :            :     return expr;
      96                 :            : 
      97                 :     355652 :   gcc_checking_assert (TREE_CODE (TREE_TYPE (expr)) != VOID_TYPE);
      98                 :            : 
      99                 :     355652 :   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
     100                 :       1568 :     return fold_build1_loc (input_location, NOP_EXPR, type, expr);
     101                 :            : 
     102                 :     354084 :   code = TREE_CODE (type);
     103                 :     354084 :   if (code == VOID_TYPE)
     104                 :          0 :     return fold_build1_loc (input_location, CONVERT_EXPR, type, e);
     105                 :     354084 :   if (code == BOOLEAN_TYPE)
     106                 :      42875 :     return fold_build1_loc (input_location, NOP_EXPR, type,
     107                 :      42875 :                             truthvalue_conversion (e));
     108                 :     311209 :   if (code == INTEGER_TYPE)
     109                 :     202131 :     return fold (convert_to_integer (type, e));
     110                 :     109078 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE)
     111                 :      98166 :     return fold (convert_to_pointer (type, e));
     112                 :      10912 :   if (code == REAL_TYPE)
     113                 :       9627 :     return fold (convert_to_real (type, e));
     114                 :       1285 :   if (code == COMPLEX_TYPE)
     115                 :       1285 :     return fold (convert_to_complex (type, e));
     116                 :          0 :   if (code == VECTOR_TYPE)
     117                 :          0 :     return fold (convert_to_vector (type, e));
     118                 :            : 
     119                 :          0 :   gcc_unreachable ();
     120                 :            : }
     121                 :            : 

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.