From: Philip Herron Date: Sun, 23 Apr 2023 22:12:45 +0000 (+0100) Subject: gccrs: Add missing ABI checking on function types X-Git-Tag: basepoints/gcc-15~2611 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd8fb58695f752b04acf3c934f9f0d33d0e0d75f;p=thirdparty%2Fgcc.git gccrs: Add missing ABI checking on function types 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 --- diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 6e39e98dfb1d..027ec5551502 100644 --- a/gcc/rust/typecheck/rust-unify.cc +++ b/gcc/rust/typecheck/rust-unify.cc @@ -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; diff --git a/gcc/rust/typecheck/rust-unify.h b/gcc/rust/typecheck/rust-unify.h index fecb21ec1e7c..4867746bbb5b 100644 --- a/gcc/rust/typecheck/rust-unify.h +++ b/gcc/rust/typecheck/rust-unify.h @@ -90,6 +90,8 @@ private: std::vector &infers); void emit_type_mismatch () const; + void emit_abi_mismatch (const TyTy::FnType &expected, + const TyTy::FnType &got) const; TyTy::BaseType *go ();