add function calls

This commit is contained in:
Bastian Kauschke 2020-09-11 10:35:28 +02:00
parent d1294e0ce2
commit c7d16df1d8
2 changed files with 48 additions and 0 deletions

View File

@ -242,6 +242,24 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
match terminator.kind {
TerminatorKind::Goto { target } => Some(Some(target)),
TerminatorKind::Return => Some(None),
TerminatorKind::Call {
ref func,
ref args,
destination: Some((ref place, target)),
cleanup: _,
from_hir_call: true,
fn_span: _,
} => {
let local = place.as_local()?;
let func = self.operand_to_node(func)?;
let args = self.tcx.arena.alloc_from_iter(
args.iter()
.map(|arg| self.operand_to_node(arg))
.collect::<Option<Vec<NodeId>>>()?,
);
self.locals[local] = self.nodes.push(Node::FunctionCall(func, args));
Some(Some(target))
}
TerminatorKind::Assert { ref cond, expected: false, target, .. } => {
let p = match cond {
mir::Operand::Copy(p) | mir::Operand::Move(p) => p,

View File

@ -0,0 +1,30 @@
// run-pass
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]
const fn test_me<T>(a: usize, b: usize) -> usize {
if a < b {
std::mem::size_of::<T>()
} else {
std::usize::MAX
}
}
fn test_simple<T>() -> [u8; std::mem::size_of::<T>()]
where
[u8; std::mem::size_of::<T>()]: Sized,
{
[0; std::mem::size_of::<T>()]
}
fn test_with_args<T, const N: usize>() -> [u8; test_me::<T>(N, N + 1) + N]
where
[u8; test_me::<T>(N, N + 1) + N]: Sized,
{
[0; test_me::<T>(N, N + 1) + N]
}
fn main() {
assert_eq!([0; 8], test_simple::<u64>());
assert_eq!([0; 12], test_with_args::<u64, 4>());
}