LCOV - code coverage report
Current view: top level - gcc/rust/util - rust-lang-item.h Coverage Total Hit
Test: gcc.info Lines: 100.0 % 2 2
Test Date: 2026-08-22 16:33:35 Functions: - 0 0
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
       2              : 
       3              : // This file is part of GCC.
       4              : 
       5              : // GCC is free software; you can redistribute it and/or modify it under
       6              : // the terms of the GNU General Public License as published by the Free
       7              : // Software Foundation; either version 3, or (at your option) any later
       8              : // version.
       9              : 
      10              : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11              : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12              : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13              : // for more details.
      14              : 
      15              : // You should have received a copy of the GNU General Public License
      16              : // along with GCC; see the file COPYING3.  If not see
      17              : // <http://www.gnu.org/licenses/>.
      18              : 
      19              : #include "rust-system.h"
      20              : #include "rust-operators.h"
      21              : #include "optional.h"
      22              : #include "bi-map.h"
      23              : 
      24              : #ifndef RUST_LANG_ITEM_H
      25              : #define RUST_LANG_ITEM_H
      26              : 
      27              : namespace Rust {
      28              : 
      29              : class LangItem
      30              : {
      31              : public:
      32              :   // FIXME: We should clean up that enum to make it more inline with the list of
      33              :   // lang-items in Rust 1.49
      34              :   // https://github.com/rust-lang/rust/blob/1.49.0/compiler/rustc_hir/src/lang_items.rs
      35              :   enum class Kind
      36              :   {
      37              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
      38              :     ADD,
      39              :     SUBTRACT,
      40              :     MULTIPLY,
      41              :     DIVIDE,
      42              :     REMAINDER,
      43              :     BITAND,
      44              :     BITOR,
      45              :     BITXOR,
      46              :     SHL,
      47              :     SHR,
      48              : 
      49              :     NEGATION,
      50              :     NOT,
      51              :     EQ,
      52              :     PARTIAL_ORD,
      53              : 
      54              :     ADD_ASSIGN,
      55              :     SUB_ASSIGN,
      56              :     MUL_ASSIGN,
      57              :     DIV_ASSIGN,
      58              :     REM_ASSIGN,
      59              :     BITAND_ASSIGN,
      60              :     BITOR_ASSIGN,
      61              :     BITXOR_ASSIGN,
      62              :     SHL_ASSIGN,
      63              :     SHR_ASSIGN,
      64              : 
      65              :     DEREF,
      66              :     DEREF_MUT,
      67              :     RECEIVER,
      68              : 
      69              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/index.rs
      70              :     INDEX,
      71              :     INDEX_MUT,
      72              : 
      73              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/ops/range.rs
      74              :     RANGE_FULL,
      75              :     RANGE,
      76              :     RANGE_FROM,
      77              :     RANGE_TO,
      78              :     RANGE_INCLUSIVE,
      79              :     RANGE_TO_INCLUSIVE,
      80              :     RANGE_INCLUSIVE_NEW,
      81              : 
      82              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/marker.rs
      83              :     PHANTOM_DATA,
      84              : 
      85              :     // functions
      86              :     FN,
      87              :     FN_MUT,
      88              :     FN_ONCE,
      89              :     FN_ONCE_OUTPUT,
      90              : 
      91              :     // markers
      92              :     COPY,
      93              :     CLONE,
      94              :     DROP,
      95              :     SIZED,
      96              :     SYNC,
      97              : 
      98              :     // https://github.com/Rust-GCC/gccrs/issues/1896
      99              :     // https://github.com/rust-lang/rust/commit/afbecc0f68c4dcfc4878ba5bcb1ac942544a1bdc
     100              :     // https://github.com/Rust-GCC/gccrs/issues/1494
     101              :     // https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/const_ptr.rs
     102              :     SLICE_ALLOC,
     103              :     SLICE_U8_ALLOC,
     104              :     STR_ALLOC,
     105              :     ARRAY,
     106              :     BOOL,
     107              :     CHAR,
     108              :     F32,
     109              :     F64,
     110              :     I8,
     111              :     I16,
     112              :     I32,
     113              :     I64,
     114              :     I128,
     115              :     ISIZE,
     116              :     U8,
     117              :     U16,
     118              :     U32,
     119              :     U64,
     120              :     U128,
     121              :     USIZE,
     122              :     CONST_PTR,
     123              :     CONST_SLICE_PTR,
     124              :     MUT_PTR,
     125              :     MUT_SLICE_PTR,
     126              :     SLICE_U8,
     127              :     SLICE,
     128              :     STR,
     129              :     // NOTE: CStr is not present in Rust 1.49, and is only backported for
     130              :     // compilation of Rust for Linux with a patched core lib.
     131              :     CSTR,
     132              :     F32_RUNTIME,
     133              :     F64_RUNTIME,
     134              : 
     135              :     OPTION_SOME,
     136              :     OPTION_NONE,
     137              : 
     138              :     RESULT_OK,
     139              :     RESULT_ERR,
     140              : 
     141              :     INTOITER_INTOITER,
     142              :     ITERATOR_NEXT,
     143              : 
     144              :     // NOTE: These lang items are *not* necessarily present in later versions of
     145              :     // Rust (I am unsure at which point they have been removed as the `Try`
     146              :     // trait is unstable). They will need to be changed when updating the
     147              :     // targeted Rust version of gccrs
     148              :     TRY,
     149              :     TRY_INTO_RESULT,
     150              :     TRY_FROM_ERROR,
     151              :     TRY_FROM_OK,
     152              : 
     153              :     // NOTE: This is not a lang item in later versions of Rust
     154              :     FROM_FROM,
     155              : 
     156              :     STRUCTURAL_PEQ,
     157              :     STRUCTURAL_TEQ,
     158              : 
     159              :     DISCRIMINANT_TYPE,
     160              :     DISCRIMINANT_KIND,
     161              : 
     162              :     MANUALLY_DROP,
     163              :     DROP_IN_PLACE,
     164              : 
     165              :     EXCHANGE_MALLOC,
     166              :     OWNED_BOX,
     167              :     OOM,
     168              :     ALLOC_LAYOUT,
     169              :     BOX_FREE,
     170              :     MAYBE_UNINIT,
     171              : 
     172              :     UNSAFE_CELL,
     173              : 
     174              :     FUTURE_TRAIT,
     175              :     POLL,
     176              :     READY,
     177              :     PENDING,
     178              :     GENERATOR,
     179              :     GENERATOR_STATE,
     180              :   };
     181              : 
     182              :   static const BiMap<std::string, Kind> lang_items;
     183              : 
     184              :   static tl::optional<Kind> Parse (const std::string &item);
     185              : 
     186              :   static std::string ToString (Kind type);
     187              :   static std::string PrettyString (Kind type);
     188              : 
     189              :   static Kind OperatorToLangItem (ArithmeticOrLogicalOperator op);
     190              :   static Kind
     191              :   CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op);
     192              :   static Kind NegationOperatorToLangItem (NegationOperator op);
     193              :   static Kind ComparisonToLangItem (ComparisonOperator op);
     194              :   static std::string ComparisonToSegment (ComparisonOperator op);
     195              : 
     196              :   static bool IsEnumVariant (Kind type);
     197              : };
     198              : 
     199              : } // namespace Rust
     200              : 
     201              : // GCC 4.8 needs us to manually implement hashing for enum classes
     202              : namespace std {
     203              : template <> struct hash<Rust::LangItem::Kind>
     204              : {
     205      1662774 :   size_t operator() (const Rust::LangItem::Kind &lang_item) const noexcept
     206              :   {
     207      1662774 :     return hash<std::underlying_type<Rust::LangItem::Kind>::type> () (
     208              :       static_cast<std::underlying_type<Rust::LangItem::Kind>::type> (
     209              :         lang_item));
     210              :   }
     211              : };
     212              : } // namespace std
     213              : 
     214              : #endif // RUST_LANG_ITEM_H
        

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.