LCOV - code coverage report
Current view: top level - gcc/sym-exec - sym-exec-expression.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 39.0 % 182 71
Test Date: 2026-02-28 14:20:25 Functions: 42.2 % 45 19
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Every class defined here represents a single bit value of a variable.
       2              :    Every variable will be represented as a vector of these classes which later
       3              :    will be used for bit-level symbolic execution.
       4              :    Copyright (C) 2022-2026 Free Software Foundation, Inc.
       5              :    Contributed by Matevos Mehrabyan <matevosmehrabyan@gmail.com>
       6              : 
       7              : This file is part of GCC.
       8              : 
       9              : GCC is free software; you can redistribute it and/or modify it under
      10              : the terms of the GNU General Public License as published by the Free
      11              : Software Foundation; either version 3, or (at your option) any later
      12              : version.
      13              : 
      14              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      15              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      16              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      17              : for more details.
      18              : 
      19              : You should have received a copy of the GNU General Public License
      20              : along with GCC; see the file COPYING3.  If not see
      21              : <http://www.gnu.org/licenses/>.  */
      22              : 
      23              : #include "sym-exec-expr-is-a-helper.h"
      24              : 
      25              : /* Returns type of the bit.  */
      26              : 
      27              : value_type
      28     21059212 : value_bit::get_type () const
      29              : {
      30     21059212 :   return m_type;
      31              : }
      32              : 
      33              : 
      34              : /* Constructor that sets the bit's initial position and its origin.  */
      35              : 
      36     10085565 : symbolic_bit::symbolic_bit (size_t i, tree orig)
      37     10085565 :     : value_bit (i), m_origin (orig)
      38              : {
      39     10085565 :   m_type = SYMBOLIC_BIT;
      40     10085565 : }
      41              : 
      42              : 
      43              : /* Constructor that sets m_val to the specified value.  */
      44              : 
      45     12209630 : bit::bit (unsigned char i) : m_val (i)
      46              : {
      47     12209630 :   m_type = BIT;
      48     12209630 : }
      49              : 
      50              : 
      51              : /* Returns left operand of the expression.  */
      52              : 
      53              : value_bit *
      54       123567 : bit_expression::get_left ()
      55              : {
      56       123567 :   return m_left;
      57              : }
      58              : 
      59              : 
      60              : /* Returns right operand of the expression.  */
      61              : 
      62              : value_bit *
      63        55712 : bit_expression::get_right ()
      64              : {
      65        55712 :   return m_right;
      66              : }
      67              : 
      68              : 
      69              : /* Sets left operand of the expression.  */
      70              : 
      71              : void
      72            0 : bit_expression::set_left (value_bit *expr)
      73              : {
      74            0 :   m_left = expr;
      75            0 : }
      76              : 
      77              : 
      78              : /* Sets right operand of the expression.  */
      79              : 
      80              : void
      81            0 : bit_expression::set_right (value_bit *expr)
      82              : {
      83            0 :   m_right = expr;
      84            0 : }
      85              : 
      86              : 
      87              : /* Returns the bit's initial index in bit-vector.  */
      88              : 
      89              : size_t
      90       418206 : value_bit::get_index () const
      91              : {
      92       418206 :   return m_index;
      93              : }
      94              : 
      95              : 
      96              : /* Returns the value of the bit.  */
      97              : 
      98              : unsigned char
      99      8882866 : bit::get_val () const
     100              : {
     101      8882866 :   return m_val;
     102              : }
     103              : 
     104              : 
     105              : /* Sets the value of the bit.  */
     106              : 
     107              : void
     108            0 : bit::set_val (unsigned char new_val)
     109              : {
     110            0 :   m_val = new_val;
     111            0 : }
     112              : 
     113              : 
     114              : /* Constructor that sets the left and right side bits
     115              :    of the bit_complement_expression sign.  */
     116              : 
     117            0 : bit_complement_expression::bit_complement_expression (value_bit *right)
     118              : {
     119              :   /* As complement has only one argument, we use only the m_right.  */
     120            0 :   this->m_left = nullptr;
     121            0 :   this->m_right = right;
     122            0 :   m_type = BIT_COMPLEMENT_EXPRESSION;
     123            0 : }
     124              : 
     125              : 
     126              : /* Copy constructor for bit_complement_expression.  */
     127              : 
     128            0 : bit_complement_expression::bit_complement_expression (
     129            0 :   const bit_complement_expression &expr)
     130              : {
     131            0 :   bit_expression::copy (&expr);
     132            0 : }
     133              : 
     134              : 
     135              : /* Destructor for bit_expression.  */
     136              : 
     137      1166544 : bit_expression::~bit_expression ()
     138              : {
     139      1166544 :   delete m_left;
     140      1166544 :   m_left = nullptr;
     141      1166544 :   delete m_right;
     142      1166544 :   m_right = nullptr;
     143      1166544 : }
     144              : 
     145              : 
     146              : /* Returns a copy of the bit.  */
     147              : 
     148              : value_bit *
     149      8420413 : symbolic_bit::copy () const
     150              : {
     151      8420413 :   return new symbolic_bit (*this);
     152              : }
     153              : 
     154              : 
     155              : /* Return a copy of the bit.  */
     156              : 
     157              : value_bit *
     158      6257849 : bit::copy () const
     159              : {
     160      6257849 :   return new bit (*this);
     161              : }
     162              : 
     163              : 
     164              : /* Copies the given expression to it by copying the left and right operands.  */
     165              : 
     166              : void
     167      1066138 : bit_expression::copy (const bit_expression *expr)
     168              : {
     169      1066138 :   if (expr->m_left)
     170      1066138 :     m_left = expr->m_left->copy ();
     171              : 
     172      1066138 :   if (expr->m_right)
     173      1066138 :     m_right = expr->m_right->copy ();
     174              : 
     175      1066138 :   m_type = expr->m_type;
     176      1066138 : }
     177              : 
     178              : 
     179              : /* Returns a copy of the expression.  */
     180              : 
     181              : value_bit *
     182      1059828 : bit_xor_expression::copy () const
     183              : {
     184      1059828 :   return new bit_xor_expression (*this);
     185              : }
     186              : 
     187              : 
     188              : /* Returns a copy of the expression.  */
     189              : 
     190              : value_bit *
     191            0 : bit_and_expression::copy () const
     192              : {
     193            0 :   return new bit_and_expression (*this);
     194              : }
     195              : 
     196              : 
     197              : /* Returns a copy of the expression.  */
     198              : 
     199              : value_bit *
     200            0 : bit_or_expression::copy () const
     201              : {
     202            0 :   return new bit_or_expression (*this);
     203              : }
     204              : 
     205              : 
     206              : /* Returns a copy of the expression.  */
     207              : 
     208              : value_bit *
     209            0 : shift_right_expression::copy () const
     210              : {
     211            0 :   return new shift_right_expression (*this);
     212              : }
     213              : 
     214              : 
     215              : /* Returns a copy of the expression.  */
     216              : 
     217              : value_bit *
     218            0 : shift_left_expression::copy () const
     219              : {
     220            0 :   return new shift_left_expression (*this);
     221              : }
     222              : 
     223              : 
     224              : /* Returns a copy of the expression.  */
     225              : 
     226              : value_bit *
     227            0 : add_expression::copy () const
     228              : {
     229            0 :   return new add_expression (*this);
     230              : }
     231              : 
     232              : 
     233              : /* Returns a copy of the expression.  */
     234              : 
     235              : value_bit *
     236            0 : sub_expression::copy () const
     237              : {
     238            0 :   return new sub_expression (*this);
     239              : }
     240              : 
     241              : 
     242              : /* Returns a copy of the expression.  */
     243              : 
     244              : value_bit *
     245            0 : bit_complement_expression::copy () const
     246              : {
     247            0 :   return new bit_complement_expression (*this);
     248              : }
     249              : 
     250              : 
     251              : /* Constructor that sets the left and right side bits
     252              :    of the bit_xor_expression sign.  */
     253              : 
     254        94096 : bit_xor_expression::bit_xor_expression (value_bit *left, value_bit *right)
     255              : {
     256        94096 :   this->m_left = left;
     257        94096 :   this->m_right = right;
     258        94096 :   m_type = BIT_XOR_EXPRESSION;
     259        94096 : }
     260              : 
     261              : 
     262              : /* Copy constructor for bit_xor_expression.  */
     263              : 
     264      1059828 : bit_xor_expression::bit_xor_expression (const bit_xor_expression &expr)
     265              : {
     266      1059828 :   bit_expression::copy (&expr);
     267      1059828 : }
     268              : 
     269              : 
     270              : /* Constructor that sets the left and right side bits
     271              :    of the bit_and_expression sign.  */
     272              : 
     273            0 : bit_and_expression::bit_and_expression (value_bit *left, value_bit *right)
     274              : {
     275            0 :   this->m_left = left;
     276            0 :   this->m_right = right;
     277            0 :   m_type = BIT_AND_EXPRESSION;
     278            0 : }
     279              : 
     280              : 
     281              : /* Copy constructor for bit_and_expression.  */
     282              : 
     283            0 : bit_and_expression::bit_and_expression (const bit_and_expression &expr)
     284              : {
     285            0 :   bit_expression::copy (&expr);
     286            0 : }
     287              : 
     288              : 
     289              : /* Constructor that sets the left and right side bits
     290              :    of the bit_or_expression sign.  */
     291              : 
     292            0 : bit_or_expression::bit_or_expression (value_bit *left, value_bit *right)
     293              : {
     294            0 :   this->m_left = left;
     295            0 :   this->m_right = right;
     296            0 :   m_type = BIT_OR_EXPRESSION;
     297            0 : }
     298              : 
     299              : 
     300              : /* Copy constructor for bit_or_expression.  */
     301              : 
     302            0 : bit_or_expression::bit_or_expression (const bit_or_expression &expr)
     303              : {
     304            0 :   bit_expression::copy (&expr);
     305            0 : }
     306              : 
     307              : 
     308              : /* Constructor that sets the left and right side bits
     309              :    of the shift_right_expression sign.  */
     310              : 
     311            0 : shift_right_expression::shift_right_expression (value_bit *left,
     312            0 :                                                 value_bit *right)
     313              : {
     314            0 :   this->m_left = left;
     315            0 :   this->m_right = right;
     316            0 :   m_type = SHIFT_RIGHT_EXPRESSION;
     317            0 : }
     318              : 
     319              : 
     320              : /* Copy constructor for shift_right_expression.  */
     321              : 
     322            0 : shift_right_expression::shift_right_expression (
     323            0 :   const shift_right_expression &expr)
     324              : {
     325            0 :   bit_expression::copy (&expr);
     326            0 : }
     327              : 
     328              : 
     329              : /* Constructor that sets the left and right side bits
     330              :    of the shift_left_expression sign.  */
     331              : 
     332            0 : shift_left_expression::shift_left_expression (value_bit *left, value_bit *right)
     333              : {
     334            0 :   this->m_left = left;
     335            0 :   this->m_right = right;
     336            0 :   m_type = SHIFT_LEFT_EXPRESSION;
     337            0 : }
     338              : 
     339              : 
     340              : /* Copy constructor for shift_left_expression.  */
     341              : 
     342            0 : shift_left_expression::shift_left_expression (const shift_left_expression &expr)
     343              : {
     344            0 :   bit_expression::copy (&expr);
     345            0 : }
     346              : 
     347              : 
     348              : /* Constructor that sets the left and right side bits
     349              :    of the add_expression sign.  */
     350              : 
     351            0 : add_expression::add_expression (value_bit *left, value_bit *right)
     352              : {
     353            0 :   this->m_left = left;
     354            0 :   this->m_right = right;
     355            0 :   m_type = ADD_EXPRESSION;
     356            0 : }
     357              : 
     358              : 
     359              : /* Copy constructor for add_expression.  */
     360              : 
     361            0 : add_expression::add_expression (const add_expression &expr)
     362              : {
     363            0 :   bit_expression::copy (&expr);
     364            0 : }
     365              : 
     366              : 
     367              : /* Constructor that sets the left and right side bits
     368              :    of the sub_expression sign.  */
     369              : 
     370            0 : sub_expression::sub_expression (value_bit *left, value_bit *right)
     371              : {
     372            0 :   this->m_left = left;
     373            0 :   this->m_right = right;
     374            0 :   m_type = SUB_EXPRESSION;
     375            0 : }
     376              : 
     377              : 
     378              : /* Copy constructor for sub_expression.  */
     379              : 
     380            0 : sub_expression::sub_expression (const sub_expression &expr)
     381              : {
     382            0 :   bit_expression::copy (&expr);
     383            0 : }
     384              : 
     385              : 
     386              : /* Returns the origin of the bit, to whom it belongs.  */
     387              : 
     388              : tree
     389       222068 : symbolic_bit::get_origin ()
     390              : {
     391       222068 :   return m_origin;
     392              : }
     393              : 
     394              : 
     395              : /* Prints the bit.  */
     396              : 
     397              : void
     398       842584 : symbolic_bit::print ()
     399              : {
     400       842584 :   if (dump_file)
     401              :     {
     402       842584 :       print_generic_expr (dump_file, m_origin, dump_flags);
     403       842584 :       fprintf (dump_file, "[%zu]", m_index);
     404              :     }
     405       842584 : }
     406              : 
     407              : 
     408              : /* Prints the bit.  */
     409              : 
     410              : void
     411       829973 : bit::print ()
     412              : {
     413       829973 :   if (dump_file)
     414       829973 :     fprintf (dump_file, "%u", m_val);
     415       829973 : }
     416              : 
     417              : 
     418              : /* Depending on the expression, prints its sign.  */
     419              : 
     420              : void
     421       180141 : bit_expression::print_expr_sign ()
     422              : {
     423       180141 :   switch (m_type)
     424              :     {
     425       180141 :       case BIT_XOR_EXPRESSION:
     426       180141 :         fprintf (dump_file, " ^ ");
     427       180141 :         break;
     428            0 :       case BIT_AND_EXPRESSION:
     429            0 :         fprintf (dump_file, " & ");
     430            0 :         break;
     431            0 :       case BIT_OR_EXPRESSION:
     432            0 :         fprintf (dump_file, " | ");
     433            0 :         break;
     434            0 :       case SHIFT_RIGHT_EXPRESSION:
     435            0 :         fprintf (dump_file, " >> ");
     436            0 :         break;
     437            0 :       case SHIFT_LEFT_EXPRESSION:
     438            0 :         fprintf (dump_file, " << ");
     439            0 :         break;
     440            0 :       case ADD_EXPRESSION:
     441            0 :         fprintf (dump_file, " + ");
     442            0 :         break;
     443            0 :       case SUB_EXPRESSION:
     444            0 :         fprintf (dump_file, " - ");
     445            0 :         break;
     446            0 :       default:
     447            0 :         fprintf (dump_file, " ?? ");
     448              :     }
     449       180141 : }
     450              : 
     451              : 
     452              : /* Prints the expression.  */
     453              : 
     454              : void
     455       190765 : bit_expression::print ()
     456              : {
     457       190765 :   if (dump_file)
     458              :     {
     459       190765 :       fprintf (dump_file, "(");
     460       190765 :       if (m_left)
     461       190765 :         m_left->print ();
     462              :       else
     463            0 :         fprintf (dump_file, "null");
     464              : 
     465       190765 :       print_expr_sign ();
     466              : 
     467       190765 :       if (m_right)
     468       190765 :         m_right->print ();
     469              :       else
     470            0 :         fprintf (dump_file, "null");
     471              : 
     472       190765 :       fprintf (dump_file, ")");
     473              :     }
     474       190765 : }
     475              : 
     476              : 
     477              : /* Prints the expression.  */
     478              : 
     479              : void
     480            0 : bit_complement_expression::print ()
     481              : {
     482            0 :   if (dump_file)
     483              :     {
     484            0 :       fprintf (dump_file, "!");
     485            0 :       if (m_right)
     486            0 :         m_right->print ();
     487              :       else
     488            0 :         fprintf (dump_file, "null");
     489              :     }
     490            0 : }
        

Generated by: LCOV version 2.4-beta

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,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.