Philip Herron [Tue, 31 Jan 2023 14:27:49 +0000 (14:27 +0000)]
gccrs: Fix nullptr dereference
When we check if this is concrete the guard checks to ensure the argument
is non null but the check here is wrongly returning early when the check
is non null meaning when it is null and therefore not concrete it will
end up doing a null dereference.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
Philip Herron [Mon, 30 Jan 2023 18:19:07 +0000 (18:19 +0000)]
gccrs: Refactor the type unification code
This refactors the unification systems to be a consistent interface using
switch statements and simple functions instead of the old clunky visitor
system. This is more maintainable as it is harder to miss cases when we
can take advantages of switch statements.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
Philip Herron [Fri, 27 Jan 2023 15:38:58 +0000 (15:38 +0000)]
gccrs: Remove monomorphization hack to setup possible associated types
During CallExpr argument type checking we may be calling a default
implementation of a trait function this will require any possible
associated types to be resolved and setup. This monomoprhization call does
this but it will premtivly do extra unification of types which will throw
off type checking later on. This fix is required for my work into type
bounds checking.
Fixes #1773
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
Philip Herron [Fri, 27 Jan 2023 18:31:11 +0000 (18:31 +0000)]
gccrs: Clear the substitution callbacks when copying ArgumentMappings
When we set the callback on substitutions this is not safe to be copied
around since we store the used argument mappings and can reuse them in
different contexts. This clears the callback on copy's to make it safer.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
Philip Herron [Fri, 27 Jan 2023 18:28:06 +0000 (18:28 +0000)]
gccrs: Refactor handle_substitutions to take a reference
This patch changes the recusive substitution code to take a reference
instead of a copy. This is important as the callback field is going to be
made non-copyable in a future patch and this pipeline is for recursive
substitutions so its ok to reuse the same mappings here.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
bors[bot] [Fri, 3 Feb 2023 13:28:26 +0000 (13:28 +0000)]
Merge #1698
1698: update the ubuntu version r=CohenArthur a=ArshErgon
Fixes: #1689
updated the ubuntu-version from 20.04 to 22.04
Thank you for making Rust GCC better!
If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.
Here is a checklist to help you with your PR.
- \[ ] GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off, see https://gcc.gnu.org/contribute.html or https://gcc.gnu.org/dco.html
- \[ ] Read contributing guidlines
- \[ ] `make check-rust` passes locally
- \[ ] Run `clang-format`
- \[ ] Added any relevant test cases to `gcc/testsuite/rust/`
Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.
---
*Please write a comment explaining your change. This is the message
that will be part of the merge commit.
The parser now recursively tries to parse a reference type after seeing a `&` or `&&` token.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_type): Handle double ampersan properly (Parser::parse_reference_type): Call into `parse_reference_type_inner` and wrap double reference types in another `AST::ReferenceType` node (Parser::parse_reference_type_inner): Add parsing implementation which does not care about the leading token (& or &&) (Parser::parse_type_no_bounds): Handle double ampersand properly
* parse/rust-parse.h: Declare `parse_reference_type_inner`
gcc/testsuite/ChangeLog:
* rust/compile/multi_reference_type.rs: New test.
Addresses #1807 partly
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Last we did #1700 "Merge upstream, last commit before GCC/Rust upstreaming",
which merged commit b4fddbe9592e9feb37ce567d90af822b75995531 from GCC upstream
master branch.
- dd950cbbb97 Use DW_ATE_UTF for the Rust 'char' type
- b772a504eff gccrs: Add necessary hooks for a Rust front-end testsuite
- 4b8f3005af0 gccrs: Add Debug info testsuite
- f60df7e6202 gccrs: Add link cases testsuite
- 97705b4459b gccrs: Add general compilation test cases
- 5a56869d6e3 gccrs: Add execution test cases
- dc4171edb3c gccrs: Add gcc-check-target check-rust
- 6b35ae12ce9 gccrs: Add Rust front-end base AST data structures
- 438ae944fa6 gccrs: Add definitions of Rust Items in AST data structures
- d588754c826 gccrs: Add full definitions of Rust AST data structures
- 5b981e9c741 gccrs: Add Rust AST visitors
- 18f6990f842 gccrs: Add Lexer for Rust front-end
- 35e4f3b4af4 gccrs: Add Parser for Rust front-end pt.1
- 32c8fb0eeaf gccrs: Add Parser for Rust front-end pt.2
- 1841081a8a3 gccrs: Add expansion pass for the Rust front-end
- 85a8fe00f80 gccrs: Add name resolution pass to the Rust front-end
- 8ad1d56d68a gccrs: Add declarations for Rust HIR
- 7641eaead40 gccrs: Add HIR definitions and visitor framework
- 7999cf327de gccrs: Add AST to HIR lowering pass
- b32b1b1576a gccrs: Add wrapper for make_unique
- c7f8347e83c gccrs: Add port of FNV hash used during legacy symbol mangling
- 15b0278905e gccrs: Add Rust ABI enum helpers
- eb10bc5225e gccrs: Add Base62 implementation
- 9a4fee5f57c gccrs: Add implementation of Optional
- 2e7fc8780e0 gccrs: Add attributes checker
- 9ce37e72062 gccrs: Add helpers mappings canonical path and lang items
- c6c3db21769 gccrs: Add type resolution and trait solving pass
- 24393cb68fa gccrs: Add Rust type information
- 06688fe40a2 gccrs: Add remaining type system transformations
- b1b35204d8a gccrs: Add unsafe checks for Rust
- 5215235f016 gccrs: Add const checker
- ca246e573fb gccrs: Add privacy checks
- 520b52b24e7 gccrs: Add dead code scan on HIR
- 4d67468d1d4 gccrs: Add unused variable scan
- 509e4c32c6a gccrs: Add metadata output pass
- 15f04af347e gccrs: Add base for HIR to GCC GENERIC lowering
- 019b2f15581 gccrs: Add HIR to GCC GENERIC lowering for all nodes
- cfbda2f78ba gccrs: Add HIR to GCC GENERIC lowering entry point
- fe6264fa28a gccrs: These are wrappers ported from reusing gccgo
- bba14a0790f gccrs: Add compiler driver
- ea34614225d gccrs: Compiler proper interface kicks off the pipeline
- ab1e0db43c2 gccrs: Add lang-spec.h
- 5e7d199739f gccrs: Add lang.opt
- 88415d33bb3 gccrs: Add GCC Rust front-end Make-lang.in
- b07ef39ffbf gccrs: Add fatal_error when experimental flag is not present
- a75f038c069 gccrs: Add config-lang.in
- edc676cfe89 gccrs: Add README, CONTRIBUTING and compiler logo
This merge is done with `git merge --strategy=ours`, so that we effectively
don't bring any changes. Rationale: any changes due to upstream review etc.,
have already been applied individually to GCC/Rust master branch, and any
remaining changes we'd either like to persist, or assess individually, later.
Co-authored-by: Tom Tromey <tom@tromey.com> Co-authored-by: Philip Herron <philip.herron@embecosm.com> Co-authored-by: Joel Phillips <simplytheother@gmail.com> Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Arthur Cohen [Wed, 1 Feb 2023 10:40:13 +0000 (11:40 +0100)]
parser: Allow parsing multiple reference types
The parser now recursively tries to parse a reference type after seeing
a `&` or `&&` token.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_type): Handle double ampersan
properly
(Parser::parse_reference_type): Call into `parse_reference_type_inner`
and wrap double reference types in another `AST::ReferenceType` node
(Parser::parse_reference_type_inner): Add parsing implementation
which does not care about the leading token (& or &&)
(Parser::parse_type_no_bounds): Handle double ampersand properly
* parse/rust-parse.h: Declare `parse_reference_type_inner`
Last we did #1700 "Merge upstream, last commit before GCC/Rust upstreaming",
which merged commit b4fddbe9592e9feb37ce567d90af822b75995531 from GCC upstream
master branch.
- dd950cbbb97 Use DW_ATE_UTF for the Rust 'char' type
- b772a504eff gccrs: Add necessary hooks for a Rust front-end testsuite
- 4b8f3005af0 gccrs: Add Debug info testsuite
- f60df7e6202 gccrs: Add link cases testsuite
- 97705b4459b gccrs: Add general compilation test cases
- 5a56869d6e3 gccrs: Add execution test cases
- dc4171edb3c gccrs: Add gcc-check-target check-rust
- 6b35ae12ce9 gccrs: Add Rust front-end base AST data structures
- 438ae944fa6 gccrs: Add definitions of Rust Items in AST data structures
- d588754c826 gccrs: Add full definitions of Rust AST data structures
- 5b981e9c741 gccrs: Add Rust AST visitors
- 18f6990f842 gccrs: Add Lexer for Rust front-end
- 35e4f3b4af4 gccrs: Add Parser for Rust front-end pt.1
- 32c8fb0eeaf gccrs: Add Parser for Rust front-end pt.2
- 1841081a8a3 gccrs: Add expansion pass for the Rust front-end
- 85a8fe00f80 gccrs: Add name resolution pass to the Rust front-end
- 8ad1d56d68a gccrs: Add declarations for Rust HIR
- 7641eaead40 gccrs: Add HIR definitions and visitor framework
- 7999cf327de gccrs: Add AST to HIR lowering pass
- b32b1b1576a gccrs: Add wrapper for make_unique
- c7f8347e83c gccrs: Add port of FNV hash used during legacy symbol mangling
- 15b0278905e gccrs: Add Rust ABI enum helpers
- eb10bc5225e gccrs: Add Base62 implementation
- 9a4fee5f57c gccrs: Add implementation of Optional
- 2e7fc8780e0 gccrs: Add attributes checker
- 9ce37e72062 gccrs: Add helpers mappings canonical path and lang items
- c6c3db21769 gccrs: Add type resolution and trait solving pass
- 24393cb68fa gccrs: Add Rust type information
- 06688fe40a2 gccrs: Add remaining type system transformations
- b1b35204d8a gccrs: Add unsafe checks for Rust
- 5215235f016 gccrs: Add const checker
- ca246e573fb gccrs: Add privacy checks
- 520b52b24e7 gccrs: Add dead code scan on HIR
- 4d67468d1d4 gccrs: Add unused variable scan
- 509e4c32c6a gccrs: Add metadata output pass
- 15f04af347e gccrs: Add base for HIR to GCC GENERIC lowering
- 019b2f15581 gccrs: Add HIR to GCC GENERIC lowering for all nodes
- cfbda2f78ba gccrs: Add HIR to GCC GENERIC lowering entry point
- fe6264fa28a gccrs: These are wrappers ported from reusing gccgo
- bba14a0790f gccrs: Add compiler driver
- ea34614225d gccrs: Compiler proper interface kicks off the pipeline
- ab1e0db43c2 gccrs: Add lang-spec.h
- 5e7d199739f gccrs: Add lang.opt
- 88415d33bb3 gccrs: Add GCC Rust front-end Make-lang.in
- b07ef39ffbf gccrs: Add fatal_error when experimental flag is not present
- a75f038c069 gccrs: Add config-lang.in
- edc676cfe89 gccrs: Add README, CONTRIBUTING and compiler logo
This merge is done with `git merge --strategy=ours`, so that we effectively
don't bring any changes. Rationale: any changes due to upstream review etc.,
have already been applied individually to GCC/Rust master branch, and any
remaining changes we'd either like to persist, or assess individually, later.
bors[bot] [Tue, 31 Jan 2023 21:46:24 +0000 (21:46 +0000)]
Merge #1788
1788: ci: Add commit format checker r=CohenArthur a=CohenArthur
Bring over the commit checker from `gcc-patch-dev` with the `gccrs` prefix checker enabled only for `gcc-patch-dev` PRs. I'll open up an issue to make sure that in the future it's easier to keep that folder in sync between the two branches
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
bors[bot] [Mon, 30 Jan 2023 13:27:16 +0000 (13:27 +0000)]
Merge #1776
1776: fixed compiler error message on wildcard pattern within expression r=CohenArthur a=00AR
Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
fixed compiler error message on wildcard pattern '_' within expression.
Added a new testcase for the same.
#867
Co-authored-by: Abdul Rafey <abdulrafeyq@gmail.com>
bors[bot] [Mon, 30 Jan 2023 12:44:25 +0000 (12:44 +0000)]
Merge #1735
1735: macro: Allow builtin `MacroInvocation`s within the AST r=CohenArthur a=CohenArthur
gcc/rust/ChangeLog:
* ast/rust-macro.h (enum class): Add `BuiltinMacro` enum class
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Mention switching on `macro.kind` once builtin macro invocations are properly handled
* parse/rust-parse-impl.h (Parser::parse_macro_invocation): Switch to new MacroInvocation API
(Parser::parse_type): Switch to new MacroInvocation API
(Parser::parse_type_no_bounds): Switch to new MacroInvocation API
This will be necessary for proper handling of builtin macros with the new `EarlyNameResolver` class and associated fixed-point algorithm
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
bors[bot] [Tue, 24 Jan 2023 16:39:54 +0000 (16:39 +0000)]
Merge #1763
1763: Do not crash on empty macros expand. Fixes #1712 r=philberty a=teromene
This PR fixes a compiler crash when expanding an empty macro into an existing AST.
(I ran clang-format but it marked a few other files as dirty, and I therefore did not touch them)
bors[bot] [Thu, 12 Jan 2023 13:54:04 +0000 (13:54 +0000)]
Merge #1733
1733: diagnostics: Add underline for tokens in diagnostics. r=CohenArthur a=TuringKi
Currently, the diagnostics only point to the corresponding token's start position by carets, and lack of underlines for full token. This commit add support for such underlines in diagnostics by encoding range information in location_t.
the results like this:
```
../gcc/testsuite/rust/compile/bad_as_bool_char.rs:5:14: error: invalid cast 'bool' to 'f32' [E0054]
5 | let fone = t as f32; // { dg-error "invalid cast" }
| ^ ~~~
../gcc/testsuite/rust/compile/bad_as_bool_char.rs:6:15: error: invalid cast 'bool' to 'f64' [E0054]
6 | let fzero = f as f64; // { dg-error "invalid cast" }
| ^ ~~~
../gcc/testsuite/rust/compile/bad_as_bool_char.rs:8:12: error: invalid cast 'u8' to 'bool' [E0054]
8 | let nb = 0u8 as bool; // { dg-error "invalid cast .u8. to .bool. \\\[E0054\\\]" }
| ^~~ ~~~~
../gcc/testsuite/rust/compile/bad_as_bool_char.rs:9:12: error: invalid cast 'bool' to 'char' [E0054]
9 | let nc = true as char; // { dg-error "invalid cast" }
| ^~~~ ~~~~
../gcc/testsuite/rust/compile/bad_as_bool_char.rs:13:12: error: invalid cast 'char' to 'f32' [E0054]
13 | let fa = a as f32; // { dg-error "invalid cast" }
| ^ ~~~
../gcc/testsuite/rust/compile/bad_as_bool_char.rs:14:12: error: invalid cast 'char' to 'bool' [E0054]
14 | let bb = b as bool; // { dg-error "invalid cast .char. to .bool. \\\[E0054\\\]" }
| ^ ~~~~
../gcc/testsuite/rust/compile/bad_as_bool_char.rs:17:12: error: invalid cast 'u32' to 'char' [E0054]
17 | let ab = t32 as char; // { dg-error "invalid cast" }
| ^~~ ~~~~
```
This commit is split from pr #1718.
Signed-off-by: Xiao Ma <mxlol233@outlook.com> Co-authored-by: mxlol233 <mxlol233@outlook.com>
mxlol233 [Wed, 11 Jan 2023 12:36:13 +0000 (20:36 +0800)]
diagnostics: Add underline for tokens in diagnostics.
Currently, the diagnostics only point to the corresponding token's start position by carets, and lack of underlines for full token. This commit add support for such underlines in diagnostics by encoding range information in location_t.
bors[bot] [Wed, 11 Jan 2023 16:45:18 +0000 (16:45 +0000)]
Merge #1734
1734: Add get_locus function for abstract class MetaItemInner. r=CohenArthur a=TuringKi
This commit adds virtual function get_locus to base class MetaItemInner, which is helpful when we need to print diagnostics on some sub-classes of MetaItemInner.
This commit is split from pr https://github.com/Rust-GCC/gccrs/pull/1718.
Signed-off-by: Xiao Ma <mxlol233@outlook.com> Co-authored-by: mxlol233 <mxlol233@outlook.com>
mxlol233 [Wed, 11 Jan 2023 15:24:07 +0000 (23:24 +0800)]
Add get_locus function for abstract class MetaItemInner.
This commit adds virtual function get_locus to base class MetaItemInner, which is helpful when we need to print diagnostics on some sub-classes of MetaItemInner.
bors[bot] [Tue, 10 Jan 2023 22:39:41 +0000 (22:39 +0000)]
Merge #1724
1724: Add support for generics associated type binding r=philberty a=philberty
This patch set adds support to specify the associated type via the argument
binding syntax. We are still missing general bounds checking so in order to
properly add more test cases for bad types we need to implement that first.
I have also changed a test case to -fsyntax-only as at the time I always get
confused between Generic arguments of foo=i32 and bar: baz only specifies
the associated type and the latter adds a bound. Currently we are lacking a
way to represent adding a bound in the AST and HIR within generic arguments
so I have raised: #1725 and #1726
Fixes #1720
Co-authored-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Sat, 7 Jan 2023 14:41:12 +0000 (14:41 +0000)]
Support associated type bound arguments
This patch adds support for the GenercArgsBinding type, where you can
specify the associated types of a trait bound using `<Foo=i32>` style
syntax. Note that the type-resolution relys on the i32 impl for Add
as type resolution will resolve the `a+a` to the core::ops::Add method
so code generation will require this to exist.
I have ameded testsuite/rust/compile/bounds.rs as this code is wrongly
creating an HIR::GenericArgs with a trait-object type and causing issues.
the parsing is still correct but we dont have the mechanism to represent
this in AST and HIR properly. I think we will need a new HIR::GenericArgs
AssociatedTypeBindingBound or something similar. We are still lacking
bounds checking during are type coercions and unifications so running this
example using an f32 will wrongly pass type checking, this will need
addressed next.
Fixes #1720
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
Philip Herron [Sat, 7 Jan 2023 17:15:23 +0000 (17:15 +0000)]
Add name resolution to generic argument associated item bindings
When specifying generic arguments to Traits we can also specify the
associated types using `<BindingName=i32>` syntax we need to add
name resolution to the type argument here and rely on the type
resolution pass to ensure the associated type exists and to setup the
associated types accordingly.
Addresses #1720
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
bors[bot] [Thu, 5 Jan 2023 15:17:27 +0000 (15:17 +0000)]
Merge #1711
1711: unsafe: check use of `target_feature` attribute r=CohenArthur a=snprajwal
The `target_feature` attribute is for conditional compilation and may or may not compile on all platforms. Using it requires an unsafe function or block.
Addresses #1411
Co-authored-by: Prajwal S N <prajwalnadig21@gmail.com>
Prajwal S N [Sat, 31 Dec 2022 07:19:02 +0000 (12:49 +0530)]
unsafe: check use of `target_feature` attribute
The `target_feature` attribute is for conditional compilation and may or
may not compile on all platforms. Using it requires an unsafe function
or block.
Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
bors[bot] [Wed, 14 Dec 2022 14:46:30 +0000 (14:46 +0000)]
Merge #1703
1703: Backport "c++: Quash -Wdangling-reference for member operator* [PR107488]" r=tschwinge a=tschwinge
As had also been reported in <https://gcc.gnu.org/PR107633> "Bootstrap failure due to -Werror=unused-parameter and -Werror=dangling-reference", GCC `--enable-bootstrap` build is currently broken:
[...]/gcc/rust/backend/rust-compile-expr.cc: In member function ‘tree_node* Rust::Compile::CompileExpr::resolve_method_address(Rust::TyTy::FnType*, Rust::HirId, Rust::TyTy::BaseType*, Rust::HIR::PathIdentSegment&, Rust::Analysis::NodeMapping, Location)’:
[...]/gcc/rust/backend/rust-compile-expr.cc:2019:13: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
2019 | auto &candidate = *candidates.begin ();
| ^~~~~~~~~
[...]/gcc/rust/backend/rust-compile-expr.cc:2019:44: note: the temporary was destroyed at the end of the full expression ‘candidates.std::set<Rust::Resolver::PathProbeCandidate>::begin().std::_Rb_tree_const_iterator<Rust::Resolver::PathProbeCandidate>::operator*()’
2019 | auto &candidate = *candidates.begin ();
| ^
[...]/gcc/rust/backend/rust-compile-expr.cc: In member function ‘tree_node* Rust::Compile::CompileExpr::generate_closure_fntype(Rust::HIR::ClosureExpr&, const Rust::TyTy::ClosureType&, tree, Rust::TyTy::FnType**)’:
[...]/gcc/rust/backend/rust-compile-expr.cc:3034:35: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
3034 | const TyTy::TypeBoundPredicate &predicate
| ^~~~~~~~~
[...]/gcc/rust/backend/rust-compile-expr.cc:3035:52: note: the temporary was destroyed at the end of the full expression ‘(&(& closure_tyty)->Rust::TyTy::ClosureType::<anonymous>.Rust::TyTy::BaseType::<anonymous>.Rust::TyTy::TypeBoundsMappings::get_specified_bounds())->std::vector<Rust::TyTy::TypeBoundPredicate>::begin().__gnu_cxx::__normal_iterator<const Rust::TyTy::TypeBoundPredicate*, std::vector<Rust::TyTy::TypeBoundPredicate> >::operator*()’
3035 | = *closure_tyty.get_specified_bounds ().begin ();
| ^
[...]/gcc/rust/typecheck/rust-hir-type-check-path.cc: In member function ‘void Rust::Resolver::TypeCheckExpr::resolve_segments(Rust::NodeId, std::vector<Rust::HIR::PathExprSegment>&, size_t, Rust::TyTy::BaseType*, const Rust::Analysis::NodeMapping&, Location)’:
[...]/gcc/rust/typecheck/rust-hir-type-check-path.cc:340:13: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
340 | auto &candidate = *candidates.begin ();
| ^~~~~~~~~
[...]/gcc/rust/typecheck/rust-hir-type-check-path.cc:340:44: note: the temporary was destroyed at the end of the full expression ‘candidates.std::set<Rust::Resolver::PathProbeCandidate>::begin().std::_Rb_tree_const_iterator<Rust::Resolver::PathProbeCandidate>::operator*()’
340 | auto &candidate = *candidates.begin ();
| ^
[...]/gcc/rust/typecheck/rust-hir-type-check-type.cc: In member function ‘Rust::TyTy::BaseType* Rust::Resolver::TypeCheckType::resolve_segments(Rust::NodeId, Rust::HirId, std::vector<std::unique_ptr<Rust::HIR::TypePathSegment> >&, size_t, Rust::TyTy::BaseType*, const Rust::Analysis::NodeMapping&, Location)’:
[...]/gcc/rust/typecheck/rust-hir-type-check-type.cc:465:13: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
465 | auto &candidate = *candidates.begin ();
| ^~~~~~~~~
[...]/gcc/rust/typecheck/rust-hir-type-check-type.cc:465:44: note: the temporary was destroyed at the end of the full expression ‘candidates.std::set<Rust::Resolver::PathProbeCandidate>::begin().std::_Rb_tree_const_iterator<Rust::Resolver::PathProbeCandidate>::operator*()’
465 | auto &candidate = *candidates.begin ();
| ^
I understand this code has been changed in the GCC/Rust upstream submission; but in order to make progress with #1700, I'd like to first individually backport "c++: Quash -Wdangling-reference for member operator* [PR107488]", to resolve this issue here.
Co-authored-by: Marek Polacek <polacek@redhat.com>
Marek Polacek [Tue, 1 Nov 2022 21:05:52 +0000 (17:05 -0400)]
c++: Quash -Wdangling-reference for member operator* [PR107488]
-Wdangling-reference complains here:
std::vector<int> v = ...;
std::vector<int>::const_iterator it = v.begin();
while (it != v.end()) {
const int &r = *it++; // warning
}
because it sees a call to
__gnu_cxx::__normal_iterator<const int*, std::vector<int> >::operator*
which returns a reference and its argument is a TARGET_EXPR representing
the result of
__gnu_cxx::__normal_iterator<const int*, std::vector<int> >::operator++
But 'r' above refers to one of the int elements of the vector 'v', not
to a temporary object. Therefore the warning is a false positive.
I suppose code like the above is relatively common (the warning broke
cppunit-1.15.1 and a few other projects), so presumably it makes sense
to suppress the warning when it comes to member operator*. In this case
it's defined as
and I'm guessing a lot of member operator* are like that, at least when
it comes to iterators. I've looked at _Fwd_list_iterator,
_Fwd_list_const_iterator, __shared_ptr_access, _Deque_iterator,
istream_iterator, etc, and they're all like that, so adding #pragmas
would be quite tedious. :/
PR c++/107488
gcc/cp/ChangeLog:
* call.cc (do_warn_dangling_reference): Quash -Wdangling-reference
for member operator*.
Thomas Schwinge [Wed, 14 Dec 2022 08:45:58 +0000 (09:45 +0100)]
Revert "ci: Apply warnings in CI"
As discussed in
<https://inbox.sourceware.org/gcc-patches/871qpjtmd8.fsf@euler.schwinge.homeip.net>:
> '-Werror=overloaded-virtual' is implied as by default, we have
> '-Woverloaded-virtual' and '-Werror' [for '--enable-bootstrap' builds].
> ([...])
> (Maybe that isn't active for '--disable-bootstrap' builds, but that's
> "OK".)
For '--disable-bootstrap' builds, we still have '-Woverloaded-virtual', and any
new such diagnostics will be caught by the #1026 "check for new warnings"
machinery, so effectively that does implement '-Werror', too.
> '-Wno-unused-parameter' [did] move into
> 'rust-warn'