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-12-05 16:10:02 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_CXCHG_FAILRELAXED,
     349              :      {1,
     350              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     351              :       IRT::TupleFirstGenericAndBool}},
     352              :     {IValue::ATOMIC_CXCHG_FAILACQ,
     353              :      {1,
     354              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     355              :       IRT::TupleFirstGenericAndBool}},
     356              :     {IValue::ATOMIC_CXCHG_ACQ_FAILRELAXED,
     357              :      {1,
     358              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     359              :       IRT::TupleFirstGenericAndBool}},
     360              :     {IValue::ATOMIC_CXCHG_ACQREL_FAILRELAXED,
     361              :      {1,
     362              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     363              :       IRT::TupleFirstGenericAndBool}},
     364              :     {IValue::ATOMIC_CXCHGWEAK,
     365              :      {1,
     366              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     367              :       IRT::TupleFirstGenericAndBool}},
     368              :     {IValue::ATOMIC_CXCHGWEAK_ACQ,
     369              :      {1,
     370              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     371              :       IRT::TupleFirstGenericAndBool}},
     372              :     {IValue::ATOMIC_CXCHGWEAK_REL,
     373              :      {1,
     374              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     375              :       IRT::TupleFirstGenericAndBool}},
     376              :     {IValue::ATOMIC_CXCHGWEAK_ACQREL,
     377              :      {1,
     378              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     379              :       IRT::TupleFirstGenericAndBool}},
     380              :     {IValue::ATOMIC_CXCHGWEAK_RELAXED,
     381              :      {1,
     382              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     383              :       IRT::TupleFirstGenericAndBool}},
     384              :     {IValue::ATOMIC_CXCHGWEAK_FAILRELAXED,
     385              :      {1,
     386              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     387              :       IRT::TupleFirstGenericAndBool}},
     388              :     {IValue::ATOMIC_CXCHGWEAK_FAILACQ,
     389              :      {1,
     390              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     391              :       IRT::TupleFirstGenericAndBool}},
     392              :     {IValue::ATOMIC_CXCHGWEAK_ACQ_FAILRELAXED,
     393              :      {1,
     394              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     395              :       IRT::TupleFirstGenericAndBool}},
     396              :     {IValue::ATOMIC_CXCHGWEAK_ACQREL_FAILRELAXED,
     397              :      {1,
     398              :       {IRT::MutPtrFirstGeneric, IRT::FirstGeneric, IRT::FirstGeneric},
     399              :       IRT::TupleFirstGenericAndBool}},
     400              :     // pub fn atomic_fence*/atomic_singlethreadfence*();
     401              :     {IValue::ATOMIC_FENCE, {0, {}, IRT::Unit}},
     402              :     {IValue::ATOMIC_FENCE_ACQ, {0, {}, IRT::Unit}},
     403              :     {IValue::ATOMIC_FENCE_REL, {0, {}, IRT::Unit}},
     404              :     {IValue::ATOMIC_FENCE_ACQREL, {0, {}, IRT::Unit}},
     405              :     {IValue::ATOMIC_SINGLETHREADFENCE, {0, {}, IRT::Unit}},
     406              :     {IValue::ATOMIC_SINGLETHREADFENCE_ACQ, {0, {}, IRT::Unit}},
     407              :     {IValue::ATOMIC_SINGLETHREADFENCE_REL, {0, {}, IRT::Unit}},
     408              :     {IValue::ATOMIC_SINGLETHREADFENCE_ACQREL, {0, {}, IRT::Unit}},
     409              :     // pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
     410              :     {IValue::UNCHECKED_ADD,
     411              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     412              :     // pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
     413              :     {IValue::UNCHECKED_SUB,
     414              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     415              :     // pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
     416              :     {IValue::UNCHECKED_MUL,
     417              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     418              :     // pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
     419              :     {IValue::UNCHECKED_DIV,
     420              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     421              :     // pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
     422              :     {IValue::UNCHECKED_REM,
     423              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     424              :     // pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
     425              :     {IValue::UNCHECKED_SHL,
     426              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     427              :     // pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
     428              :     {IValue::UNCHECKED_SHR,
     429              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     430              :     // pub unsafe fn uninit<T>() -> T
     431              :     {IValue::UNINIT, {1, {}, IRT::FirstGeneric}},
     432              :     // pub fn move_val_init<T>(dst: *mut T, src: T);
     433              :     {IValue::MOVE_VAL_INIT,
     434              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::Unit}},
     435              :     // pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
     436              :     {IValue::ROTATE_LEFT,
     437              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     438              :     // pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
     439              :     {IValue::ROTATE_RIGHT,
     440              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     441              :     // pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
     442              :     {IValue::WRAPPING_ADD,
     443              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     444              :     // pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
     445              :     {IValue::WRAPPING_SUB,
     446              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     447              :     // pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
     448              :     {IValue::WRAPPING_MUL,
     449              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     450              :     // pub fn saturating_add<T: Copy>(a: T, b: T) -> T;
     451              :     {IValue::SATURATING_ADD,
     452              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     453              :     // pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
     454              :     {IValue::SATURATING_SUB,
     455              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     456              :     // pub fn likely(b: bool) -> bool;
     457              :     {IValue::LIKELY, {0, {IRT::Bool}, IRT::Bool}},
     458              :     // pub fn unlikely(b: bool) -> bool;
     459              :     {IValue::UNLIKELY, {0, {IRT::Bool}, IRT::Bool}},
     460              :     // fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
     461              :     {IValue::DISCRIMINANT_VALUE,
     462              :      {1, {IRT::RefFirstGeneric}, IRT::AssocTypePlaceholder}},
     463              :     // pub fn variant_count<T>() -> usize;
     464              :     {IValue::VARIANT_COUNT, {1, {}, IRT::Usize}},
     465              :     // NOTE: The return value was temporarily set to () instead of i32.
     466              :     // pub unsafe fn catch_unwind(
     467              :     //    _try_fn: fn(_: *mut u8),
     468              :     //    _data: *mut u8,
     469              :     //    _catch_fn: fn(_: *mut u8, _: *mut u8),
     470              :     // ) -> i32
     471              :     {IValue::CATCH_UNWIND,
     472              :      {0,
     473              :       {IRT::Fn_MutPtrU8, IRT::MutPtrU8, IRT::Fn_MutPtrU8MutPtrU8},
     474              :       IRT::Unit}},
     475              :     // pub fn r#try(
     476              :     //          try_fn: fn(*mut u8),
     477              :     //          data: *mut u8,
     478              :     //          catch_fn: fn(*mut u8,
     479              :     //          *mut u8)
     480              :     // ) -> i32;
     481              :     {IValue::TRY,
     482              :      {0,
     483              :       {IRT::Fn_MutPtrU8, IRT::MutPtrU8, IRT::Fn_MutPtrU8MutPtrU8},
     484              :       IRT::I32}},
     485              :     // pub fn assume(b: bool);
     486              :     {IValue::ASSUME, {0, {IRT::Bool}, IRT::Unit}},
     487              :     // pub fn min_align_of<T>() -> usize;
     488              :     {IValue::MIN_ALIGN_OF, {1, {}, IRT::Usize}},
     489              :     // pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
     490              :     {IValue::MIN_ALIGN_OF_VAL, {1, {IRT::ConstPtrFirstGeneric}, IRT::Usize}},
     491              :     // pub fn needs_drop<T>() -> bool;
     492              :     {IValue::NEEDS_DROP, {1, {}, IRT::Bool}},
     493              :     // pub fn caller_location() -> &'static crate::panic::Location<'static>;
     494              :     {IValue::CALLER_LOCATION, {0, {}, IRT::RefAdt}},
     495              :     // pub fn ctpop<T: Copy>(x: T) -> T;
     496              :     {IValue::CTPOP, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     497              : 
     498              :     // pub fn ctlz<T: Copy>(x: T) -> T;
     499              :     {IValue::CTLZ, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     500              :     // pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
     501              :     {IValue::CTLZ_NONZERO, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     502              :     // pub fn cttz<T: Copy>(x: T) -> T;
     503              :     {IValue::CTTZ, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     504              :     // pub fn cttz_nonzero<T: Copy>(x: T) -> T;
     505              :     {IValue::CTTZ_NONZERO, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     506              :     // pub fn bswap<T: Copy>(x: T) -> T;
     507              :     {IValue::BSWAP, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     508              :     // pub fn bitreverse<T: Copy>(x: T) -> T;
     509              :     {IValue::BITREVERSE, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     510              :     // pub fn type_id<T: ?Sized + 'static>() -> u64;
     511              :     {IValue::TYPE_ID, {1, {}, IRT::U64}},
     512              :     // pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
     513              :     {IValue::PTR_GUARANTEED_EQ,
     514              :      {1, {IRT::ConstPtrFirstGeneric, IRT::ConstPtrFirstGeneric}, IRT::Bool}},
     515              :     // pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
     516              :     {IValue::PTR_GUARANTEED_NE,
     517              :      {1, {IRT::ConstPtrFirstGeneric, IRT::ConstPtrFirstGeneric}, IRT::Bool}},
     518              :     // pub fn rustc_peek<T>(_: T) -> T;
     519              :     {IValue::RUSTC_PEEK, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     520              :     // pub fn type_name<T: ?Sized>() -> &'static str;
     521              :     {IValue::TYPE_NAME, {1, {}, IRT::RefStaticStr}},
     522              :     // pub fn forget<T: ?Sized>(_: T);
     523              :     {IValue::FORGET, {1, {IRT::FirstGeneric}, IRT::Unit}},
     524              :     // pub fn black_box<T>(mut dummy: T) -> T
     525              :     {IValue::BLACK_BOX, {1, {IRT::FirstGeneric}, IRT::FirstGeneric}},
     526              : 
     527              :     // pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
     528              :     {IValue::ARITH_OFFSET,
     529              :      {1, {IRT::ConstPtrFirstGeneric, IRT::Isize}, IRT::ConstPtrFirstGeneric}},
     530              :     // fn write_bytes<T>(dst: *mut T, val: u8, count: usize)
     531              :     {IValue::WRITE_BYTES,
     532              :      {1, {IRT::MutPtrFirstGeneric, IRT::U8, IRT::Usize}, IRT::Unit}},
     533              : 
     534              :     // fn breakpoint()
     535              :     {IValue::BREAKPOINT, {0, {}, IRT::Unit}},
     536              : 
     537              :     // fn pref_align_of<T>() -> usize
     538              :     {IValue::PREF_ALIGN_OF, {1, {}, IRT::Usize}},
     539              : 
     540              :     // pub fn assert_zero_valid<T>();
     541              :     {IValue::ASSERT_ZERO_VALID, {1, {}, IRT::Unit}},
     542              :     // fn assert_inhabited<T>();
     543              :     {IValue::ASSERT_INHABITED, {1, {}, IRT::Unit}},
     544              :     // fn assert_maybe_uninit<T>();
     545              :     {IValue::ASSERT_UNINIT_VALID, {1, {}, IRT::Unit}},
     546              : 
     547              :     // pub fn fadd_fast<T>(a: T, b: T) -> T
     548              :     // same for fsub_fast, fmul_fast, fdiv_fast and frem_fast
     549              :     {IValue::FADD_FAST,
     550              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     551              :     {IValue::FSUB_FAST,
     552              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     553              :     {IValue::FMUL_FAST,
     554              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     555              :     {IValue::FDIV_FAST,
     556              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     557              :     {IValue::FREM_FAST,
     558              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     559              : 
     560              :     // fn float_to_int_unchecked<Float, Int>(x: Float) -> Int
     561              :     //     where Float: FloatPrimitive, Int: Copy
     562              :     {IValue::FLOAT_TO_INT_UNCHECKED,
     563              :      {2, {IRT::FirstGeneric}, IRT::SecondGeneric}},
     564              : 
     565              :     // fn exact_div<T>(lhs: T, rhs: T) -> T
     566              :     {IValue::EXACT_DIV,
     567              :      {1, {IRT::FirstGeneric, IRT::FirstGeneric}, IRT::FirstGeneric}},
     568              : 
     569              :     // fn nontemporal_store<T>(ptr: *mut T, value: T)
     570              :     {IValue::NONTEMPORAL_STORE,
     571              :      {1, {IRT::MutPtrFirstGeneric, IRT::FirstGeneric}, IRT::Unit}},
     572              : 
     573              :     // fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
     574              :     {IValue::PTR_OFFSET_FROM,
     575              :      {1, {IRT::ConstPtrFirstGeneric, IRT::ConstPtrFirstGeneric}, IRT::Isize}},
     576              : };
     577              : 
     578              : IntrinsicCheckResult
     579         2172 : IntrinsicChecker::check (const TyTy::FnType *fntype)
     580              : {
     581         4344 :   auto it = intrinsic_rules.find (fntype->get_identifier ());
     582         2172 :   if (it == intrinsic_rules.end ())
     583              :     {
     584           16 :       rust_error_at (fntype->get_locus (), ErrorCode::E0093,
     585              :                      "unrecognized intrinsic function: %qs",
     586            8 :                      fntype->get_identifier ().c_str ());
     587            8 :       return IntrinsicCheckResult::Invalid;
     588              :     }
     589         2164 :   auto rule = &it->second;
     590              : 
     591         2164 :   if (fntype->get_substs ().size () != rule->generic_count)
     592              :     {
     593            3 :       rust_error_at (fntype->get_locus (), ErrorCode::E0094,
     594              :                      "intrinsic has wrong number of type parameters: found "
     595              :                      "%lu, expected %lu",
     596            1 :                      (unsigned long) fntype->get_substs ().size (),
     597              :                      (unsigned long) rule->generic_count);
     598            1 :       return IntrinsicCheckResult::Invalid;
     599              :     }
     600              : 
     601         2163 :   IntrinsicCheckResult result = IntrinsicCheckResult::Valid;
     602              : 
     603         2163 :   if (fntype->get_num_params () != rule->param_types.size ())
     604              :     {
     605            3 :       rust_error_at (fntype->get_locus (), ErrorCode::E0308,
     606              :                      "intrinsic has wrong number of function parameters: found "
     607              :                      "%lu, expected %lu",
     608            1 :                      (unsigned long) fntype->get_params ().size (),
     609            1 :                      (unsigned long) rule->param_types.size ());
     610            1 :       result = IntrinsicCheckResult::Invalid;
     611              :     }
     612              :   else
     613              :     {
     614         5345 :       for (size_t i = 0; i < rule->param_types.size (); i++)
     615              :         {
     616         3183 :           const TyTy::BaseType *actual_param
     617         3183 :             = fntype->get_params ().at (i).get_type ();
     618         3183 :           IntrinsicRuleType expected_type = rule->param_types.at (i);
     619              : 
     620         3183 :           if (!check_type (actual_param, expected_type, fntype))
     621              :             {
     622            3 :               rust_error_at (fntype->get_locus (), ErrorCode::E0308,
     623              :                              "intrinsic has wrong type");
     624            3 :               result = IntrinsicCheckResult::Invalid;
     625              :             }
     626              :         }
     627              :     }
     628              : 
     629         2163 :   if (!check_type (fntype->get_return_type (), rule->return_type, fntype))
     630              :     {
     631            2 :       rust_error_at (fntype->get_locus (), ErrorCode::E0308,
     632              :                      "intrinsic has wrong type");
     633            2 :       result = IntrinsicCheckResult::Invalid;
     634              :     }
     635              : 
     636         2163 :   if (result == IntrinsicCheckResult::Invalid)
     637              :     {
     638            5 :       rust_inform (fntype->get_locus (), "expected fn pointer %qs",
     639            5 :                    expected_intrinsic_as_string (fntype).c_str ());
     640            5 :       rust_inform (fntype->get_locus (), "   found fn pointer %qs",
     641           10 :                    found_intrinsic_as_string (fntype).c_str ());
     642              :     }
     643              :   return result;
     644              : }
     645              : 
     646              : bool
     647         5533 : IntrinsicChecker::check_type (const TyTy::BaseType *actual,
     648              :                               IntrinsicRuleType expected,
     649              :                               const TyTy::FnType *fntype)
     650              : {
     651         6609 :   switch (expected)
     652              :     {
     653           23 :     case IRT::Bool:
     654           23 :       return actual->get_kind () == TyTy::TypeKind::BOOL;
     655          336 :     case IRT::F32:
     656          336 :       return actual->get_kind () == TyTy::TypeKind::FLOAT
     657          336 :              && static_cast<const TyTy::FloatType *> (actual)->get_float_kind ()
     658              :                   == TyTy::FloatType::FloatKind::F32;
     659          336 :     case IRT::F64:
     660          336 :       return actual->get_kind () == TyTy::TypeKind::FLOAT
     661          336 :              && static_cast<const TyTy::FloatType *> (actual)->get_float_kind ()
     662              :                   == TyTy::FloatType::FloatKind::F64;
     663           33 :     case IRT::I32:
     664           33 :       return actual->get_kind () == TyTy::TypeKind::INT
     665           33 :              && static_cast<const TyTy::IntType *> (actual)->get_int_kind ()
     666              :                   == TyTy::IntType::IntKind::I32;
     667          134 :     case IRT::Isize:
     668          134 :       return actual->get_kind () == TyTy::TypeKind::ISIZE;
     669           12 :     case IRT::U8:
     670           12 :       return actual->get_kind () == TyTy::TypeKind::UINT
     671           12 :              && static_cast<const TyTy::UintType *> (actual)->get_uint_kind ()
     672              :                   == TyTy::UintType::UintKind::U8;
     673            0 :     case IRT::U64:
     674            0 :       return actual->get_kind () == TyTy::TypeKind::UINT
     675            0 :              && static_cast<const TyTy::UintType *> (actual)->get_uint_kind ()
     676              :                   == TyTy::UintType::UintKind::U64;
     677          164 :     case IRT::Usize:
     678          164 :       return actual->get_kind () == TyTy::TypeKind::USIZE;
     679          242 :     case IRT::Unit:
     680          242 :       return actual->is_unit ();
     681          156 :     case IRT::Never:
     682          156 :       return actual->get_kind () == TyTy::TypeKind::NEVER;
     683              : 
     684         3839 :     case IRT::FirstGeneric:
     685         3839 :     case IRT::SecondGeneric:
     686         3839 :       {
     687         3839 :         if (actual->get_kind () != TyTy::TypeKind::PARAM)
     688              :           return false;
     689              : 
     690         3837 :         auto param = static_cast<const TyTy::ParamType *> (actual);
     691         3837 :         size_t expected_index = (expected == IRT::FirstGeneric) ? 0 : 1;
     692         3837 :         if (fntype->get_substs ().size () <= expected_index)
     693              :           return false;
     694         3837 :         auto expected_param
     695         3837 :           = fntype->get_substs ().at (expected_index).get_param_ty ();
     696         3837 :         return param->get_ty_ref () == expected_param->get_ty_ref ();
     697              :       }
     698          366 :     case IRT::ConstPtrFirstGeneric:
     699          366 :       {
     700          366 :         if (actual->get_kind () != TyTy::TypeKind::POINTER)
     701              :           return false;
     702          365 :         auto ptr = static_cast<const TyTy::PointerType *> (actual);
     703          365 :         if (!ptr->is_const ())
     704              :           return false;
     705          365 :         return check_type (ptr->get_base (), IntrinsicRuleType::FirstGeneric,
     706          365 :                            fntype);
     707              :       }
     708          626 :     case IRT::MutPtrFirstGeneric:
     709          626 :       {
     710          626 :         if (actual->get_kind () != TyTy::TypeKind::POINTER)
     711              :           return false;
     712          626 :         auto ptr = static_cast<const TyTy::PointerType *> (actual);
     713          626 :         if (!ptr->is_mutable ())
     714              :           return false;
     715          626 :         return check_type (ptr->get_base (), IntrinsicRuleType::FirstGeneric,
     716          626 :                            fntype);
     717              :       }
     718           72 :     case IRT::RefFirstGeneric:
     719           72 :       {
     720           72 :         if (actual->get_kind () != TyTy::TypeKind::REF)
     721              :           return false;
     722           72 :         auto ref = static_cast<const TyTy::ReferenceType *> (actual);
     723           72 :         if (ref->is_mutable ())
     724              :           return false;
     725           72 :         return check_type (ref->get_base (), IntrinsicRuleType::FirstGeneric,
     726           72 :                            fntype);
     727              :       }
     728            0 :     case IRT::RefAdt:
     729            0 :       {
     730            0 :         if (actual->get_kind () != TyTy::TypeKind::REF)
     731              :           return false;
     732            0 :         auto ref = static_cast<const TyTy::ReferenceType *> (actual);
     733            0 :         if (ref->is_mutable ())
     734              :           return false;
     735            0 :         return ref->get_base ()->get_kind () == TyTy::TypeKind::ADT;
     736              :       }
     737           11 :     case IRT::MutPtrU8:
     738           11 :       {
     739           11 :         if (actual->get_kind () != TyTy::TypeKind::POINTER)
     740              :           return false;
     741           11 :         auto ptr = static_cast<const TyTy::PointerType *> (actual);
     742           11 :         if (!ptr->is_mutable ())
     743              :           return false;
     744           11 :         return check_type (ptr->get_base (), IRT::U8, fntype);
     745              :       }
     746            0 :     case IRT::RefStaticStr:
     747            0 :       {
     748            0 :         if (actual->get_kind () != TyTy::TypeKind::REF)
     749              :           return false;
     750            0 :         auto ref = static_cast<const TyTy::ReferenceType *> (actual);
     751            0 :         if (ref->is_mutable ())
     752              :           return false;
     753            0 :         return ref->get_base ()->get_kind () == TyTy::TypeKind::STR;
     754              :       }
     755              :     case IRT::AssocTypePlaceholder:
     756              :       return true;
     757              : 
     758          181 :     case IRT::TupleFirstGenericAndBool:
     759          181 :       {
     760          181 :         if (actual->get_kind () != TyTy::TypeKind::TUPLE)
     761              :           return false;
     762          181 :         auto tuple = static_cast<const TyTy::TupleType *> (actual);
     763          181 :         if (tuple->num_fields () != 2)
     764              :           return false;
     765          181 :         return tuple->get_field (1)->get_kind () == TyTy::TypeKind::BOOL
     766          181 :                && check_type (tuple->get_field (0),
     767              :                               IntrinsicRuleType::FirstGeneric, fntype);
     768              :       }
     769              : 
     770            3 :     case IRT::Fn_MutPtrU8:
     771            3 :       {
     772            3 :         if (actual->get_kind () != TyTy::TypeKind::FNPTR)
     773              :           return false;
     774            2 :         auto fn = static_cast<const TyTy::FnPtr *> (actual);
     775            2 :         if (!fn->get_return_type ()->is_unit ())
     776              :           return false;
     777            2 :         if (fn->get_num_params () != 1)
     778              :           return false;
     779            2 :         return check_type (fn->get_param_type_at (0), IRT::MutPtrU8, fntype);
     780              :       }
     781            3 :     case IRT::Fn_MutPtrU8MutPtrU8:
     782            3 :       {
     783            3 :         if (actual->get_kind () != TyTy::TypeKind::FNPTR)
     784              :           return false;
     785            3 :         auto fn = static_cast<const TyTy::FnPtr *> (actual);
     786            3 :         if (!fn->get_return_type ()->is_unit ())
     787              :           return false;
     788            3 :         if (fn->get_num_params () != 2)
     789              :           return false;
     790            3 :         return check_type (fn->get_param_type_at (0), IRT::MutPtrU8, fntype)
     791            3 :                && check_type (fn->get_param_type_at (1), IRT::MutPtrU8, fntype);
     792              :       }
     793              : 
     794            0 :     default:
     795            0 :       rust_unreachable ();
     796              :     };
     797              :   return true;
     798              : }
     799              : 
     800              : static std::string
     801           22 : to_string (const TyTy::BaseType *type, const TyTy::FnType *fntype)
     802              : {
     803           22 :   switch (type->get_kind ())
     804              :     {
     805            1 :     case TyTy::TypeKind::BOOL:
     806            1 :       return "bool";
     807            3 :     case TyTy::TypeKind::USIZE:
     808            3 :       return "usize";
     809            1 :     case TyTy::TypeKind::ISIZE:
     810            1 :       return "isize";
     811            1 :     case TyTy::TypeKind::NEVER:
     812            1 :       return "!";
     813            0 :     case TyTy::TypeKind::STR:
     814            0 :       return "str";
     815              : 
     816            3 :     case TyTy::TypeKind::INT:
     817            3 :       {
     818            3 :         auto int_ty = static_cast<const TyTy::IntType *> (type);
     819            3 :         switch (int_ty->get_int_kind ())
     820              :           {
     821            0 :           case TyTy::IntType::IntKind::I8:
     822            0 :             return "i8";
     823            0 :           case TyTy::IntType::IntKind::I16:
     824            0 :             return "i16";
     825            3 :           case TyTy::IntType::IntKind::I32:
     826            3 :             return "i32";
     827            0 :           case TyTy::IntType::IntKind::I64:
     828            0 :             return "i64";
     829            0 :           case TyTy::IntType::IntKind::I128:
     830            0 :             return "i128";
     831              :           }
     832            0 :         rust_unreachable ();
     833              :       }
     834              : 
     835            3 :     case TyTy::TypeKind::UINT:
     836            3 :       {
     837            3 :         auto uint_ty = static_cast<const TyTy::UintType *> (type);
     838            3 :         switch (uint_ty->get_uint_kind ())
     839              :           {
     840            3 :           case TyTy::UintType::UintKind::U8:
     841            3 :             return "u8";
     842            0 :           case TyTy::UintType::UintKind::U16:
     843            0 :             return "u16";
     844            0 :           case TyTy::UintType::UintKind::U32:
     845            0 :             return "u32";
     846            0 :           case TyTy::UintType::UintKind::U64:
     847            0 :             return "u64";
     848            0 :           case TyTy::UintType::UintKind::U128:
     849            0 :             return "u128";
     850              :           }
     851            0 :         rust_unreachable ();
     852              :       }
     853              : 
     854            0 :     case TyTy::TypeKind::FLOAT:
     855            0 :       {
     856            0 :         auto float_ty = static_cast<const TyTy::FloatType *> (type);
     857            0 :         switch (float_ty->get_float_kind ())
     858              :           {
     859            0 :           case TyTy::FloatType::FloatKind::F32:
     860            0 :             return "f32";
     861            0 :           case TyTy::FloatType::FloatKind::F64:
     862            0 :             return "f64";
     863              :           }
     864            0 :         rust_unreachable ();
     865              :       }
     866              : 
     867            4 :     case TyTy::TypeKind::PARAM:
     868            4 :       {
     869            4 :         auto param = static_cast<const TyTy::ParamType *> (type);
     870            4 :         if (fntype != nullptr)
     871              :           {
     872            4 :             auto substs = fntype->get_substs ();
     873            8 :             for (size_t i = 0; i < substs.size (); i++)
     874              :               {
     875            8 :                 if (substs[i].get_param_ty ()->get_ty_ref ()
     876            4 :                     == param->get_ty_ref ())
     877            4 :                   return "P" + std::to_string (i);
     878              :               }
     879            4 :           }
     880            0 :         return param->get_symbol ();
     881              :       }
     882              : 
     883            4 :     case TyTy::TypeKind::POINTER:
     884            4 :       {
     885            4 :         auto ptr = static_cast<const TyTy::PointerType *> (type);
     886            4 :         std::string prefix = ptr->is_mutable () ? "*mut "
     887            1 :                              : ptr->is_const () ? "*const "
     888            5 :                                                 : "*";
     889            4 :         return prefix + to_string (ptr->get_base (), fntype);
     890            4 :       }
     891              : 
     892            0 :     case TyTy::TypeKind::REF:
     893            0 :       {
     894            0 :         auto ref = static_cast<const TyTy::ReferenceType *> (type);
     895            0 :         std::string prefix = ref->is_mutable () ? "&mut " : "&";
     896            0 :         return prefix + to_string (ref->get_base (), fntype);
     897            0 :       }
     898              : 
     899            1 :     case TyTy::TypeKind::TUPLE:
     900            1 :       {
     901            1 :         auto tuple = static_cast<const TyTy::TupleType *> (type);
     902            1 :         if (tuple->num_fields () == 0)
     903            0 :           return "()";
     904              : 
     905            1 :         std::string res = "(";
     906            3 :         for (size_t i = 0; i < tuple->num_fields (); i++)
     907              :           {
     908            2 :             if (i > 0)
     909            1 :               res += ", ";
     910            4 :             res += to_string (tuple->get_field (i), fntype);
     911              :           }
     912            1 :         res += ")";
     913            1 :         return res;
     914            1 :       }
     915              : 
     916            1 :     case TyTy::TypeKind::FNPTR:
     917            1 :       {
     918            1 :         auto fnptr = static_cast<const TyTy::FnPtr *> (type);
     919            1 :         std::string res = "fn(";
     920            3 :         for (size_t i = 0; i < fnptr->get_num_params (); i++)
     921              :           {
     922            2 :             if (i > 0)
     923            1 :               res += ", ";
     924            4 :             res += to_string (fnptr->get_param_type_at (i), fntype);
     925              :           }
     926            1 :         res += ")";
     927            1 :         if (!fnptr->get_return_type ()->is_unit ()
     928            1 :             || fnptr->get_return_type ()->get_kind () == TyTy::TypeKind::NEVER)
     929              :           {
     930            0 :             res += " -> ";
     931            0 :             res += to_string (fnptr->get_return_type (), fntype);
     932              :           }
     933            1 :         return res;
     934            1 :       }
     935              : 
     936            0 :     case TyTy::TypeKind::ADT:
     937            0 :       {
     938            0 :         auto adt = static_cast<const TyTy::ADTType *> (type);
     939            0 :         return adt->get_name ();
     940              :       }
     941              : 
     942            0 :     case TyTy::TypeKind::PLACEHOLDER:
     943            0 :       {
     944            0 :         auto ph = static_cast<const TyTy::PlaceholderType *> (type);
     945            0 :         return "<" + ph->get_symbol () + ">";
     946              :       }
     947              : 
     948            0 :     default:
     949            0 :       return type->as_string ();
     950              :     }
     951              : }
     952              : 
     953              : static std::string
     954           12 : to_string (IntrinsicRuleType ty)
     955              : {
     956           12 :   switch (ty)
     957              :     {
     958            0 :     case IRT::Bool:
     959            0 :       return "bool";
     960            0 :     case IRT::F32:
     961            0 :       return "f32";
     962            0 :     case IRT::F64:
     963            0 :       return "f64";
     964            0 :     case IRT::I32:
     965            0 :       return "i32";
     966            1 :     case IRT::Isize:
     967            1 :       return "isize";
     968            0 :     case IRT::U8:
     969            0 :       return "u8";
     970            0 :     case IRT::U64:
     971            0 :       return "u64";
     972            0 :     case IRT::Usize:
     973            0 :       return "usize";
     974            0 :     case IRT::Unit:
     975            0 :       return "()";
     976            1 :     case IRT::Never:
     977            1 :       return "!";
     978              : 
     979            3 :     case IRT::FirstGeneric:
     980            3 :       return "P0";
     981            1 :     case IRT::SecondGeneric:
     982            1 :       return "P1";
     983              : 
     984            2 :     case IRT::ConstPtrFirstGeneric:
     985            2 :       return "*const P0";
     986            0 :     case IRT::MutPtrFirstGeneric:
     987            0 :       return "*mut P0";
     988            0 :     case IRT::RefFirstGeneric:
     989            0 :       return "&P0";
     990              : 
     991            0 :     case IRT::RefAdt:
     992            0 :       return "&<ADT>";
     993            1 :     case IRT::MutPtrU8:
     994            1 :       return "*mut u8";
     995            0 :     case IRT::RefStaticStr:
     996            0 :       return "&'static str";
     997            0 :     case IRT::AssocTypePlaceholder:
     998            0 :       return "<AssocType>";
     999              : 
    1000            1 :     case IRT::TupleFirstGenericAndBool:
    1001            1 :       return "(P0, bool)";
    1002              : 
    1003            1 :     case IRT::Fn_MutPtrU8:
    1004            1 :       return "fn(*mut u8)";
    1005            1 :     case IRT::Fn_MutPtrU8MutPtrU8:
    1006            1 :       return "fn(*mut u8, *mut u8)";
    1007            0 :     };
    1008            0 :   rust_unreachable ();
    1009              : }
    1010              : 
    1011              : std::string
    1012            5 : IntrinsicChecker::expected_intrinsic_as_string (const TyTy::FnType *fntype)
    1013              : {
    1014           10 :   auto it = intrinsic_rules.find (fntype->get_identifier ());
    1015            5 :   rust_assert (it != intrinsic_rules.end ());
    1016            5 :   auto rule = &it->second;
    1017            5 :   std::stringstream result;
    1018            5 :   result << "extern \"rust-intrinsic\" fn(";
    1019            5 :   if (rule->param_types.size () > 0)
    1020              :     {
    1021           12 :       for (size_t i = 0; i < rule->param_types.size (); i++)
    1022              :         {
    1023            8 :           if (i != 0)
    1024            4 :             result << ", ";
    1025           16 :           result << to_string (rule->param_types.at (i));
    1026              :         }
    1027              :     }
    1028            5 :   result << ")";
    1029            5 :   if (rule->return_type != IntrinsicRuleType::Unit)
    1030              :     {
    1031            8 :       result << " -> " << to_string (rule->return_type);
    1032              :     }
    1033            5 :   return result.str ();
    1034            5 : }
    1035              : 
    1036              : std::string
    1037            5 : IntrinsicChecker::found_intrinsic_as_string (const TyTy::FnType *fntype)
    1038              : {
    1039            5 :   std::stringstream result;
    1040            5 :   result << "extern \"rust-intrinsic\" fn(";
    1041            5 :   if (fntype->get_num_params () > 0)
    1042              :     {
    1043            5 :       const auto &params = fntype->get_params ();
    1044           14 :       for (size_t i = 0; i < params.size (); i++)
    1045              :         {
    1046            9 :           if (i != 0)
    1047            4 :             result << ", ";
    1048           18 :           result << to_string (params.at (i).get_type (), fntype);
    1049              :         }
    1050              :     }
    1051            5 :   result << ")";
    1052            5 :   if (!fntype->get_return_type ()->is_unit ()
    1053            5 :       || fntype->get_return_type ()->get_kind () == TyTy::TypeKind::NEVER)
    1054              :     {
    1055           10 :       result << " -> " << to_string (fntype->get_return_type (), fntype);
    1056              :     }
    1057            5 :   return result.str ();
    1058            5 : }
    1059              : 
    1060              : } // namespace Resolver
    1061              : } // namespace Rust
        

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