LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-compile-intrinsic.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 71.4 % 14 10
Test Date: 2026-07-11 15:47:05 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // This file is part of GCC.
       2              : 
       3              : // GCC is free software; you can redistribute it and/or modify it under
       4              : // the terms of the GNU General Public License as published by the Free
       5              : // Software Foundation; either version 3, or (at your option) any later
       6              : // version.
       7              : 
       8              : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
       9              : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      10              : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      11              : // for more details.
      12              : 
      13              : // You should have received a copy of the GNU General Public License
      14              : // along with GCC; see the file COPYING3.  If not see
      15              : // <http://www.gnu.org/licenses/>.
      16              : 
      17              : #include "rust-compile-intrinsic.h"
      18              : #include "rust-compile-context.h"
      19              : #include "rust-builtins.h"
      20              : #include "rust-diagnostics.h"
      21              : #include "tree-core.h"
      22              : #include "rust-intrinsic-handlers.h"
      23              : #include "rust-intrinsic-values.h"
      24              : 
      25              : namespace Rust {
      26              : namespace Compile {
      27              : 
      28              : using IValue = Values::Intrinsics;
      29              : 
      30              : static const std::map<std::string, handlers::HandlerBuilder> generic_intrinsics
      31              :   = {{IValue::OFFSET, handlers::offset},
      32              :      {IValue::ARITH_OFFSET, handlers::arith_offset_handler},
      33              :      {IValue::WRITE_BYTES, handlers::write_bytes_handler},
      34              :      {IValue::SIZE_OF, handlers::sizeof_handler},
      35              :      {IValue::SIZE_OF_VAL, handlers::size_of_val_handler},
      36              :      {IValue::MIN_ALIGN_OF, handlers::min_align_of_handler},
      37              :      {IValue::MIN_ALIGN_OF_VAL, handlers::min_align_of_val_handler},
      38              :      {IValue::TRANSMUTE, handlers::transmute},
      39              :      {IValue::ROTATE_LEFT, handlers::rotate_left},
      40              :      {IValue::ROTATE_RIGHT, handlers::rotate_right},
      41              :      {IValue::WRAPPING_ADD, handlers::wrapping_op (PLUS_EXPR)},
      42              :      {IValue::WRAPPING_SUB, handlers::wrapping_op (MINUS_EXPR)},
      43              :      {IValue::WRAPPING_MUL, handlers::wrapping_op (MULT_EXPR)},
      44              :      {IValue::ADD_WITH_OVERFLOW, handlers::op_with_overflow (PLUS_EXPR)},
      45              :      {IValue::SUB_WITH_OVERFLOW, handlers::op_with_overflow (MINUS_EXPR)},
      46              :      {IValue::MUL_WITH_OVERFLOW, handlers::op_with_overflow (MULT_EXPR)},
      47              :      {IValue::COPY, handlers::copy (true)},
      48              :      {IValue::COPY_NONOVERLAPPING, handlers::copy (false)},
      49              :      {IValue::PREFETCH_READ_DATA, handlers::prefetch_read_data},
      50              :      {IValue::PREFETCH_WRITE_DATA, handlers::prefetch_write_data},
      51              :      {IValue::ATOMIC_STORE_SEQCST, handlers::atomic_store (__ATOMIC_SEQ_CST)},
      52              :      {IValue::ATOMIC_STORE_RELEASE, handlers::atomic_store (__ATOMIC_RELEASE)},
      53              :      {IValue::ATOMIC_STORE_RELAXED, handlers::atomic_store (__ATOMIC_RELAXED)},
      54              :      {IValue::ATOMIC_STORE_UNORDERED,
      55              :       handlers::atomic_store (__ATOMIC_RELAXED)},
      56              :      {IValue::ATOMIC_LOAD_SEQCST, handlers::atomic_load (__ATOMIC_SEQ_CST)},
      57              :      {IValue::ATOMIC_LOAD_ACQUIRE, handlers::atomic_load (__ATOMIC_ACQUIRE)},
      58              :      {IValue::ATOMIC_LOAD_RELAXED, handlers::atomic_load (__ATOMIC_RELAXED)},
      59              :      {IValue::ATOMIC_LOAD_UNORDERED, handlers::atomic_load (__ATOMIC_RELAXED)},
      60              :      {IValue::UNCHECKED_ADD, handlers::unchecked_op (PLUS_EXPR)},
      61              :      {IValue::UNCHECKED_SUB, handlers::unchecked_op (MINUS_EXPR)},
      62              :      {IValue::UNCHECKED_MUL, handlers::unchecked_op (MULT_EXPR)},
      63              :      {IValue::UNCHECKED_DIV, handlers::unchecked_op (TRUNC_DIV_EXPR)},
      64              :      {IValue::UNCHECKED_REM, handlers::unchecked_op (TRUNC_MOD_EXPR)},
      65              :      {IValue::UNCHECKED_SHL, handlers::unchecked_op (LSHIFT_EXPR)},
      66              :      {IValue::UNCHECKED_SHR, handlers::unchecked_op (RSHIFT_EXPR)},
      67              :      {IValue::UNINIT, handlers::uninit},
      68              :      {IValue::MOVE_VAL_INIT, handlers::move_val_init},
      69              :      {IValue::LIKELY, handlers::expect (true)},
      70              :      {IValue::UNLIKELY, handlers::expect (false)},
      71              :      {IValue::ASSUME, handlers::assume},
      72              :      {IValue::TRY, handlers::try_handler (false)},
      73              :      {IValue::CATCH_UNWIND, handlers::try_handler (true)},
      74              :      {IValue::DISCRIMINANT_VALUE, handlers::discriminant_value},
      75              :      {IValue::VARIANT_COUNT, handlers::variant_count},
      76              :      {IValue::BSWAP, handlers::bswap_handler},
      77              :      {IValue::CTLZ, handlers::ctlz_handler},
      78              :      {IValue::CTLZ_NONZERO, handlers::ctlz_nonzero_handler},
      79              :      {IValue::CTTZ, handlers::cttz_handler},
      80              :      {IValue::CTTZ_NONZERO, handlers::cttz_nonzero_handler}};
      81              : 
      82         3370 : Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {}
      83              : 
      84              : /**
      85              :  * Returns a FUNC_DECL corresponding to the intrinsic function FNTYPE. If a
      86              :  * corresponding builtin exists, returns it. If not, search in the generic
      87              :  * intrinsics declared and delegate the return to the corresponding handler.
      88              :  *
      89              :  * @param fntype The Rust function type that should be implemented by the
      90              :  * compiler
      91              :  */
      92              : tree
      93         3370 : Intrinsics::compile (TyTy::FnType *fntype, location_t expr_locus)
      94              : {
      95         3370 :   rust_assert (fntype->get_abi () == ABI::INTRINSIC);
      96              : 
      97         3370 :   tree builtin = error_mark_node;
      98         3370 :   BuiltinsContext &builtin_ctx = BuiltinsContext::get ();
      99              : 
     100         6740 :   if (builtin_ctx.lookup_simple_builtin (fntype->get_identifier (), &builtin))
     101          449 :     return builtin;
     102              : 
     103              :   // is it an generic builtin?
     104         5842 :   auto it = generic_intrinsics.find (fntype->get_identifier ());
     105         2921 :   if (it != generic_intrinsics.end ())
     106         2921 :     return it->second (ctx, fntype, expr_locus);
     107              : 
     108            0 :   location_t locus = ctx->get_mappings ().lookup_location (fntype->get_ref ());
     109            0 :   rust_error_at (locus, ErrorCode::E0093,
     110              :                  "unrecognized intrinsic function: %qs",
     111            0 :                  fntype->get_identifier ().c_str ());
     112              : 
     113            0 :   return error_mark_node;
     114              : }
     115              : 
     116              : } // namespace Compile
     117              : } // namespace Rust
        

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.