LCOV - code coverage report
Current view: top level - gcc - selftest-rtl.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 23 39 59.0 %
Date: 2020-04-04 11:58:09 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Selftest support for RTL.
       2                 :            :    Copyright (C) 2016-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 "selftest.h"
      24                 :            : #include "backend.h"
      25                 :            : #include "target.h"
      26                 :            : #include "rtl.h"
      27                 :            : #include "read-rtl-function.h"
      28                 :            : #include "read-md.h"
      29                 :            : #include "tree-core.h"
      30                 :            : #include "memmodel.h"
      31                 :            : #include "emit-rtl.h"
      32                 :            : #include "selftest-rtl.h"
      33                 :            : 
      34                 :            : #if CHECKING_P
      35                 :            : 
      36                 :            : namespace selftest {
      37                 :            : 
      38                 :            : /* Compare rtx EXPECTED and ACTUAL using rtx_equal_p, calling
      39                 :            :    ::selftest::pass if they are equal, aborting if they are non-equal.
      40                 :            :    LOC is the effective location of the assertion, MSG describes it.  */
      41                 :            : 
      42                 :            : void
      43                 :      17474 : assert_rtx_eq_at (const location &loc, const char *msg,
      44                 :            :                   rtx expected, rtx actual)
      45                 :            : {
      46                 :      17474 :   if (rtx_equal_p (expected, actual))
      47                 :      17474 :     ::selftest::pass (loc, msg);
      48                 :            :   else
      49                 :            :     {
      50                 :          0 :       fprintf (stderr, "%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line,
      51                 :          0 :                loc.m_function, msg);
      52                 :          0 :       fprintf (stderr, "  expected: ");
      53                 :          0 :       print_rtl (stderr, expected);
      54                 :          0 :       fprintf (stderr, "\n  actual: ");
      55                 :          0 :       print_rtl (stderr, actual);
      56                 :          0 :       fprintf (stderr, "\n");
      57                 :          0 :       abort ();
      58                 :            :     }
      59                 :      17474 : }
      60                 :            : 
      61                 :            : /* Compare rtx EXPECTED and ACTUAL by pointer equality, calling
      62                 :            :    ::selftest::pass if they are equal, aborting if they are non-equal.
      63                 :            :    LOC is the effective location of the assertion, MSG describes it.  */
      64                 :            : 
      65                 :            : void
      66                 :        260 : assert_rtx_ptr_eq_at (const location &loc, const char *msg,
      67                 :            :                       rtx expected, rtx actual)
      68                 :            : {
      69                 :        260 :   if (expected == actual)
      70                 :        260 :     ::selftest::pass (loc, msg);
      71                 :            :   else
      72                 :            :     {
      73                 :          0 :       fprintf (stderr, "%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line,
      74                 :          0 :                loc.m_function, msg);
      75                 :          0 :       fprintf (stderr, "  expected (at %p): ", (void *)expected);
      76                 :          0 :       print_rtl (stderr, expected);
      77                 :          0 :       fprintf (stderr, "\n  actual (at %p): ", (void *)actual);
      78                 :          0 :       print_rtl (stderr, actual);
      79                 :          0 :       fprintf (stderr, "\n");
      80                 :          0 :       abort ();
      81                 :            :     }
      82                 :        260 : }
      83                 :            : 
      84                 :            : /* Constructor for selftest::rtl_dump_test.
      85                 :            :    Read a dumped RTL function from PATH.
      86                 :            :    Takes ownership of PATH, freeing in dtor.
      87                 :            :    Use LOC as the effective location when reporting failures.  */
      88                 :            : 
      89                 :         38 : rtl_dump_test::rtl_dump_test (const location &loc, char *path)
      90                 :         38 :   : m_path (path)
      91                 :            : {
      92                 :         38 :   bool read_ok = read_rtl_function_body (path);
      93                 :         38 :   ASSERT_TRUE_AT (loc, read_ok);
      94                 :         38 : }
      95                 :            : 
      96                 :            : /* Destructor for selftest::rtl_dump_test.
      97                 :            :    Cleanup global state relating to the function, and free the path.  */
      98                 :            : 
      99                 :         76 : selftest::rtl_dump_test::~rtl_dump_test ()
     100                 :            : {
     101                 :            :   /* Cleanups.  */
     102                 :         38 :   current_function_decl = NULL;
     103                 :         38 :   free_after_compilation (cfun);
     104                 :         38 :   set_cfun (NULL);
     105                 :         38 :   free (m_path);
     106                 :         38 : }
     107                 :            : 
     108                 :            : /* Get the insn with the given uid, or NULL if not found.  */
     109                 :            : 
     110                 :            : rtx_insn *
     111                 :         50 : get_insn_by_uid (int uid)
     112                 :            : {
     113                 :        162 :   for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
     114                 :        106 :     if (INSN_UID (insn) == uid)
     115                 :         50 :       return insn;
     116                 :            : 
     117                 :            :   /* Not found.  */
     118                 :            :   return NULL;
     119                 :            : }
     120                 :            : 
     121                 :            : } // namespace selftest
     122                 :            : 
     123                 :            : #endif /* #if CHECKING_P */

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.