aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-12-05 01:22:10 +0000
committerGitHub <noreply@github.com>2022-12-05 01:22:10 +0000
commit9666f2b169b5192b5c827d605cc80e6987e1aac5 (patch)
tree465b0f518b726001cda0e05c0a3a1344913bb022 /gcc
parente39fadcd0aa4d52d53667e2adad9a6677f7e9adf (diff)
parent31dd14e197c00891751994839b16a5a193a71820 (diff)
downloadgcc-9666f2b169b5192b5c827d605cc80e6987e1aac5.zip
gcc-9666f2b169b5192b5c827d605cc80e6987e1aac5.tar.gz
gcc-9666f2b169b5192b5c827d605cc80e6987e1aac5.tar.bz2
Merge #1632
1632: Fix mac-os regression in apply generic arguments to method calls r=philberty a=philberty When applying generic arguments to method calls such as: ```receiver.method_name<i32, bool>()``` This ended up wrongly using the default constructor with an empty generic arguments which seems like a possible bug in the new version of clang. This explicitly sets up all relevant copy constructors for HIR::PathExprSegment and removes the defaults. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h3
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-decls.h2
-rw-r--r--gcc/rust/hir/tree/rust-hir-path.h37
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.cc5
-rw-r--r--gcc/rust/typecheck/rust-tyty.h4
-rw-r--r--gcc/testsuite/rust/debug/chartype.rs15
6 files changed, 46 insertions, 20 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 66d8509..693704e 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -1872,7 +1872,8 @@ public:
std::unique_ptr<Expr> &get_receiver () { return receiver; }
- PathExprSegment get_method_name () const { return method_name; };
+ PathExprSegment &get_method_name () { return method_name; };
+ const PathExprSegment &get_method_name () const { return method_name; };
size_t num_params () const { return params.size (); }
diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h
index 717facf..761526b 100644
--- a/gcc/rust/hir/tree/rust-hir-full-decls.h
+++ b/gcc/rust/hir/tree/rust-hir-full-decls.h
@@ -43,7 +43,7 @@ class PathExpr;
// rust-path.h
class PathIdentSegment;
struct GenericArgsBinding;
-struct GenericArgs;
+class GenericArgs;
class PathExprSegment;
class PathPattern;
class PathInExpression;
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index 06f3acb..8cc16f3 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -140,8 +140,7 @@ private:
Location locus;
};
-// Generic arguments allowed in each path expression segment - inline?
-struct GenericArgs
+class GenericArgs
{
std::vector<Lifetime> lifetime_args;
std::vector<std::unique_ptr<Type> > type_args;
@@ -172,6 +171,7 @@ public:
: lifetime_args (other.lifetime_args), binding_args (other.binding_args),
const_args (other.const_args), locus (other.locus)
{
+ type_args.clear ();
type_args.reserve (other.type_args.size ());
for (const auto &e : other.type_args)
@@ -188,6 +188,7 @@ public:
const_args = other.const_args;
locus = other.locus;
+ type_args.clear ();
type_args.reserve (other.type_args.size ());
for (const auto &e : other.type_args)
type_args.push_back (e->clone_type ());
@@ -235,26 +236,44 @@ private:
Location locus;
public:
- // Returns true if there are any generic arguments
- bool has_generic_args () const { return generic_args.has_generic_args (); }
-
- // Constructor for segment (from IdentSegment and GenericArgs)
PathExprSegment (Analysis::NodeMapping mappings,
- PathIdentSegment segment_name, Location locus = Location (),
- GenericArgs generic_args = GenericArgs::create_empty ())
+ PathIdentSegment segment_name, Location locus,
+ GenericArgs generic_args)
: mappings (std::move (mappings)), segment_name (std::move (segment_name)),
generic_args (std::move (generic_args)), locus (locus)
{}
+ PathExprSegment (PathExprSegment const &other)
+ : mappings (other.mappings), segment_name (other.segment_name),
+ generic_args (other.generic_args), locus (other.locus)
+ {}
+
+ PathExprSegment &operator= (PathExprSegment const &other)
+ {
+ mappings = other.mappings;
+ segment_name = other.segment_name;
+ generic_args = other.generic_args;
+ locus = other.locus;
+
+ return *this;
+ }
+
+ // move constructors
+ PathExprSegment (PathExprSegment &&other) = default;
+ PathExprSegment &operator= (PathExprSegment &&other) = default;
+
std::string as_string () const;
Location get_locus () const { return locus; }
- PathIdentSegment get_segment () const { return segment_name; }
+ PathIdentSegment &get_segment () { return segment_name; }
+ const PathIdentSegment &get_segment () const { return segment_name; }
GenericArgs &get_generic_args () { return generic_args; }
const Analysis::NodeMapping &get_mappings () const { return mappings; }
+
+ bool has_generic_args () const { return generic_args.has_generic_args (); }
};
// HIR node representing a pattern that involves a "path" - abstract base class
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 7ea1bd9..3ee59e6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1149,10 +1149,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
// apply any remaining generic arguments
if (expr.get_method_name ().has_generic_args ())
{
- rust_debug_loc (expr.get_method_name ().get_generic_args ().get_locus (),
+ HIR::GenericArgs &args = expr.get_method_name ().get_generic_args ();
+ rust_debug_loc (args.get_locus (),
"applying generic arguments to method_call: {%s}",
lookup->debug_str ().c_str ());
- HIR::GenericArgs &args = expr.get_method_name ().get_generic_args ();
+
lookup
= SubstMapper::Resolve (lookup, expr.get_method_name ().get_locus (),
&args);
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 8b39e51..0503528 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -699,6 +699,10 @@ public:
return *this;
}
+ SubstitutionArgumentMappings (SubstitutionArgumentMappings &&other) = default;
+ SubstitutionArgumentMappings &operator= (SubstitutionArgumentMappings &&other)
+ = default;
+
static SubstitutionArgumentMappings error ()
{
return SubstitutionArgumentMappings ({}, Location (), nullptr, false);
diff --git a/gcc/testsuite/rust/debug/chartype.rs b/gcc/testsuite/rust/debug/chartype.rs
index 69e7ab0..3300925 100644
--- a/gcc/testsuite/rust/debug/chartype.rs
+++ b/gcc/testsuite/rust/debug/chartype.rs
@@ -1,10 +1,11 @@
-// 'char' should use DW_ATE_UTF
-fn main () {
- let c = 'x';
// { dg-do compile }
-// Use -w to avoid warnings about the unused variables
-// DW_ATE_UTF entered in DWARF 4.
+// { dg-skip-if "see https://github.com/Rust-GCC/gccrs/pull/1632" { *-*-darwin* } }
// { dg-options "-w -gdwarf-4 -dA" }
-// DW_ATE_UTF = 0x10
-// { dg-final { scan-assembler "0x10\[ \t]\[^\n\r]* DW_AT_encoding" } } */
+// 'char' should use DW_ATE_UTF
+fn main() {
+ let c = 'x';
+ // Use -w to avoid warnings about the unused variables
+ // DW_ATE_UTF entered in DWARF 4.
+ // DW_ATE_UTF = 0x10
+ // { dg-final { scan-assembler "0x10\[ \t]\[^\n\r]* DW_AT_encoding" } } */
}