]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add missing ABI checking on function types
authorPhilip Herron <herron.philip@googlemail.com>
Sun, 23 Apr 2023 22:12:45 +0000 (23:12 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:34:14 +0000 (18:34 +0100)
Addresses #2304

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
(UnifyRules::expect_fndef): add ABI check
* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-unify.cc
gcc/rust/typecheck/rust-unify.h

index 6e39e98dfb1df83f5feda948bcb131d77619bf7e..027ec5551502e4edea6a43e49427abf58d9a188f 100644 (file)
@@ -126,6 +126,18 @@ UnifyRules::emit_type_mismatch () const
                 expected->get_name ().c_str (), expr->get_name ().c_str ());
 }
 
+void
+UnifyRules::emit_abi_mismatch (const TyTy::FnType &expected,
+                              const TyTy::FnType &got) const
+{
+  RichLocation r (locus);
+  r.add_range (lhs.get_locus ());
+  r.add_range (rhs.get_locus ());
+  rust_error_at (r, "mistached abi %<%s%> got %<%s%>",
+                get_string_from_abi (expected.get_abi ()).c_str (),
+                get_string_from_abi (got.get_abi ()).c_str ());
+}
+
 TyTy::BaseType *
 UnifyRules::go ()
 {
@@ -912,6 +924,19 @@ UnifyRules::expect_fndef (TyTy::FnType *ltype, TyTy::BaseType *rtype)
            return new TyTy::ErrorType (0);
          }
 
+       // ABI match? see
+       // https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/extern.20blocks/near/346416045
+       if (ltype->get_abi () != type.get_abi ())
+         {
+           if (emit_error)
+             {
+               emit_abi_mismatch (*ltype, type);
+             }
+           return new TyTy::ErrorType (0);
+         }
+
+       // DEF Id match? see https://github.com/Rust-GCC/gccrs/issues/2053
+
        return ltype->clone ();
       }
       break;
index fecb21ec1e7ca81f054feb98225104cd29512f58..4867746bbb5be9f6910bb7b05f942c77aa4988c7 100644 (file)
@@ -90,6 +90,8 @@ private:
              std::vector<InferenceSite> &infers);
 
   void emit_type_mismatch () const;
+  void emit_abi_mismatch (const TyTy::FnType &expected,
+                         const TyTy::FnType &got) const;
 
   TyTy::BaseType *go ();