aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-10-05 12:28:38 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:09:34 +0100
commit068bdc3c6141833d533fd99234578c86658c0576 (patch)
treeb7dad078048dc1b93bfbd01aa0de44b5fe7b80f9 /gcc/rust
parent4ad869fadaf93bb2aee92c40da98ed011449b45a (diff)
downloadgcc-068bdc3c6141833d533fd99234578c86658c0576.zip
gcc-068bdc3c6141833d533fd99234578c86658c0576.tar.gz
gcc-068bdc3c6141833d533fd99234578c86658c0576.tar.bz2
gccrs: Add array length to the proc macro buffer
The compiler cannot infer the array length from the type, we should therefore hand it the information. The proc macro buffer missed that information. gcc/rust/ChangeLog: * backend/rust-compile.cc (proc_macro_buffer): Update type builder with array length information. (proc_macro_array): Update type initializer with array length information. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/backend/rust-compile.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index f400d69..d0052fe 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -207,8 +207,14 @@ proc_macro ()
tree
proc_macro_buffer (tree proc_macro_type, size_t total_macro)
{
- // FIXME: Add the array length, build a structure containing an array
- return build_array_type_nelts (proc_macro_type, total_macro);
+ auto length_field = Backend::typed_identifier ("length", unsigned_type_node,
+ BUILTINS_LOCATION);
+
+ auto array_type = build_array_type_nelts (proc_macro_type, total_macro);
+ auto macros_field
+ = Backend::typed_identifier ("macros", array_type, BUILTINS_LOCATION);
+
+ return Backend::struct_type ({length_field, macros_field});
}
// The entrypoint of a proc macro crate is a reference to the proc macro buffer
@@ -374,8 +380,15 @@ proc_macro_array (Context *ctx, tree proc_macro_buffer_type,
index++;
}
- return Backend::array_constructor_expression (proc_macro_buffer_type, indexes,
- ctors, BUILTINS_LOCATION);
+ auto length = build_int_cst (unsigned_type_node, ctors.size ());
+ auto array = Backend::array_constructor_expression (
+ build_array_type_nelts (proc_macro_type, ctors.size ()), indexes, ctors,
+ BUILTINS_LOCATION);
+ return Backend::constructor_expression (proc_macro_buffer_type,
+ false /* invariant */,
+ {length, array},
+ -1 /* Structure: No index */,
+ BUILTINS_LOCATION);
}
} // namespace init