Skip to content

Commit f51ac65

Browse files
philbertyCohenArthur
authored andcommitted
gccrs: Add missing ABI checking on function types
Addresses Rust-GCC#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 <[email protected]>
1 parent 31376c6 commit f51ac65

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

gcc/rust/typecheck/rust-unify.cc

+25
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ UnifyRules::emit_type_mismatch () const
126126
expected->get_name ().c_str (), expr->get_name ().c_str ());
127127
}
128128

129+
void
130+
UnifyRules::emit_abi_mismatch (const TyTy::FnType &expected,
131+
const TyTy::FnType &got) const
132+
{
133+
RichLocation r (locus);
134+
r.add_range (lhs.get_locus ());
135+
r.add_range (rhs.get_locus ());
136+
rust_error_at (r, "mistached abi %<%s%> got %<%s%>",
137+
get_string_from_abi (expected.get_abi ()).c_str (),
138+
get_string_from_abi (got.get_abi ()).c_str ());
139+
}
140+
129141
TyTy::BaseType *
130142
UnifyRules::go ()
131143
{
@@ -912,6 +924,19 @@ UnifyRules::expect_fndef (TyTy::FnType *ltype, TyTy::BaseType *rtype)
912924
return new TyTy::ErrorType (0);
913925
}
914926

927+
// ABI match? see
928+
// https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/extern.20blocks/near/346416045
929+
if (ltype->get_abi () != type.get_abi ())
930+
{
931+
if (emit_error)
932+
{
933+
emit_abi_mismatch (*ltype, type);
934+
}
935+
return new TyTy::ErrorType (0);
936+
}
937+
938+
// DEF Id match? see https://github.com/Rust-GCC/gccrs/issues/2053
939+
915940
return ltype->clone ();
916941
}
917942
break;

gcc/rust/typecheck/rust-unify.h

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class UnifyRules
9090
std::vector<InferenceSite> &infers);
9191

9292
void emit_type_mismatch () const;
93+
void emit_abi_mismatch (const TyTy::FnType &expected,
94+
const TyTy::FnType &got) const;
9395

9496
TyTy::BaseType *go ();
9597

0 commit comments

Comments
 (0)