Skip to content

Commit

Permalink
Added noreturn checking for nevertype, new test
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
	Added noreturn checking for nevertype

gcc/testsuite/ChangeLog:

	* rust/compile/inline_asm_typecheck.rs: New test.
  • Loading branch information
badumbatish committed Aug 2, 2024
1 parent e0b05ae commit a8c24ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
18 changes: 11 additions & 7 deletions gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,9 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
&& (((TyTy::InferType *) loop_context_type)->get_infer_kind ()
!= TyTy::InferType::GENERAL));

infered = loop_context_type_infered
? loop_context_type
: TyTy::TupleType::get_unit_type (
expr.get_mappings ().get_hirid ());
infered = loop_context_type_infered ? loop_context_type
: TyTy::TupleType::get_unit_type (
expr.get_mappings ().get_hirid ());
}
else
{
Expand Down Expand Up @@ -827,9 +826,14 @@ TypeCheckExpr::visit (HIR::InlineAsm &expr)
{
typecheck_inline_asm_operand (expr);

// TODO: Hoise out if we have noreturn as an option
// NOTE: Hoise out if we have noreturn as an option
// to return a never type
infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
// TODO : new keyword for memory seems sooooo shaky
if (expr.options.count (AST::InlineAsmOption::NORETURN) == 1)
infered = new TyTy::NeverType (expr.get_mappings ().get_hirid ());
else
infered
= TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
}

void
Expand Down Expand Up @@ -1613,7 +1617,7 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr)
TyTy::TyVar result_type
= expr.has_return_type ()
? TyTy::TyVar (
TypeCheckType::Resolve (expr.get_return_type ().get ())->get_ref ())
TypeCheckType::Resolve (expr.get_return_type ().get ())->get_ref ())
: TyTy::TyVar::get_implicit_infer_var (expr.get_locus ());

// resolve the block
Expand Down
21 changes: 21 additions & 0 deletions gcc/testsuite/rust/compile/inline_asm_typecheck.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![feature(rustc_attrs)]

#[rustc_builtin_macro]
macro_rules! asm {
() => {};
}

fn main() {
let mut _num1: i32 = 10;
let mut _num2: i32 = 10;
unsafe {
// This demonstrates that asm!'s is inferred with a unit type is parsed correctly.
let _ = asm!("nop");

// This errors out per rust spec
// The asm! block never returns, and its return type is defined as ! (never).
// Behavior is undefined if execution falls through past the end of the asm code.
// A noreturn asm block behaves just like a function which doesn't return; notably, local variables in scope are not dropped before it is invoked.
let _ = asm!("nop", options(noreturn));
}
}

0 comments on commit a8c24ef

Please sign in to comment.