LCOV - code coverage report
Current view: top level - gcc/rust/typecheck - rust-hir-type-check-intrinsic.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 71.1 % 325 231
Test Date: 2026-11-14 16:39:50 Functions: 100.0 % 6 6
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 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-hir-type-check-intrinsic.h"
      20              : #include "rust-diagnostics.h"
      21              : #include "rust-intrinsic-values.h"
      22              : #include "rust-system.h"
      23              : #include "rust-tyty.h"
      24              : 
      25              : namespace Rust {
      26              : namespace Resolver {
      27              : 
      28              : using IValue = Values::Intrinsics;
      29              : using IRT = IntrinsicRuleType;
      30              : 
      31              : const std::unordered_map<std::string, IntrinsicRules>
      32              :   IntrinsicChecker::intrinsic_rules = {
      33              :     // fn unreachable() -> !;
      34              :     {IValue::UNREACHABLE, {0, {}, IRT::Never}},
      35              : 
      36              :     // pub fn sqrtf32(x: f32) -> f32;
      37              :     {IValue::SQRTF32, {0, {IRT::F32}, IRT::F32}},
      38              :     // pub fn sqrtf64(x: f64) -> f64;
      39              :     {IValue::SQRTF64, {0, {IRT::F64}, IRT::F64}},
      40              :     // pub fn sinf32(x: f32) -> f32;
      41              :     {IValue::SINF32, {0, {IRT::F32}, IRT::F32}},
      42              :     // pub fn sinf64(x: f64) -> f64;
      43              :     {IValue::SINF64, {0, {IRT::F64}, IRT::F64}},
      44              :     // pub fn cosf32(x: f32) -> f32;
      45              :     {IValue::COSF32, {0, {IRT::F32}, IRT::F32}},
      46              :     // pub fn cosf64(x: f64) -> f64;
      47              :     {IValue::COSF64, {0, {IRT::F64}, IRT::F64}},
      48              :     // pub fn expf32(x: f32) -> f32;
      49              :     {IValue::EXPF32, {0, {IRT::F32}, IRT::F32}},
      50              :     // pub fn expf64(x: f64) -> f64;
      51              :     {IValue::EXPF64, {0, {IRT::F64}, IRT::F64}},
      52              :     // pub fn exp2f32(x: f32) -> f32;
      53              :     {IValue::EXP2F32, {0, {IRT::F32}, IRT::F32}},
      54              :     // pub fn exp2f64(x: f64) -> f64;
      55              :     {IValue::EXP2F64, {0, {IRT::F64}, IRT::F64}},
      56              :     // pub fn logf32(x: f32) -> f32;
      57              :     {IValue::LOGF32, {0, {IRT::F32}, IRT::F32}},
      58              :     // pub fn logf64(x: f64) -> f64;
      59              :     {IValue::LOGF64, {0, {IRT::F64}, IRT::F64}},
      60              :     // pub fn log10f32(x: f32) -> f32;
      61              :     {IValue::LOG10F32, {0, {IRT::F32}, IRT::F32}},
      62              :     // pub fn log10f64(x: f64) -> f64;
      63              :     {IValue::LOG10F64, {0, {IRT::F64}, IRT::F64}},
      64              :     // pub fn log2f32(x: f32) -> f32;
      65              :     {IValue::LOG2F32, {0, {IRT::F32}, IRT::F32}},
      66              :     // pub fn log2f64(x: f64) -> f64;
      67              :     {IValue::LOG2F64, {0, {IRT::F64}, IRT::F64}},
      68              :     // pub fn fabsf32(x: f32) -> f32;
      69              :     {IValue::FABSF32, {0, {IRT::F32}, IRT::F32}},
      70              :     // pub fn fabsf64(x: f64) -> f64;
      71              :     {IValue::FABSF64, {0, {IRT::F64}, IRT::F64}},
      72              :     // pub fn floorf32(x: f32) -> f32;
      73              :     {IValue::FLOORF32, {0, {IRT::F32}, IRT::F32}},
      74              :     // pub fn floorf64(x: f64) -> f64;
      75              :     {IValue::FLOORF64, {0, {IRT::F64}, IRT::F64}},
      76              :     // pub fn ceilf32(x: f32) -> f32;
      77              :     {IValue::CEILF32, {0, {IRT::F32}, IRT::F32}},
      78              :     // pub fn ceilf64(x: f64) -> f64;
      79              :     {IValue::CEILF64, {0, {IRT::F64}, IRT::F64}},
      80              :     // pub fn truncf32(x: f32) -> f32;
      81              :     {IValue::TRUNCF32, {0, {IRT::F32}, IRT::F32}},
      82              :     // pub fn truncf64(x: f64) -> f64;
      83              :     {IValue::TRUNCF64, {0, {IRT::F64}, IRT::F64}},
      84              :     // pub fn rintf32(x: f32) -> f32;
      85              :     {IValue::RINTF32, {0, {IRT::F32}, IRT::F32}},
      86              :     // pub fn rintf64(x: f64) -> f64;
      87              :     {IValue::RINTF64, {0, {IRT::F64}, IRT::F64}},
      88              :     // pub fn nearbyintf32(x: f32) -> f32;
      89              :     {IValue::NEARBYINTF32, {0, {IRT::F32}, IRT::F32}},
      90              :     // pub fn nearbyintf64(x: f64) -> f64;
      91              :     {IValue::NEARBYINTF64, {0, {IRT::F64}, IRT::F64}},
      92              :     // pub fn roundf32(x: f32) -> f32;
      93              :     {IValue::ROUNDF32, {0, {IRT::F32}, IRT::F32}},
      94              :     // pub fn roundf64(x: f64) -> f64;
      95              :     {IValue::ROUNDF64, {0, {IRT::F64}, IRT::F64}},
      96              :     // pub fn minnumf32(x: f32, y: f32) -> f32;
      97              :     {IValue::MINNUMF32, {0, {IRT::F32, IRT::F32}, IRT::F32}},
      98              :     // pub fn minnumf64(x: f64, y: f64) -> f64;
      99              :     {IValue::MINNUMF64, {0, {IRT::F64, IRT::F64}, IRT::F64}},
     100              :     // pub fn maxnumf32(x: f32, y: f32) -> f32;
     101              :     {IValue::MAXNUMF32, {0, {IRT::F32, IRT::F32}, IRT::F32}},
     102              :     // pub fn maxnumf64(x: f64, y: f64) -> f64;
     103              :     {IValue::MAXNUMF64, {0, {IRT::F64, IRT::F64}, IRT::F64}},
     104              : 
     105              :     // pub fn powf32(a: f32, x: f32) -> f32;
     106              :     {IValue::POWF32, {0, {IRT::F32, IRT::F32}, IRT::F32}},
     107              :     // pub fn powf64(a: f64, x: f64) -> f64;
     108              :     {IValue::POWF64, {0, {IRT::F64, IRT::F64}, IRT::F64}},
     109              :     // pub fn copysignf32(x: f32, y: f32) -> f32;
     110              :     {IValue::COPYSIGNF32, {0, {IRT::F32, IRT::F32}, IRT::F32}},
     111              :     // pub fn copysignf64(x: f64, y: f64) -> f64;
     112              :     {IValue::COPYSIGNF64, {0, {IRT::F64, IRT::F64}, IRT::F64}},
     113              : 
     114              :     // pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
     115              :     {IValue::FMAF32, {0, {IRT::F32, IRT::F32, IRT::F32}, IRT::F32}},
     116              :     // pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
     117              :     {IValue::FMAF64, {0, {IRT::F64, IRT::F64, IRT::F64}, IRT::F64}},
     118              : 
     119              :     // pub fn powif32(a: f32, x: i32) -> f32;
     120              :     {IValue::POWIF32, {0, {IRT::F32, IRT::I32}, IRT::F32}},
     121              :     // pub fn powif64(a: f64, x: i32) -> f64;
     122              :     {IValue::POWIF64, {0, {IRT::F64, IRT::I32}, IRT::F64}},
     123              : 
     124              :     // pub fn abort() -> !;
     125              :     {IValue::ABORT, {0, {}, IRT::Never}},
     126              :     // pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
     127              :     {IValue::OFFSET,
     128              :      {1, {IRT::ConstPtrFirstGeneric, IRT::Isize}, IRT::ConstPtrFirstGeneric}},
     129              :     // pub fn size_of<T>() -> usize;
     130              :     {IValue::SIZE_OF, {1, {}, IRT::Usize}},
     131              :     // pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
     132              :     {IValue::SIZE_OF_VAL, {1, {IRT::ConstPtrFirstGeneric}, IRT::Usize}},
     133              :     // pub fn transmute<T, U>(e: T) -> U;
     134              :     {IValue::TRANSMUTE, {2, {IRT::FirstGeneric}, IRT::SecondGeneric}},
     135              :     // pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
     136              :     {IValue::ADD_WITH_OVERFLOW,
     137              :      {1,
     138              :       {IRT::FirstGeneric, IRT::FirstGeneric},
     139              :       IRT::TupleFirstGenericAndBool}},
     140              :     // pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
     141              :     {IValue::SUB_WITH_OVERFLOW,
     142              :      {1,
     143              :       {IRT::FirstGeneric, IRT::FirstGeneric},
     144              :       IRT::TupleFirstGenericAndBool}},
     145              :     // pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
     146              :     {IValue::MUL_WITH_OVERFLOW,
     147              :      {1,
     148              :       {IRT::FirstGeneric, IRT::FirstGeneric},
     149              :       IRT::TupleFirstGenericAndBool}},
     150              :     // fn copy<T>(src: *const T, dst: *mut T, count: usize);
     151              :     {IValue::COPY,
     152              :      {1,
     153              :       {IRT::ConstPtrFirstGeneric, IRT::MutPtrFirstGeneric, IRT::Usize},
     154              :       IRT::Unit}},
     155              :     // fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
     156              :     {IValue::COPY_NONOVERLAPPING,
     157              :      {1,
     158              :       {IRT::ConstPtrFirstGeneric, IRT::MutPtrFirstGeneric, IRT::Usize},
     159              :       IRT::Unit}},
     160              : 
     161              :     // pub fn prefetch_{read,write}_{data,instruction}<T>(data: *const T,
     162              :     // locality: i32);
     163              :     {IValue::PREFETCH_READ_DATA,
     164              :      {1, {IRT::ConstPtrFirstGeneric, IRT::I32}, IRT::Unit}},
     165              :     {IValue::PREFETCH_WRITE_DATA,
     166              :      {1, {IRT::ConstPtrFirstGeneric, IRT::I32}, IRT::Unit}},
     167              :     {IValue::PREFETCH_READ_INSTRUCTION,
     168              :      {1, {IRT::ConstPtrFirstGeneric, IRT::I32}, IRT::Unit}},
     169              :     {IValue::PREFETCH_WRITE_INSTRUCTION,
     170              :      {1, {IRT::ConstPtrFirstGeneric, IRT::I32}, IRT::Unit}},
     171              : 
     172              :     // pub unsafe fn atomic_store_seqcst<T: Copy>(_dst: *mut T, _val: T);
     173              :     {IValue::ATOMIC_STORE_SEQCST,
     174              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::Unit}},
     175              :     // pub unsafe fn atomic_store_release<T: Copy>(_dst: *mut T, _val: T);
     176              :     {IValue::ATOMIC_STORE_RELEASE,
     177              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::Unit}},
     178              :     // pub unsafe fn atomic_store_relaxed<T: Copy>(_dst: *mut T, _val: T);
     179              :     {IValue::ATOMIC_STORE_RELAXED,
     180              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::Unit}},
     181              :     // pub unsafe fn atomic_store_unordered<T: Copy>(_dst: *mut T, _val: T);
     182              :     {IValue::ATOMIC_STORE_UNORDERED,
     183              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::Unit}},
     184              :     // pub unsafe fn atomic_load_seqcst<T: Copy>(_src: *const T) -> T;
     185              :     {IValue::ATOMIC_LOAD_SEQCST,
     186              :      {1, {IRT::ConstPtrFirstGeneric}, IRT::FirstGeneric}},
     187              :     // pub unsafe fn atomic_load_acquire<T: Copy>(_src: *const T) -> T;
     188              :     {IValue::ATOMIC_LOAD_ACQUIRE,
     189              :      {1, {IRT::ConstPtrFirstGeneric}, IRT::FirstGeneric}},
     190              :     // pub unsafe fn atomic_load_relaxed<T: Copy>(_src: *const T) -> T;
     191              :     {IValue::ATOMIC_LOAD_RELAXED,
     192              :      {1, {IRT::ConstPtrFirstGeneric}, IRT::FirstGeneric}},
     193              :     // pub unsafe fn atomic_load_unordered<T: Copy>(_src: *const T) -> T;
     194              :     {IValue::ATOMIC_LOAD_UNORDERED,
     195              :      {1, {IRT::ConstPtrFirstGeneric}, IRT::FirstGeneric}},
     196              :     // pub unsafe fn atomic_xadd<T: Copy>(dst: *mut T, val: T) -> T;
     197              :     {IValue::ATOMIC_XADD,
     198              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     199              :     // pub unsafe fn atomic_xadd_acq<T: Copy>(dst: *mut T, val: T) -> T;
     200              :     {IValue::ATOMIC_XADD_ACQ,
     201              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     202              :     // pub unsafe fn atomic_xadd_rel<T: Copy>(dst: *mut T, val: T) -> T;
     203              :     {IValue::ATOMIC_XADD_REL,
     204              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     205              :     // pub unsafe fn atomic_xadd_acqrel<T: Copy>(dst: *mut T, val: T) -> T;
     206              :     {IValue::ATOMIC_XADD_ACQREL,
     207              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     208              :     // pub unsafe fn atomic_xadd_relaxed<T: Copy>(dst: *mut T, val: T) -> T;
     209              :     {IValue::ATOMIC_XADD_RELAXED,
     210              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     211              :     // pub unsafe fn atomic_xsub<T: Copy>(dst: *mut T, val: T) -> T;
     212              :     {IValue::ATOMIC_XSUB,
     213              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     214              :     // pub unsafe fn atomic_xsub_acq<T: Copy>(dst: *mut T, val: T) -> T;
     215              :     {IValue::ATOMIC_XSUB_ACQ,
     216              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     217              :     // pub unsafe fn atomic_xsub_rel<T: Copy>(dst: *mut T, val: T) -> T;
     218              :     {IValue::ATOMIC_XSUB_REL,
     219              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     220              :     // pub unsafe fn atomic_xsub_acqrel<T: Copy>(dst: *mut T, val: T) -> T;
     221              :     {IValue::ATOMIC_XSUB_ACQREL,
     222              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     223              :     // pub unsafe fn atomic_xsub_relaxed<T: Copy>(dst: *mut T, val: T) -> T;
     224              :     {IValue::ATOMIC_XSUB_RELAXED,
     225              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     226              :     // pub unsafe fn atomic_and<T: Copy>(dst: *mut T, val: T) -> T;
     227              :     {IValue::ATOMIC_AND,
     228              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     229              :     // pub unsafe fn atomic_and_acq<T: Copy>(dst: *mut T, val: T) -> T;
     230              :     {IValue::ATOMIC_AND_ACQ,
     231              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     232              :     // pub unsafe fn atomic_and_rel<T: Copy>(dst: *mut T, val: T) -> T;
     233              :     {IValue::ATOMIC_AND_REL,
     234              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     235              :     // pub unsafe fn atomic_and_acqrel<T: Copy>(dst: *mut T, val: T) -> T;
     236              :     {IValue::ATOMIC_AND_ACQREL,
     237              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     238              :     // pub unsafe fn atomic_and_relaxed<T: Copy>(dst: *mut T, val: T) -> T;
     239              :     {IValue::ATOMIC_AND_RELAXED,
     240              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     241              :     // pub unsafe fn atomic_nand<T: Copy>(dst: *mut T, val: T) -> T;
     242              :     {IValue::ATOMIC_NAND,
     243              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     244              :     // pub unsafe fn atomic_nand_acq<T: Copy>(dst: *mut T, val: T) -> T;
     245              :     {IValue::ATOMIC_NAND_ACQ,
     246              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     247              :     // pub unsafe fn atomic_nand_rel<T: Copy>(dst: *mut T, val: T) -> T;
     248              :     {IValue::ATOMIC_NAND_REL,
     249              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     250              :     // pub unsafe fn atomic_nand_acqrel<T: Copy>(dst: *mut T, val: T) -> T;
     251              :     {IValue::ATOMIC_NAND_ACQREL,
     252              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     253              :     // pub unsafe fn atomic_nand_relaxed<T: Copy>(dst: *mut T, val: T) -> T;
     254              :     {IValue::ATOMIC_NAND_RELAXED,
     255              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     256              :     // pub unsafe fn atomic_or<T: Copy>(dst: *mut T, val: T) -> T;
     257              :     {IValue::ATOMIC_OR,
     258              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     259              :     // pub unsafe fn atomic_or_acq<T: Copy>(dst: *mut T, val: T) -> T;
     260              :     {IValue::ATOMIC_OR_ACQ,
     261              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     262              :     // pub unsafe fn atomic_or_rel<T: Copy>(dst: *mut T, val: T) -> T;
     263              :     {IValue::ATOMIC_OR_REL,
     264              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     265              :     // pub unsafe fn atomic_or_acqrel<T: Copy>(dst: *mut T, val: T) -> T;
     266              :     {IValue::ATOMIC_OR_ACQREL,
     267              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     268              :     // pub unsafe fn atomic_or_relaxed<T: Copy>(dst: *mut T, val: T) -> T;
     269              :     {IValue::ATOMIC_OR_RELAXED,
     270              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     271              :     // pub unsafe fn atomic_xor<T: Copy>(dst: *mut T, val: T) -> T;
     272              :     {IValue::ATOMIC_XOR,
     273              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     274              :     // pub unsafe fn atomic_xor_acq<T: Copy>(dst: *mut T, val: T) -> T;
     275              :     {IValue::ATOMIC_XOR_ACQ,
     276              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     277              :     // pub unsafe fn atomic_xor_rel<T: Copy>(dst: *mut T, val: T) -> T;
     278              :     {IValue::ATOMIC_XOR_REL,
     279              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     280              :     // pub unsafe fn atomic_xor_acqrel<T: Copy>(dst: *mut T, val: T) -> T;
     281              :     {IValue::ATOMIC_XOR_ACQREL,
     282              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     283              :     // pub unsafe fn atomic_xor_relaxed<T: Copy>(dst: *mut T, val: T) -> T;
     284              :     {IValue::ATOMIC_XOR_RELAXED,
     285              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     286              :     // fn atomic_[u]min/max<T>(dst: *mut T, val: T) -> T;
     287              :     {IValue::ATOMIC_MIN,
     288              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     289              :     {IValue::ATOMIC_MIN_ACQ,
     290              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     291              :     {IValue::ATOMIC_MIN_REL,
     292              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     293              :     {IValue::ATOMIC_MIN_ACQREL,
     294              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     295              :     {IValue::ATOMIC_MIN_RELAXED,
     296              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     297              :     {IValue::ATOMIC_MAX,
     298              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     299              :     {IValue::ATOMIC_MAX_ACQ,
     300              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     301              :     {IValue::ATOMIC_MAX_REL,
     302              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     303              :     {IValue::ATOMIC_MAX_ACQREL,
     304              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     305              :     {IValue::ATOMIC_MAX_RELAXED,
     306              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     307              :     {IValue::ATOMIC_UMIN,
     308              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     309              :     {IValue::ATOMIC_UMIN_ACQ,
     310              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     311              :     {IValue::ATOMIC_UMIN_REL,
     312              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     313              :     {IValue::ATOMIC_UMIN_ACQREL,
     314              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     315              :     {IValue::ATOMIC_UMIN_RELAXED,
     316              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     317              :     {IValue::ATOMIC_UMAX,
     318              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     319              :     {IValue::ATOMIC_UMAX_ACQ,
     320              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     321              :     {IValue::ATOMIC_UMAX_REL,
     322              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     323              :     {IValue::ATOMIC_UMAX_ACQREL,
     324              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     325              :     {IValue::ATOMIC_UMAX_RELAXED,
     326              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     327              :     // fn atomic_cxchg[weak]*<T>(dst: *mut T, old: T, new: T) -> (T, bool);
     328              :     {IValue::ATOMIC_CXCHG,
     329              :      {1,
     330              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     331              :       IRT::TupleFirstGenericAndBool}},
     332              :     {IValue::ATOMIC_CXCHG_ACQ,
     333              :      {1,
     334              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     335              :       IRT::TupleFirstGenericAndBool}},
     336              :     {IValue::ATOMIC_CXCHG_REL,
     337              :      {1,
     338              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     339              :       IRT::TupleFirstGenericAndBool}},
     340              :     {IValue::ATOMIC_CXCHG_ACQREL,
     341              :      {1,
     342              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     343              :       IRT::TupleFirstGenericAndBool}},
     344              :     {IValue::ATOMIC_CXCHG_RELAXED,
     345              :      {1,
     346              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     347              :       IRT::TupleFirstGenericAndBool}},
     348              :     {IValue::ATOMIC_CXCHGWEAK,
     349              :      {1,
     350              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     351              :       IRT::TupleFirstGenericAndBool}},
     352              :     {IValue::ATOMIC_CXCHGWEAK_ACQ,
     353              :      {1,
     354              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     355              :       IRT::TupleFirstGenericAndBool}},
     356              :     {IValue::ATOMIC_CXCHGWEAK_REL,
     357              :      {1,
     358              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     359              :       IRT::TupleFirstGenericAndBool}},
     360              :     {IValue::ATOMIC_CXCHGWEAK_ACQREL,
     361              :      {1,
     362              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     363              :       IRT::TupleFirstGenericAndBool}},
     364              :     {IValue::ATOMIC_CXCHGWEAK_RELAXED,
     365              :      {1,
     366              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     367              :       IRT::TupleFirstGenericAndBool}},
     368              :     // pub fn atomic_fence*/atomic_singlethreadfence*();
     369              :     {IValue::ATOMIC_FENCE, {0, {}, IRT::Unit}},
     370              :     {IValue::ATOMIC_FENCE_ACQ, {0, {}, IRT::Unit}},
     371              :     {IValue::ATOMIC_FENCE_REL, {0, {}, IRT::Unit}},
     372              :     {IValue::ATOMIC_FENCE_ACQREL, {0, {}, IRT::Unit}},
     373              :     {IValue::ATOMIC_SINGLETHREADFENCE, {0, {}, IRT::Unit}},
     374              :     {IValue::ATOMIC_SINGLETHREADFENCE_ACQ, {0, {}, IRT::Unit}},
     375              :     {IValue::ATOMIC_SINGLETHREADFENCE_REL, {0, {}, IRT::Unit}},
     376              :     {IValue::ATOMIC_SINGLETHREADFENCE_ACQREL, {0, {}, IRT::Unit}},
     377              :     // pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
     378              :     {IValue::UNCHECKED_ADD,
     379              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     380              :     // pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
     381              :     {IValue::UNCHECKED_SUB,
     382              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     383              :     // pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
     384              :     {IValue::UNCHECKED_MUL,
     385              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     386              :     // pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
     387              :     {IValue::UNCHECKED_DIV,
     388              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     389              :     // pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
     390              :     {IValue::UNCHECKED_REM,
     391              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     392              :     // pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
     393              :     {IValue::UNCHECKED_SHL,
     394              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     395              :     // pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
     396              :     {IValue::UNCHECKED_SHR,
     397              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     398              :     // pub unsafe fn uninit<T>() -> T
     399              :     {IValue::UNINIT, {1, {}, IRT::FirstGeneric}},
     400              :     // pub fn move_val_init<T>(dst: *mut T, src: T);
     401              :     {IValue::MOVE_VAL_INIT,
     402              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::Unit}},
     403              :     // pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
     404              :     {IValue::ROTATE_LEFT,
     405              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     406              :     // pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
     407              :     {IValue::ROTATE_RIGHT,
     408              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     409              :     // pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
     410              :     {IValue::WRAPPING_ADD,
     411              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     412              :     // pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
     413              :     {IValue::WRAPPING_SUB,
     414              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     415              :     // pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
     416              :     {IValue::WRAPPING_MUL,
     417              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     418              :     // pub fn saturating_add<T: Copy>(a: T, b: T) -> T;
     419              :     {IValue::SATURATING_ADD,
     420              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     421              :     // pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
     422              :     {IValue::SATURATING_SUB,
     423              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     424              :     // pub fn likely(b: bool) -> bool;
     425              :     {IValue::LIKELY, {0, {IRT::Bool}, IRT::Bool}},
     426              :     // pub fn unlikely(b: bool) -> bool;
     427              :     {IValue::UNLIKELY, {0, {IRT::Bool}, IRT::Bool}},
     428              :     // fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
     429              :     {IValue::DISCRIMINANT_VALUE,
     430              :      {1, {IRT::RefFirstGeneric}, IRT::AssocTypePlaceholder}},
     431              :     // pub fn variant_count<T>() -> usize;
     432              :     {IValue::VARIANT_COUNT, {1, {}, IRT::Usize}},
     433              :     // NOTE: The return value was temporarily set to () instead of i32.
     434              :     // pub unsafe fn catch_unwind(
     435              :     //    _try_fn: fn(_: *mut u8),
     436              :     //    _data: *mut u8,
     437              :     //    _catch_fn: fn(_: *mut u8, _: *mut u8),
     438              :     // ) -> i32
     439              :     {IValue::CATCH_UNWIND,
     440              :      {0,
     441              :       {IRT::Fn_MutPtrU8, IRT::MutPtrU8, IRT::Fn_MutPtrU8MutPtrU8},
     442              :       IRT::Unit}},
     443              :     // pub fn r#try(
     444              :     //          try_fn: fn(*mut u8),
     445              :     //          data: *mut u8,
     446              :     //          catch_fn: fn(*mut u8,
     447              :     //          *mut u8)
     448              :     // ) -> i32;
     449              :     {IValue::TRY,
     450              :      {0,
     451              :       {IRT::Fn_MutPtrU8, IRT::MutPtrU8, IRT::Fn_MutPtrU8MutPtrU8},
     452              :       IRT::I32}},
     453              :     // pub fn assume(b: bool);
     454              :     {IValue::ASSUME, {0, {IRT::Bool}, IRT::Unit}},
     455              :     // pub fn min_align_of<T>() -> usize;
     456              :     {IValue::MIN_ALIGN_OF, {1, {}, IRT::Usize}},
     457              :     // pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
     458              :     {IValue::MIN_ALIGN_OF_VAL, {1, {IRT::ConstPtrFirstGeneric}, IRT::Usize}},
     459              :     // pub fn needs_drop<T>() -> bool;
     460              :     {IValue::NEEDS_DROP, {1, {}, IRT::Bool}},
     461              :     // pub fn caller_location() -> &'static crate::panic::Location<'static>;
     462              :     {IValue::CALLER_LOCATION, {0, {}, IRT::RefAdt}},
     463              :     // pub fn ctpop<T: Copy>(x: T) -> T;
     464              :     {IValue::CTPOP, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     465              : 
     466              :     // pub fn ctlz<T: Copy>(x: T) -> T;
     467              :     {IValue::CTLZ, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     468              :     // pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
     469              :     {IValue::CTLZ_NONZERO, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     470              :     // pub fn cttz<T: Copy>(x: T) -> T;
     471              :     {IValue::CTTZ, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     472              :     // pub fn cttz_nonzero<T: Copy>(x: T) -> T;
     473              :     {IValue::CTTZ_NONZERO, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     474              :     // pub fn bswap<T: Copy>(x: T) -> T;
     475              :     {IValue::BSWAP, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     476              :     // pub fn bitreverse<T: Copy>(x: T) -> T;
     477              :     {IValue::BITREVERSE, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     478              :     // pub fn type_id<T: ?Sized + 'static>() -> u64;
     479              :     {IValue::TYPE_ID, {1, {}, IRT::U64}},
     480              :     // pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
     481              :     {IValue::PTR_GUARANTEED_EQ,
     482              :      {1, {IRT::ConstPtrFirstGeneric, IRT::ConstPtrFirstGeneric}, IRT::Bool}},
     483              :     // pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
     484              :     {IValue::PTR_GUARANTEED_NE,
     485              :      {1, {IRT::ConstPtrFirstGeneric, IRT::ConstPtrFirstGeneric}, IRT::Bool}},
     486              :     // pub fn rustc_peek<T>(_: T) -> T;
     487              :     {IValue::RUSTC_PEEK, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     488              :     // pub fn type_name<T: ?Sized>() -> &'static str;
     489              :     {IValue::TYPE_NAME, {1, {}, IRT::RefStaticStr}},
     490              :     // pub fn forget<T: ?Sized>(_: T);
     491              :     {IValue::FORGET, {1, {IRT::FirstGeneric}, IRT::Unit}},
     492              :     // pub fn black_box<T>(mut dummy: T) -> T
     493              :     {IValue::BLACK_BOX, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     494              : 
     495              :     // pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
     496              :     {IValue::ARITH_OFFSET,
     497              :      {1, {IRT::ConstPtrFirstGeneric, IRT::Isize}, IRT::ConstPtrFirstGeneric}},
     498              :     // fn write_bytes<T>(dst: *mut T, val: u8, count: usize)
     499              :     {IValue::WRITE_BYTES,
     500              :      {1, {IRT::MutPtrFirstGeneric, IRT::U8, IRT::Usize}, IRT::Unit}},
     501              : 
     502              :     // fn breakpoint()
     503              :     {IValue::BREAKPOINT, {0, {}, IRT::Unit}},
     504              : 
     505              :     // fn pref_align_of<T>() -> usize
     506              :     {IValue::PREF_ALIGN_OF, {1, {}, IRT::Usize}},
     507              : 
     508              :     // pub fn assert_zero_valid<T>();
     509              :     {IValue::ASSERT_ZERO_VALID, {1, {}, IRT::Unit}},
     510              :     // fn assert_inhabited<T>();
     511              :     {IValue::ASSERT_INHABITED, {1, {}, IRT::Unit}},
     512              :     // fn assert_maybe_uninit<T>();
     513              :     {IValue::ASSERT_UNINIT_VALID, {1, {}, IRT::Unit}},
     514              : 
     515              :     // pub fn fadd_fast<T>(a: T, b: T) -> T
     516              :     // same for fsub_fast, fmul_fast, fdiv_fast and frem_fast
     517              :     {IValue::FADD_FAST,
     518              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     519              :     {IValue::FSUB_FAST,
     520              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     521              :     {IValue::FMUL_FAST,
     522              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     523              :     {IValue::FDIV_FAST,
     524              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     525              :     {IValue::FREM_FAST,
     526              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     527              : 
     528              :     // fn float_to_int_unchecked<Float, Int>(x: Float) -> Int
     529              :     //     where Float: FloatPrimitive, Int: Copy
     530              :     {IValue::FLOAT_TO_INT_UNCHECKED,
     531              :      {2, {IRT::FirstGeneric}, IRT::SecondGeneric}},
     532              : 
     533              :     // fn exact_div<T>(lhs: T, rhs: T) -> T
     534              :     {IValue::EXACT_DIV,
     535              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     536              : 
     537              :     // fn nontemporal_store<T>(ptr: *mut T, value: T)
     538              :     {IValue::NONTEMPORAL_STORE,
     539              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::Unit}},
     540              : 
     541              :     // fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
     542              :     {IValue::PTR_OFFSET_FROM,
     543              :      {1, {IRT::ConstPtrFirstGeneric, IRT::ConstPtrFirstGeneric}, IRT::Isize}},
     544              : };
     545              : 
     546              : IntrinsicCheckResult
     547         2096 : IntrinsicChecker::check (const TyTy::FnType *fntype)
     548              : {
     549         4192 :   auto it = intrinsic_rules.find (fntype->get_identifier ());
     550         2096 :   if (it == intrinsic_rules.end ())
     551              :     {
     552           16 :       rust_error_at (fntype->get_locus (), ErrorCode::E0093,
     553              :                      "unrecognized intrinsic function: %qs",
     554            8 :                      fntype->get_identifier ().c_str ());
     555            8 :       return IntrinsicCheckResult::Invalid;
     556              :     }
     557         2088 :   auto rule = &it->second;
     558              : 
     559         2088 :   if (fntype->get_substs ().size () != rule->generic_count)
     560              :     {
     561            3 :       rust_error_at (fntype->get_locus (), ErrorCode::E0094,
     562              :                      "intrinsic has wrong number of type parameters: found "
     563              :                      "%lu, expected %lu",
     564            1 :                      (unsigned long) fntype->get_substs ().size (),
     565              :                      (unsigned long) rule->generic_count);
     566            1 :       return IntrinsicCheckResult::Invalid;
     567              :     }
     568              : 
     569         2087 :   IntrinsicCheckResult result = IntrinsicCheckResult::Valid;
     570              : 
     571         2087 :   if (fntype->get_num_params () != rule->param_types.size ())
     572              :     {
     573            3 :       rust_error_at (fntype->get_locus (), ErrorCode::E0308,
     574              :                      "intrinsic has wrong number of function parameters: found "
     575              :                      "%lu, expected %lu",
     576            1 :                      (unsigned long) fntype->get_params ().size (),
     577            1 :                      (unsigned long) rule->param_types.size ());
     578            1 :       result = IntrinsicCheckResult::Invalid;
     579              :     }
     580              :   else
     581              :     {
     582         5065 :       for (size_t i = 0; i < rule->param_types.size (); i++)
     583              :         {
     584         2979 :           const TyTy::BaseType *actual_param
     585         2979 :             = fntype->get_params ().at (i).get_type ();
     586         2979 :           IntrinsicRuleType expected_type = rule->param_types.at (i);
     587              : 
     588         2979 :           if (!check_type (actual_param, expected_type, fntype))
     589              :             {
     590            3 :               rust_error_at (fntype->get_locus (), ErrorCode::E0308,
     591              :                              "intrinsic has wrong type");
     592            3 :               result = IntrinsicCheckResult::Invalid;
     593              :             }
     594              :         }
     595              :     }
     596              : 
     597         2087 :   if (!check_type (fntype->get_return_type (), rule->return_type, fntype))
     598              :     {
     599            2 :       rust_error_at (fntype->get_locus (), ErrorCode::E0308,
     600              :                      "intrinsic has wrong type");
     601            2 :       result = IntrinsicCheckResult::Invalid;
     602              :     }
     603              : 
     604         2087 :   if (result == IntrinsicCheckResult::Invalid)
     605              :     {
     606            5 :       rust_inform (fntype->get_locus (), "expected fn pointer %qs",
     607            5 :                    expected_intrinsic_as_string (fntype).c_str ());
     608            5 :       rust_inform (fntype->get_locus (), "   found fn pointer %qs",
     609           10 :                    found_intrinsic_as_string (fntype).c_str ());
     610              :     }
     611              :   return result;
     612              : }
     613              : 
     614              : bool
     615         5197 : IntrinsicChecker::check_type (const TyTy::BaseType *actual,
     616              :                               IntrinsicRuleType expected,
     617              :                               const TyTy::FnType *fntype)
     618              : {
     619         6209 :   switch (expected)
     620              :     {
     621           15 :     case IRT::Bool:
     622           15 :       return actual->get_kind () == TyTy::TypeKind::BOOL;
     623          336 :     case IRT::F32:
     624          336 :       return actual->get_kind () == TyTy::TypeKind::FLOAT
     625          336 :              && static_cast<const TyTy::FloatType *> (actual)->get_float_kind ()
     626              :                   == TyTy::FloatType::FloatKind::F32;
     627          336 :     case IRT::F64:
     628          336 :       return actual->get_kind () == TyTy::TypeKind::FLOAT
     629          336 :              && static_cast<const TyTy::FloatType *> (actual)->get_float_kind ()
     630              :                   == TyTy::FloatType::FloatKind::F64;
     631           33 :     case IRT::I32:
     632           33 :       return actual->get_kind () == TyTy::TypeKind::INT
     633           33 :              && static_cast<const TyTy::IntType *> (actual)->get_int_kind ()
     634              :                   == TyTy::IntType::IntKind::I32;
     635          130 :     case IRT::Isize:
     636          130 :       return actual->get_kind () == TyTy::TypeKind::ISIZE;
     637           12 :     case IRT::U8:
     638           12 :       return actual->get_kind () == TyTy::TypeKind::UINT
     639           12 :              && static_cast<const TyTy::UintType *> (actual)->get_uint_kind ()
     640              :                   == TyTy::UintType::UintKind::U8;
     641            0 :     case IRT::U64:
     642            0 :       return actual->get_kind () == TyTy::TypeKind::UINT
     643            0 :              && static_cast<const TyTy::UintType *> (actual)->get_uint_kind ()
     644              :                   == TyTy::UintType::UintKind::U64;
     645          164 :     case IRT::Usize:
     646          164 :       return actual->get_kind () == TyTy::TypeKind::USIZE;
     647          242 :     case IRT::Unit:
     648          242 :       return actual->is_unit ();
     649          156 :     case IRT::Never:
     650          156 :       return actual->get_kind () == TyTy::TypeKind::NEVER;
     651              : 
     652         3571 :     case IRT::FirstGeneric:
     653         3571 :     case IRT::SecondGeneric:
     654         3571 :       {
     655         3571 :         if (actual->get_kind () != TyTy::TypeKind::PARAM)
     656              :           return false;
     657              : 
     658         3569 :         auto param = static_cast<const TyTy::ParamType *> (actual);
     659         3569 :         size_t expected_index = (expected == IRT::FirstGeneric) ? 0 : 1;
     660         3569 :         if (fntype->get_substs ().size () <= expected_index)
     661              :           return false;
     662         3569 :         auto expected_param
     663         3569 :           = fntype->get_substs ().at (expected_index).get_param_ty ();
     664         3569 :         return param->get_ty_ref () == expected_param->get_ty_ref ();
     665              :       }
     666          358 :     case IRT::ConstPtrFirstGeneric:
     667          358 :       {
     668          358 :         if (actual->get_kind () != TyTy::TypeKind::POINTER)
     669              :           return false;
     670          357 :         auto ptr = static_cast<const TyTy::PointerType *> (actual);
     671          357 :         if (!ptr->is_const ())
     672              :           return false;
     673          357 :         return check_type (ptr->get_base (), IntrinsicRuleType::FirstGeneric,
     674          357 :                            fntype);
     675              :       }
     676          570 :     case IRT::MutPtrFirstGeneric:
     677          570 :       {
     678          570 :         if (actual->get_kind () != TyTy::TypeKind::POINTER)
     679              :           return false;
     680          570 :         auto ptr = static_cast<const TyTy::PointerType *> (actual);
     681          570 :         if (!ptr->is_mutable ())
     682              :           return false;
     683          570 :         return check_type (ptr->get_base (), IntrinsicRuleType::FirstGeneric,
     684          570 :                            fntype);
     685              :       }
     686           72 :     case IRT::RefFirstGeneric:
     687           72 :       {
     688           72 :         if (actual->get_kind () != TyTy::TypeKind::REF)
     689              :           return false;
     690           72 :         auto ref = static_cast<const TyTy::ReferenceType *> (actual);
     691           72 :         if (ref->is_mutable ())
     692              :           return false;
     693           72 :         return check_type (ref->get_base (), IntrinsicRuleType::FirstGeneric,
     694           72 :                            fntype);
     695              :       }
     696            0 :     case IRT::RefAdt:
     697            0 :       {
     698            0 :         if (actual->get_kind () != TyTy::TypeKind::REF)
     699              :           return false;
     700            0 :         auto ref = static_cast<const TyTy::ReferenceType *> (actual);
     701            0 :         if (ref->is_mutable ())
     702              :           return false;
     703            0 :         return ref->get_base ()->get_kind () == TyTy::TypeKind::ADT;
     704              :       }
     705           11 :     case IRT::MutPtrU8:
     706           11 :       {
     707           11 :         if (actual->get_kind () != TyTy::TypeKind::POINTER)
     708              :           return false;
     709           11 :         auto ptr = static_cast<const TyTy::PointerType *> (actual);
     710           11 :         if (!ptr->is_mutable ())
     711              :           return false;
     712           11 :         return check_type (ptr->get_base (), IRT::U8, fntype);
     713              :       }
     714            0 :     case IRT::RefStaticStr:
     715            0 :       {
     716            0 :         if (actual->get_kind () != TyTy::TypeKind::REF)
     717              :           return false;
     718            0 :         auto ref = static_cast<const TyTy::ReferenceType *> (actual);
     719            0 :         if (ref->is_mutable ())
     720              :           return false;
     721            0 :         return ref->get_base ()->get_kind () == TyTy::TypeKind::STR;
     722              :       }
     723              :     case IRT::AssocTypePlaceholder:
     724              :       return true;
     725              : 
     726          125 :     case IRT::TupleFirstGenericAndBool:
     727          125 :       {
     728          125 :         if (actual->get_kind () != TyTy::TypeKind::TUPLE)
     729              :           return false;
     730          125 :         auto tuple = static_cast<const TyTy::TupleType *> (actual);
     731          125 :         if (tuple->num_fields () != 2)
     732              :           return false;
     733          125 :         return tuple->get_field (1)->get_kind () == TyTy::TypeKind::BOOL
     734          125 :                && check_type (tuple->get_field (0),
     735              :                               IntrinsicRuleType::FirstGeneric, fntype);
     736              :       }
     737              : 
     738            3 :     case IRT::Fn_MutPtrU8:
     739            3 :       {
     740            3 :         if (actual->get_kind () != TyTy::TypeKind::FNPTR)
     741              :           return false;
     742            2 :         auto fn = static_cast<const TyTy::FnPtr *> (actual);
     743            2 :         if (!fn->get_return_type ()->is_unit ())
     744              :           return false;
     745            2 :         if (fn->get_num_params () != 1)
     746              :           return false;
     747            2 :         return check_type (fn->get_param_type_at (0), IRT::MutPtrU8, fntype);
     748              :       }
     749            3 :     case IRT::Fn_MutPtrU8MutPtrU8:
     750            3 :       {
     751            3 :         if (actual->get_kind () != TyTy::TypeKind::FNPTR)
     752              :           return false;
     753            3 :         auto fn = static_cast<const TyTy::FnPtr *> (actual);
     754            3 :         if (!fn->get_return_type ()->is_unit ())
     755              :           return false;
     756            3 :         if (fn->get_num_params () != 2)
     757              :           return false;
     758            3 :         return check_type (fn->get_param_type_at (0), IRT::MutPtrU8, fntype)
     759            3 :                && check_type (fn->get_param_type_at (1), IRT::MutPtrU8, fntype);
     760              :       }
     761              : 
     762            0 :     default:
     763            0 :       rust_unreachable ();
     764              :     };
     765              :   return true;
     766              : }
     767              : 
     768              : static std::string
     769           22 : to_string (const TyTy::BaseType *type, const TyTy::FnType *fntype)
     770              : {
     771           22 :   switch (type->get_kind ())
     772              :     {
     773            1 :     case TyTy::TypeKind::BOOL:
     774            1 :       return "bool";
     775            3 :     case TyTy::TypeKind::USIZE:
     776            3 :       return "usize";
     777            1 :     case TyTy::TypeKind::ISIZE:
     778            1 :       return "isize";
     779            1 :     case TyTy::TypeKind::NEVER:
     780            1 :       return "!";
     781            0 :     case TyTy::TypeKind::STR:
     782            0 :       return "str";
     783              : 
     784            3 :     case TyTy::TypeKind::INT:
     785            3 :       {
     786            3 :         auto int_ty = static_cast<const TyTy::IntType *> (type);
     787            3 :         switch (int_ty->get_int_kind ())
     788              :           {
     789            0 :           case TyTy::IntType::IntKind::I8:
     790            0 :             return "i8";
     791            0 :           case TyTy::IntType::IntKind::I16:
     792            0 :             return "i16";
     793            3 :           case TyTy::IntType::IntKind::I32:
     794            3 :             return "i32";
     795            0 :           case TyTy::IntType::IntKind::I64:
     796            0 :             return "i64";
     797            0 :           case TyTy::IntType::IntKind::I128:
     798            0 :             return "i128";
     799              :           }
     800            0 :         rust_unreachable ();
     801              :       }
     802              : 
     803            3 :     case TyTy::TypeKind::UINT:
     804            3 :       {
     805            3 :         auto uint_ty = static_cast<const TyTy::UintType *> (type);
     806            3 :         switch (uint_ty->get_uint_kind ())
     807              :           {
     808            3 :           case TyTy::UintType::UintKind::U8:
     809            3 :             return "u8";
     810            0 :           case TyTy::UintType::UintKind::U16:
     811            0 :             return "u16";
     812            0 :           case TyTy::UintType::UintKind::U32:
     813            0 :             return "u32";
     814            0 :           case TyTy::UintType::UintKind::U64:
     815            0 :             return "u64";
     816            0 :           case TyTy::UintType::UintKind::U128:
     817            0 :             return "u128";
     818              :           }
     819            0 :         rust_unreachable ();
     820              :       }
     821              : 
     822            0 :     case TyTy::TypeKind::FLOAT:
     823            0 :       {
     824            0 :         auto float_ty = static_cast<const TyTy::FloatType *> (type);
     825            0 :         switch (float_ty->get_float_kind ())
     826              :           {
     827            0 :           case TyTy::FloatType::FloatKind::F32:
     828            0 :             return "f32";
     829            0 :           case TyTy::FloatType::FloatKind::F64:
     830            0 :             return "f64";
     831              :           }
     832            0 :         rust_unreachable ();
     833              :       }
     834              : 
     835            4 :     case TyTy::TypeKind::PARAM:
     836            4 :       {
     837            4 :         auto param = static_cast<const TyTy::ParamType *> (type);
     838            4 :         if (fntype != nullptr)
     839              :           {
     840            4 :             auto substs = fntype->get_substs ();
     841            8 :             for (size_t i = 0; i < substs.size (); i++)
     842              :               {
     843            8 :                 if (substs[i].get_param_ty ()->get_ty_ref ()
     844            4 :                     == param->get_ty_ref ())
     845            4 :                   return "P" + std::to_string (i);
     846              :               }
     847            4 :           }
     848            0 :         return param->get_symbol ();
     849              :       }
     850              : 
     851            4 :     case TyTy::TypeKind::POINTER:
     852            4 :       {
     853            4 :         auto ptr = static_cast<const TyTy::PointerType *> (type);
     854            4 :         std::string prefix = ptr->is_mutable () ? "*mut "
     855            1 :                              : ptr->is_const () ? "*const "
     856            5 :                                                 : "*";
     857            4 :         return prefix + to_string (ptr->get_base (), fntype);
     858            4 :       }
     859              : 
     860            0 :     case TyTy::TypeKind::REF:
     861            0 :       {
     862            0 :         auto ref = static_cast<const TyTy::ReferenceType *> (type);
     863            0 :         std::string prefix = ref->is_mutable () ? "&mut " : "&";
     864            0 :         return prefix + to_string (ref->get_base (), fntype);
     865            0 :       }
     866              : 
     867            1 :     case TyTy::TypeKind::TUPLE:
     868            1 :       {
     869            1 :         auto tuple = static_cast<const TyTy::TupleType *> (type);
     870            1 :         if (tuple->num_fields () == 0)
     871            0 :           return "()";
     872              : 
     873            1 :         std::string res = "(";
     874            3 :         for (size_t i = 0; i < tuple->num_fields (); i++)
     875              :           {
     876            2 :             if (i > 0)
     877            1 :               res += ", ";
     878            4 :             res += to_string (tuple->get_field (i), fntype);
     879              :           }
     880            1 :         res += ")";
     881            1 :         return res;
     882            1 :       }
     883              : 
     884            1 :     case TyTy::TypeKind::FNPTR:
     885            1 :       {
     886            1 :         auto fnptr = static_cast<const TyTy::FnPtr *> (type);
     887            1 :         std::string res = "fn(";
     888            3 :         for (size_t i = 0; i < fnptr->get_num_params (); i++)
     889              :           {
     890            2 :             if (i > 0)
     891            1 :               res += ", ";
     892            4 :             res += to_string (fnptr->get_param_type_at (i), fntype);
     893              :           }
     894            1 :         res += ")";
     895            1 :         if (!fnptr->get_return_type ()->is_unit ()
     896            1 :             || fnptr->get_return_type ()->get_kind () == TyTy::TypeKind::NEVER)
     897              :           {
     898            0 :             res += " -> ";
     899            0 :             res += to_string (fnptr->get_return_type (), fntype);
     900              :           }
     901            1 :         return res;
     902            1 :       }
     903              : 
     904            0 :     case TyTy::TypeKind::ADT:
     905            0 :       {
     906            0 :         auto adt = static_cast<const TyTy::ADTType *> (type);
     907            0 :         return adt->get_name ();
     908              :       }
     909              : 
     910            0 :     case TyTy::TypeKind::PLACEHOLDER:
     911            0 :       {
     912            0 :         auto ph = static_cast<const TyTy::PlaceholderType *> (type);
     913            0 :         return "<" + ph->get_symbol () + ">";
     914              :       }
     915              : 
     916            0 :     default:
     917            0 :       return type->as_string ();
     918              :     }
     919              : }
     920              : 
     921              : static std::string
     922           12 : to_string (IntrinsicRuleType ty)
     923              : {
     924           12 :   switch (ty)
     925              :     {
     926            0 :     case IRT::Bool:
     927            0 :       return "bool";
     928            0 :     case IRT::F32:
     929            0 :       return "f32";
     930            0 :     case IRT::F64:
     931            0 :       return "f64";
     932            0 :     case IRT::I32:
     933            0 :       return "i32";
     934            1 :     case IRT::Isize:
     935            1 :       return "isize";
     936            0 :     case IRT::U8:
     937            0 :       return "u8";
     938            0 :     case IRT::U64:
     939            0 :       return "u64";
     940            0 :     case IRT::Usize:
     941            0 :       return "usize";
     942            0 :     case IRT::Unit:
     943            0 :       return "()";
     944            1 :     case IRT::Never:
     945            1 :       return "!";
     946              : 
     947            3 :     case IRT::FirstGeneric:
     948            3 :       return "P0";
     949            1 :     case IRT::SecondGeneric:
     950            1 :       return "P1";
     951              : 
     952            2 :     case IRT::ConstPtrFirstGeneric:
     953            2 :       return "*const P0";
     954            0 :     case IRT::MutPtrFirstGeneric:
     955            0 :       return "*mut P0";
     956            0 :     case IRT::RefFirstGeneric:
     957            0 :       return "&P0";
     958              : 
     959            0 :     case IRT::RefAdt:
     960            0 :       return "&<ADT>";
     961            1 :     case IRT::MutPtrU8:
     962            1 :       return "*mut u8";
     963            0 :     case IRT::RefStaticStr:
     964            0 :       return "&'static str";
     965            0 :     case IRT::AssocTypePlaceholder:
     966            0 :       return "<AssocType>";
     967              : 
     968            1 :     case IRT::TupleFirstGenericAndBool:
     969            1 :       return "(P0, bool)";
     970              : 
     971            1 :     case IRT::Fn_MutPtrU8:
     972            1 :       return "fn(*mut u8)";
     973            1 :     case IRT::Fn_MutPtrU8MutPtrU8:
     974            1 :       return "fn(*mut u8, *mut u8)";
     975            0 :     };
     976            0 :   rust_unreachable ();
     977              : }
     978              : 
     979              : std::string
     980            5 : IntrinsicChecker::expected_intrinsic_as_string (const TyTy::FnType *fntype)
     981              : {
     982           10 :   auto it = intrinsic_rules.find (fntype->get_identifier ());
     983            5 :   rust_assert (it != intrinsic_rules.end ());
     984            5 :   auto rule = &it->second;
     985            5 :   std::stringstream result;
     986            5 :   result << "extern \"rust-intrinsic\" fn(";
     987            5 :   if (rule->param_types.size () > 0)
     988              :     {
     989           12 :       for (size_t i = 0; i < rule->param_types.size (); i++)
     990              :         {
     991            8 :           if (i != 0)
     992            4 :             result << ", ";
     993           16 :           result << to_string (rule->param_types.at (i));
     994              :         }
     995              :     }
     996            5 :   result << ")";
     997            5 :   if (rule->return_type != IntrinsicRuleType::Unit)
     998              :     {
     999            8 :       result << " -> " << to_string (rule->return_type);
    1000              :     }
    1001            5 :   return result.str ();
    1002            5 : }
    1003              : 
    1004              : std::string
    1005            5 : IntrinsicChecker::found_intrinsic_as_string (const TyTy::FnType *fntype)
    1006              : {
    1007            5 :   std::stringstream result;
    1008            5 :   result << "extern \"rust-intrinsic\" fn(";
    1009            5 :   if (fntype->get_num_params () > 0)
    1010              :     {
    1011            5 :       const auto &params = fntype->get_params ();
    1012           14 :       for (size_t i = 0; i < params.size (); i++)
    1013              :         {
    1014            9 :           if (i != 0)
    1015            4 :             result << ", ";
    1016           18 :           result << to_string (params.at (i).get_type (), fntype);
    1017              :         }
    1018              :     }
    1019            5 :   result << ")";
    1020            5 :   if (!fntype->get_return_type ()->is_unit ()
    1021            5 :       || fntype->get_return_type ()->get_kind () == TyTy::TypeKind::NEVER)
    1022              :     {
    1023           10 :       result << " -> " << to_string (fntype->get_return_type (), fntype);
    1024              :     }
    1025            5 :   return result.str ();
    1026            5 : }
    1027              : 
    1028              : } // namespace Resolver
    1029              : } // namespace Rust
        

Generated by: LCOV version 2.5.0-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.