aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-10-05 14:43:24 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-10-05 14:43:24 +0100
commit591b43e42e7f63841ce46fdd4f2760e47b6a7b0d (patch)
treeca78a39cfaa6563575ad6567d5cd30484bfcd08a /gcc
parent6cd07341b1057961bebc8c11d70909ccac781113 (diff)
downloadgcc-591b43e42e7f63841ce46fdd4f2760e47b6a7b0d.zip
gcc-591b43e42e7f63841ce46fdd4f2760e47b6a7b0d.tar.gz
gcc-591b43e42e7f63841ce46fdd4f2760e47b6a7b0d.tar.bz2
Coercion site type checking in CallExprs must hold onto the argument type
Coercion sites like CallExpr arguments must coerce the arguments for type checking, but we must still insert the type of the actual argument for that mapping not the coerced type. For example we might have: ```rust fn dynamic_dispatch(t: &dyn Bar) { t.baz(); } fn main() { let a = &Foo(123); dynamic_dispatch(a); } ``` Here the argument 'a' has a type of (&ADT{Foo}) but this is coerceable to (&dyn{Bar}) which is fine. The backend needs to be able to detect the coercion from the two types in order to generate the vtable code. This patch fixes the type checking such that we store the actual type of (&ADT{Foo}) at that argument mapping instead of the coerced one. Addresses: #700
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc17
-rw-r--r--gcc/testsuite/rust/compile/func3.rs6
2 files changed, 13 insertions, 10 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 64eab30..05e5942 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2454,14 +2454,13 @@ TypeCheckCallExpr::visit (FnType &type)
return;
}
- auto resolved_argument_type = argument_expr_tyty;
-
// it might be a varadic function
if (i < type.num_params ())
{
auto fnparam = type.param_at (i);
- resolved_argument_type = fnparam.second->coerce (argument_expr_tyty);
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+ auto resolved_argument_type
+ = fnparam.second->coerce (argument_expr_tyty);
+ if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (argument->get_locus (),
"Type Resolution failure on parameter");
@@ -2469,7 +2468,7 @@ TypeCheckCallExpr::visit (FnType &type)
}
}
- context->insert_type (argument->get_mappings (), resolved_argument_type);
+ context->insert_type (argument->get_mappings (), argument_expr_tyty);
i++;
}
@@ -2522,14 +2521,14 @@ TypeCheckCallExpr::visit (FnPtr &type)
}
auto resolved_argument_type = fnparam->coerce (argument_expr_tyty);
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+ if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (argument->get_locus (),
"Type Resolution failure on parameter");
return;
}
- context->insert_type (argument->get_mappings (), resolved_argument_type);
+ context->insert_type (argument->get_mappings (), argument_expr_tyty);
i++;
}
@@ -2575,14 +2574,14 @@ TypeCheckMethodCallExpr::visit (FnType &type)
}
auto resolved_argument_type = fnparam.second->coerce (argument_expr_tyty);
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+ if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (argument->get_locus (),
"Type Resolution failure on parameter");
return;
}
- context->insert_type (argument->get_mappings (), resolved_argument_type);
+ context->insert_type (argument->get_mappings (), argument_expr_tyty);
i++;
}
diff --git a/gcc/testsuite/rust/compile/func3.rs b/gcc/testsuite/rust/compile/func3.rs
index 6cedf8e..3ab374a 100644
--- a/gcc/testsuite/rust/compile/func3.rs
+++ b/gcc/testsuite/rust/compile/func3.rs
@@ -3,5 +3,9 @@ fn test(a: i32, b: i32) -> i32 {
}
fn main() {
- let a = test(1, true); // { dg-error "expected .i32. got .bool." }
+ let a = test(1, true);
+ // { dg-error "expected .i32. got .bool." "" { target *-*-* } .-1 }
+ // { dg-error "Type Resolution failure on parameter" "" { target *-*-* } .-2 }
+ // { dg-error "failed to lookup type to CallExpr" "" { target *-*-* } .-3 }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-4 }
}