diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-07-30 11:57:45 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-08-05 16:37:03 +0200 |
commit | eb54ab61fd5532d08be99721ffdbb03590cc3fff (patch) | |
tree | 7da45ef1b40250a3a9dc490f00779db0c1f4de3b /gcc/testsuite/rust | |
parent | 2f054b8db9fa548443560a1187c998945fc9634a (diff) | |
download | gcc-eb54ab61fd5532d08be99721ffdbb03590cc3fff.zip gcc-eb54ab61fd5532d08be99721ffdbb03590cc3fff.tar.gz gcc-eb54ab61fd5532d08be99721ffdbb03590cc3fff.tar.bz2 |
gccrs: offset_of: Compile the offset properly
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Add proper handling
of the node.
* rust-backend.h (lookup_field): Declare it.
* rust-gcc.cc (lookup_field): Add forked implementation from gcc/c/.
gcc/testsuite/ChangeLog:
* rust/execute/torture/offset_of1.rs: New test.
Diffstat (limited to 'gcc/testsuite/rust')
-rw-r--r-- | gcc/testsuite/rust/execute/torture/offset_of1.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/execute/torture/offset_of1.rs b/gcc/testsuite/rust/execute/torture/offset_of1.rs new file mode 100644 index 0000000..7d39483 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/offset_of1.rs @@ -0,0 +1,16 @@ +// { dg-do run { target x86_64*-*-* } } +// { dg-additional-options "-frust-assume-builtin-offset-of" } + +pub struct Foo { + pub a: i32, + pub b: i32, +} + +fn main() -> i32 { + let a = offset_of!(Foo, a); // valid + let b = offset_of!(Foo, b); // valid + + let res = a + b - 4; + + res as i32 +} |