diff options
author | Philip Herron <herron.philip@googlemail.com> | 2024-12-13 15:51:55 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-21 12:55:43 +0100 |
commit | 18d289ca2b1996aa76b902432941e88fa3497b6d (patch) | |
tree | 65f60208bf1641e919bc1a81ee0e5e0f126c7439 /gcc/testsuite/rust/compile | |
parent | 7bf460b338845d1b9a581cca70a3191f76769816 (diff) | |
download | gcc-18d289ca2b1996aa76b902432941e88fa3497b6d.zip gcc-18d289ca2b1996aa76b902432941e88fa3497b6d.tar.gz gcc-18d289ca2b1996aa76b902432941e88fa3497b6d.tar.bz2 |
gccrs: implement the TuplePattern and use it for function patterns
In order to handle the tuple pattern of: fn test ((x _) : (i32, i32)) -> i32 { x }
we need to recognize that ABI wise this function still takes a tuple as the parameter
to this function its just how we can address the "pattern" of the tuple changes.
So reall if this was C it would look like:
void test (struct tuple_type __prameter)
{
return __parameter.0
}
The code here reuses our existing pattern code so that we generate these implicit
bindings of the paramter with a field access so any time x is referenced it's really
just emplacing __parameter.0 for the field access into the struct which is a tuple.
Fixes Rust-GCC#2847
gcc/rust/ChangeLog:
* backend/rust-compile-fnparam.cc (CompileFnParam::visit): compile tuple patterns
(CompileSelfParam::compile): update return type
(CompileFnParam::create_tmp_param_var): return Bvariable not tree to stop ICE
* backend/rust-compile-fnparam.h: update prototype
* backend/rust-compile-pattern.cc (CompilePatternBindings::visit): implement TuplePattern
* backend/rust-compile-pattern.h: update prototype
gcc/testsuite/ChangeLog:
* rust/compile/issue-2847.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/testsuite/rust/compile')
-rw-r--r-- | gcc/testsuite/rust/compile/issue-2847.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/issue-2847.rs b/gcc/testsuite/rust/compile/issue-2847.rs new file mode 100644 index 0000000..2bc5566 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2847.rs @@ -0,0 +1,8 @@ +pub fn myfun1((x, _): (i32, i32)) -> i32 { + x +} + +pub fn myfun2() -> i32 { + let (x, _) = (1, 2); + x +} |