From eb54ab61fd5532d08be99721ffdbb03590cc3fff Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Wed, 30 Jul 2025 11:57:45 +0200 Subject: 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. --- gcc/rust/rust-gcc.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gcc/rust/rust-gcc.cc') diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index 0f9ccfb..398dea1 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -2366,4 +2366,30 @@ write_global_definitions (const std::vector &type_decls, delete[] defs; } +tree +lookup_field (const_tree type, tree component) +{ + tree field; + + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) + { + if (DECL_NAME (field) == NULL_TREE + && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))) + { + tree anon = lookup_field (TREE_TYPE (field), component); + + if (anon) + return tree_cons (NULL_TREE, field, anon); + } + + if (DECL_NAME (field) == component) + break; + } + + if (field == NULL_TREE) + return NULL_TREE; + + return tree_cons (NULL_TREE, field, NULL_TREE); +} + } // namespace Backend -- cgit v1.1