This implementation differs significantly from the
std::experimental::simd implementation. One goal was a reduction in
template instantiations wrt. what std::experimental::simd did.
Design notes:
- bits/vec_ops.h contains concepts, traits, and functions for working
with GNU vector builtins that are mostly independent from std::simd.
These could move from std::simd:: to std::__vec (or similar). However,
we would then need to revisit naming. For now we kept everything in
the std::simd namespace with __vec_ prefix in the names. The __vec_*
functions can be called unqualified because they can never be called
on user-defined types (no ADL). If we ever get simd<UDT> support this
will be implemented via bit_cast to/from integral vector
builtins/intrinsics.
- bits/simd_x86.h extends vec_ops.h with calls to __builtin_ia32_* that
can only be used after uttering the right GCC target pragma.
- basic_vec and basic_mask are built on top of register-size GNU vector
builtins (for now / x86). Any larger vec/mask is a tree of power-of-2
#elements on the "first" branch. Anything non-power-of-2 that is
smaller than register size uses padding elements that participate in
element-wise operations. The library ensures that padding elements
lead to no side effects. The implementation makes no assumption on the
values of these padding elements since the user can bit_cast to
basic_vec/basic_mask.
Implementation status:
- The implementation is prepared for more than x86 but is x86-only for
now.
- Parts of [simd] *not* implemented in this patch:
- std::complex<floating-point> as vectorizable types
- [simd.permute.dynamic]
- [simd.permute.mask]
- [simd.permute.memory]
- [simd.bit]
- [simd.math]
- mixed operations with vec-mask and bit-mask types
- some conversion optimizations (open questions wrt. missed
optimizations in the compiler)
- This patch implements P3844R3 "Restore simd::vec broadcast from int",
which is not part of the C++26 WD draft yet. If the paper does not get
accepted the feature will be reverted.
- This patch implements D4042R0 "incorrect cast between simd::vec and
simd::mask via conversion to and from impl-defined vector types" (to be
published once the reported LWG issue gets a number).
- The standard feature test macro __cpp_lib_simd is not defined yet.
Tests:
- Full coverage requires testing
1. constexpr,
2. constant-propagating inputs, and
3. unknown (to the optimizer) inputs
- for all vectorizable types
* for every supported width (1–64 and higher)
+ for all possible ISA extensions (combinations)
= with different fast-math flags
... leading to a test matrix that's far out of reach for regular
testsuite builds.
- The tests in testsuite/std/simd/ try to cover all of the API. The
tests can be build in every combination listed above. Per default only
a small subset is built and tested.
- Use GCC_TEST_RUN_EXPENSIVE=something to compile the more expensive
tests (constexpr and const-prop testing) and to enable more /
different widths for the test type.
- Tests can still emit bogus -Wpsabi warnings (see PR98734) which are
filtered out via dg-prune-output.
Benchmarks:
- The current implementation has been benchmarked in some aspects on
x86_64 hardware. There is more optimization potential. However, it is
not always clear whether optimizations should be part of the library
if they can be implemented in the compiler.
- No benchmark code is included in this patch.
libstdc++-v3/ChangeLog:
* include/Makefile.am: Add simd headers.
* include/Makefile.in: Regenerate.
* include/bits/version.def (simd): New.
* include/bits/version.h: Regenerate.
* include/bits/simd_alg.h: New file.
* include/bits/simd_details.h: New file.
* include/bits/simd_flags.h: New file.
* include/bits/simd_iterator.h: New file.
* include/bits/simd_loadstore.h: New file.
* include/bits/simd_mask.h: New file.
* include/bits/simd_mask_reductions.h: New file.
* include/bits/simd_reductions.h: New file.
* include/bits/simd_vec.h: New file.
* include/bits/simd_x86.h: New file.
* include/bits/vec_ops.h: New file.
* include/std/simd: New file.
* testsuite/std/simd/arithmetic.cc: New test.
* testsuite/std/simd/arithmetic_expensive.cc: New test.
* testsuite/std/simd/create_tests.h: New file.
* testsuite/std/simd/creation.cc: New test.
* testsuite/std/simd/creation_expensive.cc: New test.
* testsuite/std/simd/loads.cc: New test.
* testsuite/std/simd/loads_expensive.cc: New test.
* testsuite/std/simd/mask2.cc: New test.
* testsuite/std/simd/mask2_expensive.cc: New test.
* testsuite/std/simd/mask.cc: New test.
* testsuite/std/simd/mask_expensive.cc: New test.
* testsuite/std/simd/reductions.cc: New test.
* testsuite/std/simd/reductions_expensive.cc: New test.
* testsuite/std/simd/shift_left.cc: New test.
* testsuite/std/simd/shift_left_expensive.cc: New test.
* testsuite/std/simd/shift_right.cc: New test.
* testsuite/std/simd/shift_right_expensive.cc: New test.
* testsuite/std/simd/simd_alg.cc: New test.
* testsuite/std/simd/simd_alg_expensive.cc: New test.
* testsuite/std/simd/sse_intrin.cc: New test.
* testsuite/std/simd/stores.cc: New test.
* testsuite/std/simd/stores_expensive.cc: New test.
* testsuite/std/simd/test_setup.h: New file.
* testsuite/std/simd/traits_common.cc: New test.
* testsuite/std/simd/traits_impl.cc: New test.
* testsuite/std/simd/traits_math.cc: New test.
Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
This is a minimal fix to not just silently drop the section attribute on
stream-in. Ideally we should be using cplus_decl_attributes for this,
but it's not yet ready for modules (many attributes behave weirdly when
applied not during parsing). We should also be checking for
incompatible sections on stream-in in is_matching_decl, but that would
also be better handled more generally so I'm leaving that out of this
patch.
Instead this minimally fixes the issue by just re-applying the section
name from the attributes we've streamed in.
PR c++/122786
gcc/cp/ChangeLog:
* module.cc (trees_in::decl_value): Set section name from
attribute.
gcc/testsuite/ChangeLog:
* g++.dg/modules/attrib-5_a.C: New test.
* g++.dg/modules/attrib-5_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
The [[maybe_unused]] attribute works by marking relevant entities as
TREE_USED, and DECL_READ_P for vars and parms. But modules streaming
typically clears this flag unless reading a definition. This patch sets
it back again when we see this attribute applied to a parameter.
PR c++/124483
gcc/cp/ChangeLog:
* module.cc (trees_in::fn_parms_init): Set TREE_USED and
DECL_READ_P for parameters deliberately marked unused.
gcc/testsuite/ChangeLog:
* g++.dg/modules/attrib-4_a.C: New test.
* g++.dg/modules/attrib-4_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
Support for iterators on mapper functions is an OpenMP 5.2
feature that is not implemented yet. Presently attempting to use
this feature results in an ICE; let's make it a more user-friendly
"sorry" until we get around to implementing this.
gcc/ChangeLog
PR c/122866
* gimplify.cc (omp_instantiate_mapper): Give a sorry if there are
iterators.
gcc/testsuite/ChangeLog
PR c/122866
* c-c++-common/gomp/pr122866.c: New.
Co-authored-by: Sandra Loosemore <sloosemore@baylibre.com>
gimplify_omp_workshare() correctly handles iterators in the "target"
construct but missed the very similar case for "target data", causing
an ICE.
gcc/ChangeLog
* gimplify.cc (gimplify_omp_workshare): Handle iterators in
"target data".
gcc/testsuite/ChangeLog
* c-c++-common/gomp/target-map-iterators-6.c: New.
libgomp/ChangeLog
* testsuite/libgomp.c-c++-common/target-data-iterators-1.c: New.
Co-authored-by: Sandra Loosemore <sloosemore@baylibre.com>
The overall strategy for types declared with implicit dereference is to add
two interpretations for every name, the direct one and the one corresponding
to the generalized reference. But the two interpretations are not always
preserved through the analysis and, more importantly, the resolution stops
at the first couple of interpretations for such a name, disregarding more
traditional overloading of specific names.
The change makes sure that the two interpretation are preserved through the
analysis, and implements the proper resolution of traditionally overloaded
names in the presence of types with implicit dereference. It also performs
some streamlining in the common processing of overloaded nodes in Resolve.
gcc/ada/
PR ada/120669
* sem_ch4.adb (Analyze_Explicit_Dereference): Remove interpretations
of the prefix only if they are of access types.
(Analyze_One_Call.Indicate_Name_And_Type): Check for an implicit
dereference only after indicating the name and type of the call.
* sem_ch5.adb (Analyze_Assignment): Do not remove interpretations
for the LHS if they are for a type with implicit dereference.
* sem_res.adb (Resolve): Streamline the processing of overloaded
nodes once an interpretation is picked for them. Add a specific
handling for additional interpretations for generalized references.
(Resolve_Explicit_Dereference): Remove interpretations of the prefix
only if they are of access types.
(Is_Ambiguous_Operand): Skip the direct interpretation for a limited
type that has implicit dereference.
* sem_type.adb (Add_One_Interp): Set the name of the first entry of
the table of interpretations in more cases.
gcc/testsuite/
* gnat.dg/implicit_deref1.adb: New test.
* gnat.dg/implicit_deref2.adb: Likewise.
* gnat.dg/implicit_deref3.adb: Likewise.
Here we ICE in output_constant because we attempt to emit the temporary
created for lifetime extension of a consteval-only expression. Like
other consteval-only variables, the temporary also has to be marked
DECL_EXTERNAL so that we don't emit it.
I tried to do the setting in make_temporary_var_for_ref_to_temp, but
then we ICE in set_decl_context_in_fn.
PR c++/124575
gcc/cp/ChangeLog:
* call.cc (set_up_extended_ref_temp): If var is consteval-only,
mark it DECL_EXTERNAL.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/expr16.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
Inner attribute injection was not within the injection function where
the other things get injected within a crate.
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::compile_crate): Use additional
cli attributes for the injection function. Move additional attribute
injection from here...
(Session::injection): ... to here.
* rust-session-manager.h: Update injection fonction prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
It is often required to inject some inner attributes to a crate from the
CLI. It has been required recently for fuzzing the compiler easily.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Crate::inject_inner_attribute): Add member function
to inject an inner attribute.
* ast/rust-ast.h: Add function prototype.
* lang.opt: Add frust-crate-attr argument to the compiler CLI.
* rust-lang.cc: Remove unused attribute on option handler.
* rust-session-manager.cc (Session::handle_crate_name): Collect CLI
additional inner attributes.
(Session::compile_crate): Parse the additional inner attributes and
inject them.
* rust-session-manager.h (struct CompileOptions): Add collection of
additional inner attributes.
gcc/testsuite/ChangeLog:
* rust/compile/cli_inner_attribute_injection.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
no_std is a builtin attribute required for rust-for-linux but was
missing from the builtin attribute list and instead considered an unknown
attribute macro invocation.
gcc/rust/ChangeLog:
* util/rust-attributes.cc: Add no_std to list of builtin attributes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This patch implements the bswap intrinsic for integer types. It maps to the respective GCC built-ins for 16, 32, 64 and 128-bit integers.
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: Add bswap_handler.
* backend/rust-intrinsic-handlers.cc (bswap_handler): New function.
* backend/rust-intrinsic-handlers.h (bswap_handler): New declaration.
gcc/testsuite/ChangeLog:
* rust/compile/bswap.rs: New test.
* rust/execute/bswap.rs: New test.
Signed-off-by: Enes Cevik <nsvke@proton.me>
The compiler was accepting `#![no_core]` without requiring
`#![feature(no_core)]`, silently treating an unstable attribute
as stable. Gate it via check_no_core_attribute, consistent with
how other experimental attributes are handled.
Fixes: Rust-GCC#4461
gcc/rust/ChangeLog:
* checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Call check_no_core_attri.
* checks/errors/feature/rust-feature-gate.h: Declare method check_no_core_attri.
gcc/testsuite/ChangeLog:
* rust/compile/match-scope.rs: Fix test.
* rust/compile/no_core_feature_gate.rs: New test.
Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>
This patch adds an ambiguity check in 'finalize_rebind_import'.
If a Definition is ambiguous, it emits a proper error diagnostic
instead of crashing, consistent with rustc's behavior(verified)
FixesRust-GCC/gccrs#4411
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Add ambiguity
check before calling get_node_id() on glob import definitions.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4411.rs: New test.
Signed-off-by: Harishankar <harishankarpp7@gmail.com>
The compiler should not emit any unused function warning on function name
prefixed with an underscore.
gcc/rust/ChangeLog:
* checks/lints/rust-lint-scan-deadcode.h: Add additional condition
to prevent warning emission. Check for underscore prefix.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3947.rs: Do not expect a warning on this
underscore prefixed function.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* parse/rust-parse-error.h (struct EnumVariant): Add error for enum
variant.
* parse/rust-parse-impl.hxx: Use new error type instead of nullptr.
* parse/rust-parse.h: Update function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* checks/lints/rust-lint-unused-var.cc (starts_with_underscore): Add
function to detect underscore within symbol name.
(check_decl): Call new function for underscore checking.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Every wildcard should be considered different and no error should be
emitted when multiple wildcards are used within the same rib.
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc(TopLevel::visit): Insert
constant item only if now wildcard.
gcc/testsuite/ChangeLog:
* rust/compile/wildcard_items.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
When encountering `#[derive(RustcEncodable)]` or `RustcDecodable`, the
`DeriveVisitor` previously fell through to `rust_unreachable ()`,
causing an Internal Compiler Error.
This patch adds cases for these built-in macros to explicitly emit a
"sorry, unimplemented" message instead of crashing.
Fixes Rust-GCC#3951
gcc/rust/ChangeLog:
* expand/rust-derive.cc (DeriveVisitor::derive): Handle
`BuiltinMacro::RustcEncodable` and `BuiltinMacro::RustcDecodable`.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3951.rs: New test.
Signed-off-by: jayant chauhan <0001jayant@gmail.com>
In full constructor, add initialization for ExternalItem base class. Use
the node id inside ExternalItem to populate member node id.
gcc/rust/ChangeLog:
* ast/rust-macro.h: add initialization for ExternalItem base
class in full construtor and use node id inside ExternalItem
to populate memeber node id.
Signed-off-by: vibhatsu <maulikbarot2915@gmail.com>
This patch implements the `reconstruct` pattern for the `Path` hierarchy and its
constituents (segments, generic args, qualified paths).
Previously, derive expansion macros (like `derive(PartialEq)`) had to manually
rebuild paths field-by-field to ensure fresh NodeIDs. This change moves that
logic into the AST classes themselves, allowing paths to be deeply reconstructed
uniformly. This ensures that expanded code has unique NodeIDs, which is critical
for correct name resolution.
gcc/rust/ChangeLog:
* ast/rust-path.h (GenericArgsBinding::reconstruct): New method.
(GenericArg::reconstruct): New method.
(GenericArgs::reconstruct): New method.
(PathExprSegment::reconstruct): New method.
(PathInExpression::reconstruct): New method.
(TypePathSegmentGeneric::reconstruct_impl): New method.
(TypePathFunction::reconstruct): New method.
(TypePathSegmentFunction::reconstruct_impl): New method.
(QualifiedPathType::reconstruct): New method.
(QualifiedPathInExpression::reconstruct): New method.
(QualifiedPathInType::reconstruct_impl): New method.
* expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): Use path.reconstruct().
(EnumMatchBuilder::strukt): Use path.reconstruct().
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
Add a no_std attribute, when both no_std and no_core attributes are
missing, inject an external std crate.
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::compile_crate): Inject std crate
when both no_std and no_core attributes are missing.
* util/rust-attribute-values.h: Add no_std attribute value.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Attribute content was checked twice within the early name resolution,
from outside the attribute and then using the default visitor. Remove
the first one visit. Also fix the wrong locus on trait resolution.
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::visit_derive_attribute):
Change from attribute locus to trait locus.
(Early::visit_attributes): Remove function.
(Early::visit): Remove functions.
* resolve/rust-early-name-resolver-2.0.h: Remove unused prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
We were emitting warning even on attribute that were then removed by
the cfgstrip pass. We cannot move the cfg strip pass before the attribute
checking because we need to first emit malformed input error messages.
This means the attribute checking pass must know if an attribute input
may be removed later down the line.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (MetaItemPathExpr::to_attribute): Remove cast to
literal.
(AttrInputMetaItemContainer::separate_cfg_attrs): Remove PathExpr
specific code.
* expand/rust-cfg-strip.cc (expand_cfg_attrs): Remove the whole
attribute if condition's result is false.
* util/rust-attributes.cc (AttributeChecker::visit): Remove specific
code section for meta item container. Do not check input if
configuration does not match condition.
gcc/testsuite/ChangeLog:
* rust/compile/attr_malformed_path.rs: Filter existing test to x86_64
exclusively, add two new tests that appear when visiting the resulting
expression.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
We will require expr within attribute input in the future in order to be
able to handle some nightly features. Even, the current macro attribute
input could be converted to an expression attribute input.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor
implementation.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-collector.h: Add function prototype.
* ast/rust-ast-visitor.h: Likewise.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Handle EXPR
variant.
(AttrInputExpr::AttrInputExpr): Add constructor.
(AttrInputExpr::operator=): Add assignment operator implementation.
(AttrInputExpr::as_string): Add a string conversion member function.
(AttrInputExpr::accept_vis): Add visitor function.
* ast/rust-ast.h: Add EXPR type variant to AttrInput.
* util/rust-attributes.cc (check_doc_attribute): Handle expr variant.
* ast/rust-expr.h (class AttrInputExpr): Add class definition with
member function prototypes.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add empty
visitor implementation.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
A crate is not a visitable and thus cannot be used with the debug
function. Until it is made visitable this commit provides a function
to dump the content of a crate.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (debug): Add debug function which calls debug
on every crate field.
* ast/rust-ast-dump.h (debug): Add function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Remove attribute specific checking, use default ast visitor instead.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (AttributeChecker::visit): Rename function
and make call to ast default visitor.
(AttributeChecker::check_attribute): Remove function.
* util/rust-attributes.h: Add function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
These changes allows interfacing with attributes as a Visitable node.
gcc/rust/ChangeLog:
* ast/rust-ast.h (class Attribute): Make visitable parent class public.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Attribute have always been a bit weird, they were part of the AST but did
not have any visitor function, this create a lot of friction around them
as their input which may be an expression, a literal and even an
expression in the future didn't get visited properly during the different
passes of the compiler.
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h (struct Attribute): Change from here...
(class Attribute): ...to a class here.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add a default
visit function for the attributes.
* ast/rust-ast-visitor.h: Add a proper visit function declaration for
attributes.
* ast/rust-ast.cc (Attribute::accept_vis): Add a function to accept a
visitor within the attributes.
* ast/rust-ast.h (struct Attribute): Add the accept_vis function
prototype.
(class Attribute): Rename from struct to class.
* expand/rust-derive.h: Add an empty implementation for visits to
prevent the visitor from recursing into the attributes.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add missing
implementation for attribute visit function. Add a check for derive
attributes that would have slipped through the passes.
* hir/rust-ast-lower-base.h: Add function prototype.
* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Split the function into two halves.
(Early::visit_derive_attribute): Specialized function from
visit_attribute for derive attributes.
(Early::visit_non_builtin_attribute): Likewise for non builtin
attributes.
(Early::visit): Rename visit_attributes to visit.
* resolve/rust-early-name-resolver-2.0.h (class Early): Update function
prototypes.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4212.rs: Update test with the new errors.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Those attributes should be considered as builtin attributes but were
missing from the list of builtin attributes.
gcc/rust/ChangeLog:
* util/rust-attributes.cc: Add "feature", "no_core", "doc",
"crate_name", "crate_type" and "may_dandle" to the list of builtin
attributes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::handle_crate_name): Use the new
constexpr instead of a raw string value.
* util/rust-attribute-values.h: Add crate_name and crate_type values.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Move the early feature gate store to it's own translation unit. This
will reduces the size of included headers within the parser.
gcc/rust/ChangeLog:
* Make-lang.in: Add new specific feature store file.
* checks/errors/feature/rust-feature-gate.cc (EarlyFeatureGateStore::get):
Move from here to rust-feature-store.cc.
(EarlyFeatureGateStore::add): Likewise.
(EarlyFeatureGateStore::get_error): Likewise.
(FeatureGate::check): Likewise.
* checks/errors/feature/rust-feature-gate.h (class EarlyFeatureGateStore):
Move class declaration to rust-feature-store.h header.
* parse/rust-parse.h: Change included header.
* checks/errors/feature/rust-feature-store.cc: New file.
* checks/errors/feature/rust-feature-store.h: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
We use multiple parsers and can't retrieve all early feature gating
errors within the usual gating pass. This commit introduces a store to
collect all early gating errors in the same place from multiple parsers.
The features are then checked as usual within the feature gate checker.
gcc/rust/ChangeLog:
* checks/errors/feature/rust-feature-gate.cc (EarlyFeatureGateStore::get):
Add function to retrieve singleton instance.
(EarlyFeatureGateStore::add): New function to add an error and the
corresponding feature in the store.
(EarlyFeatureGateStore::get_error): Add new function to retrieve the
oldest error.
(FeatureGate::check): Update the function to retrieve the errors from
the store instead of getting it from the parameters.
* checks/errors/feature/rust-feature-gate.h (class EarlyFeatureGateStore):
Add a new class to collect all early feature gating errors.
* parse/rust-parse.h: Use store instead of keeping the errors within
the parser instance.
* rust-session-manager.cc (Session::compile_crate): Remove old early
error collection from the main parser.
* rust-system.h: Include queue header.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3661.rs: Add key_value_attribute feature to
prevent error on stringify macro.
* rust/compile/early_feature_gate_in_macro.rs: Add test to highlight
early feature gate error collection within macros.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Some nightly features change the parser's behavior, it may accepts syntax
that should be rejected when the feature is missing. But the complete
list of enabled features can only be found once the parsing is complete.
We should therefore not emit any error at parse time and instead collect
a potential error and emit it later during the feature gating step.
gcc/rust/ChangeLog:
* checks/errors/feature/rust-feature-gate.cc (FeatureGate::check):
Check all parse time errors.
* checks/errors/feature/rust-feature-gate.h: Update function prototype
with parse time errors.
* parse/rust-parse-impl-attribute.hxx: Collect potential gating error
with non literal attribute values. Remove error emission.
* parse/rust-parse.h: Add a function to gather potential feature gating
errors as well as a getter for collected errors.
* rust-session-manager.cc (Session::compile_crate): Retrieve potential
feature gating errors and check them later during the feature gating
step.
* util/rust-attributes.cc (check_export_name_attribute): Change
attribute checking error emission to prevent errors with macro inputs.
gcc/testsuite/ChangeLog:
* rust/compile/doc_macro.rs: Enable feature to use a macro within an
attribute input.
* rust/compile/parse_time_feature_gate.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
rust-for-linux uses some nightly features that appeared with rust 1.50,
this patch provides a new mechanism dedicated to features required for
rfl that were not available back then.
gcc/rust/ChangeLog:
* checks/errors/feature/contrib/fetch: Bump version from 1.49.0 to
1.50.0. Change brace expansion to explicit file fetch.
* checks/errors/feature/rust-feature-defs.h: Regenerate.
* checks/errors/feature/contrib/copyright-stub.h: Add rfl include
directive.
* checks/errors/feature/rust-feature-defs-rfl.h: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Features are now collected early rather than later during the feature
gating visitor. This requires the introduction of an early cfg strip
in order to collect #![cfg(xxxx), feature(yyyy)] correctly.
gcc/rust/ChangeLog:
* Make-lang.in: Add rust-early-cfg-strip object file.
* expand/rust-cfg-strip.h (expand_cfg_attrs): Declare function prototype.
* rust-session-manager.cc (Session::compile_crate): Reorder feature
collection and add early cfg strip.
* expand/rust-early-cfg-strip.cc: New file.
* expand/rust-early-cfg-strip.h: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Feature collection should happen before expansion because some feature
gating happens with macros. This commit does no move the feature
collection before the expansion pass, it simply split the collection part
from the gating part.
gcc/rust/ChangeLog:
* Make-lang.in: Add new feature collector file.
* checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit):
Remove feature collection from gating visitor.
(FeatureGate::gate): Use features from the crate feature entity instead
of old class members.
* checks/errors/feature/rust-feature-gate.h: Get features from a
separate CrateFeatures struct instead of keeping them in the class.
* rust-session-manager.cc (Session::compile_crate): Collect features
before gating them.
* util/rust-attribute-values.h: Add feature attribute value.
* checks/errors/feature/rust-feature-collector.cc: New file.
* checks/errors/feature/rust-feature-collector.h: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Rename is_builtin to identify_builtin and change prototype to return the
builtin when found.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (is_builtin): Rename from here ...
(identify_builtin): ... to here.
(is_proc_macro_type): Handle new return value.
(AttributeChecker::check_inner_attribute): Likewise.
(AttributeChecker::check_attribute): Likewise.
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h (identify_builtin): Update function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fixes Rust-GCC#4433
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Propagate location
info from MetaWord to SimplePath.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4433.rs: Update test to expect valid line numbers.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>