]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Added noreturn checking for nevertype, new test
authorbadumbatish <tanghocle456@gmail.com>
Fri, 2 Aug 2024 18:36:04 +0000 (11:36 -0700)
committerCohenArthur <arthur.cohen@embecosm.com>
Mon, 2 Sep 2024 09:44:55 +0000 (09:44 +0000)
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.

gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/testsuite/rust/compile/inline_asm_typecheck.rs [new file with mode: 0644]

index bb1f32ed3b5f1240ee2417a0075a7c40ac68a6a2..62bbd25d485094b54e99ac9b8646c864e75458bb 100644 (file)
@@ -623,10 +623,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
     {
@@ -829,9 +828,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
@@ -1625,7 +1629,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
diff --git a/gcc/testsuite/rust/compile/inline_asm_typecheck.rs b/gcc/testsuite/rust/compile/inline_asm_typecheck.rs
new file mode 100644 (file)
index 0000000..22b7fb1
--- /dev/null
@@ -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));
+    }
+}