diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-04-23 23:12:45 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:34:14 +0100 |
commit | dd8fb58695f752b04acf3c934f9f0d33d0e0d75f (patch) | |
tree | 5588bc9f6619345c2e84f2553a9f44bd073a15a7 /gcc | |
parent | a92d1cc9b51d5b708b1c4d1cb409cf6ee8a29f38 (diff) | |
download | gcc-dd8fb58695f752b04acf3c934f9f0d33d0e0d75f.zip gcc-dd8fb58695f752b04acf3c934f9f0d33d0e0d75f.tar.gz gcc-dd8fb58695f752b04acf3c934f9f0d33d0e0d75f.tar.bz2 |
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 <herron.philip@googlemail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-unify.cc | 25 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-unify.h | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 6e39e98..027ec55 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 fecb21e..4867746 100644 --- a/gcc/rust/typecheck/rust-unify.h +++ b/gcc/rust/typecheck/rust-unify.h @@ -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 (); |