From 6526a80758d1b0333fcc9900add737aad792622f Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Thu, 30 Nov 2023 10:43:36 +0100 Subject: [PATCH 1/2] Add multiple regression test in name resolution Local variables and functions or global variables have different resolution when binded to a variable. This was not covered before, even though it was handled by the new name resolution. This commit highlight this behavior from the new name resolution mechanism. gcc/testsuite/ChangeLog: * rust/compile/name_resolution11.rs: New test. * rust/compile/name_resolution12.rs: New test. * rust/compile/name_resolution13.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/name_resolution11.rs | 7 +++++++ gcc/testsuite/rust/compile/name_resolution12.rs | 10 ++++++++++ gcc/testsuite/rust/compile/name_resolution13.rs | 9 +++++++++ 3 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/rust/compile/name_resolution11.rs create mode 100644 gcc/testsuite/rust/compile/name_resolution12.rs create mode 100644 gcc/testsuite/rust/compile/name_resolution13.rs diff --git a/gcc/testsuite/rust/compile/name_resolution11.rs b/gcc/testsuite/rust/compile/name_resolution11.rs new file mode 100644 index 000000000000..a464d2a0fd3e --- /dev/null +++ b/gcc/testsuite/rust/compile/name_resolution11.rs @@ -0,0 +1,7 @@ +// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" } +fn foo() { + let b = 10; + fn bar() { + let a = foo; + } +} diff --git a/gcc/testsuite/rust/compile/name_resolution12.rs b/gcc/testsuite/rust/compile/name_resolution12.rs new file mode 100644 index 000000000000..9cce31ceb5c2 --- /dev/null +++ b/gcc/testsuite/rust/compile/name_resolution12.rs @@ -0,0 +1,10 @@ +// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" } + +const TOTO: i32 = 10; + +fn foo() { + let b = 10; + fn bar() { + let e = TOTO; + } +} diff --git a/gcc/testsuite/rust/compile/name_resolution13.rs b/gcc/testsuite/rust/compile/name_resolution13.rs new file mode 100644 index 000000000000..52a152bf51a5 --- /dev/null +++ b/gcc/testsuite/rust/compile/name_resolution13.rs @@ -0,0 +1,9 @@ +// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" } + +fn foo() { + let b = 10; + fn bar() { + let c = b; + // { dg-error "cannot find value .b. in this scope .E0425." "" { target *-*-* } .-1 } + } +} From 717bcf8d3e12a8451ff4b8146c86f9826455608c Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Thu, 30 Nov 2023 13:27:01 +0100 Subject: [PATCH 2/2] Add execution test for name resolution 2.0 We already have some compile tests but it lacked an execution test to ensure everything compiles correctly to the correct value. gcc/testsuite/ChangeLog: * rust/execute/torture/name_resolution.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- .../rust/execute/torture/name_resolution.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 gcc/testsuite/rust/execute/torture/name_resolution.rs diff --git a/gcc/testsuite/rust/execute/torture/name_resolution.rs b/gcc/testsuite/rust/execute/torture/name_resolution.rs new file mode 100644 index 000000000000..749218352d64 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/name_resolution.rs @@ -0,0 +1,24 @@ +// { dg-additional-options "-frust-name-resolution-2.0" } +// { dg-output "Value is 10\r*\n" } + +const BAZ: i32 = 10; + +extern "C" { + fn printf(s: *const i8, ...); +} + +fn foo() { + fn bar() { + let e = BAZ; + unsafe { + printf("Value is %i\n" as *const str as *const i8, e); + } + } + + bar(); +} + +fn main() -> i32 { + foo(); + 0 +}