Skip to content

Commit 9666f2b

Browse files
bors[bot]philberty
andauthored
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 <[email protected]>
2 parents e39fadc + 31dd14e commit 9666f2b

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

gcc/rust/hir/tree/rust-hir-expr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,8 @@ class MethodCallExpr : public ExprWithoutBlock
18721872

18731873
std::unique_ptr<Expr> &get_receiver () { return receiver; }
18741874

1875-
PathExprSegment get_method_name () const { return method_name; };
1875+
PathExprSegment &get_method_name () { return method_name; };
1876+
const PathExprSegment &get_method_name () const { return method_name; };
18761877

18771878
size_t num_params () const { return params.size (); }
18781879

gcc/rust/hir/tree/rust-hir-full-decls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PathExpr;
4343
// rust-path.h
4444
class PathIdentSegment;
4545
struct GenericArgsBinding;
46-
struct GenericArgs;
46+
class GenericArgs;
4747
class PathExprSegment;
4848
class PathPattern;
4949
class PathInExpression;

gcc/rust/hir/tree/rust-hir-path.h

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ class ConstGenericArg
140140
Location locus;
141141
};
142142

143-
// Generic arguments allowed in each path expression segment - inline?
144-
struct GenericArgs
143+
class GenericArgs
145144
{
146145
std::vector<Lifetime> lifetime_args;
147146
std::vector<std::unique_ptr<Type> > type_args;
@@ -172,6 +171,7 @@ struct GenericArgs
172171
: lifetime_args (other.lifetime_args), binding_args (other.binding_args),
173172
const_args (other.const_args), locus (other.locus)
174173
{
174+
type_args.clear ();
175175
type_args.reserve (other.type_args.size ());
176176

177177
for (const auto &e : other.type_args)
@@ -188,6 +188,7 @@ struct GenericArgs
188188
const_args = other.const_args;
189189
locus = other.locus;
190190

191+
type_args.clear ();
191192
type_args.reserve (other.type_args.size ());
192193
for (const auto &e : other.type_args)
193194
type_args.push_back (e->clone_type ());
@@ -235,26 +236,44 @@ class PathExprSegment
235236
Location locus;
236237

237238
public:
238-
// Returns true if there are any generic arguments
239-
bool has_generic_args () const { return generic_args.has_generic_args (); }
240-
241-
// Constructor for segment (from IdentSegment and GenericArgs)
242239
PathExprSegment (Analysis::NodeMapping mappings,
243-
PathIdentSegment segment_name, Location locus = Location (),
244-
GenericArgs generic_args = GenericArgs::create_empty ())
240+
PathIdentSegment segment_name, Location locus,
241+
GenericArgs generic_args)
245242
: mappings (std::move (mappings)), segment_name (std::move (segment_name)),
246243
generic_args (std::move (generic_args)), locus (locus)
247244
{}
248245

246+
PathExprSegment (PathExprSegment const &other)
247+
: mappings (other.mappings), segment_name (other.segment_name),
248+
generic_args (other.generic_args), locus (other.locus)
249+
{}
250+
251+
PathExprSegment &operator= (PathExprSegment const &other)
252+
{
253+
mappings = other.mappings;
254+
segment_name = other.segment_name;
255+
generic_args = other.generic_args;
256+
locus = other.locus;
257+
258+
return *this;
259+
}
260+
261+
// move constructors
262+
PathExprSegment (PathExprSegment &&other) = default;
263+
PathExprSegment &operator= (PathExprSegment &&other) = default;
264+
249265
std::string as_string () const;
250266

251267
Location get_locus () const { return locus; }
252268

253-
PathIdentSegment get_segment () const { return segment_name; }
269+
PathIdentSegment &get_segment () { return segment_name; }
270+
const PathIdentSegment &get_segment () const { return segment_name; }
254271

255272
GenericArgs &get_generic_args () { return generic_args; }
256273

257274
const Analysis::NodeMapping &get_mappings () const { return mappings; }
275+
276+
bool has_generic_args () const { return generic_args.has_generic_args (); }
258277
};
259278

260279
// HIR node representing a pattern that involves a "path" - abstract base class

gcc/rust/typecheck/rust-hir-type-check-expr.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,10 +1149,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
11491149
// apply any remaining generic arguments
11501150
if (expr.get_method_name ().has_generic_args ())
11511151
{
1152-
rust_debug_loc (expr.get_method_name ().get_generic_args ().get_locus (),
1152+
HIR::GenericArgs &args = expr.get_method_name ().get_generic_args ();
1153+
rust_debug_loc (args.get_locus (),
11531154
"applying generic arguments to method_call: {%s}",
11541155
lookup->debug_str ().c_str ());
1155-
HIR::GenericArgs &args = expr.get_method_name ().get_generic_args ();
1156+
11561157
lookup
11571158
= SubstMapper::Resolve (lookup, expr.get_method_name ().get_locus (),
11581159
&args);

gcc/rust/typecheck/rust-tyty.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ class SubstitutionArgumentMappings
699699
return *this;
700700
}
701701

702+
SubstitutionArgumentMappings (SubstitutionArgumentMappings &&other) = default;
703+
SubstitutionArgumentMappings &operator= (SubstitutionArgumentMappings &&other)
704+
= default;
705+
702706
static SubstitutionArgumentMappings error ()
703707
{
704708
return SubstitutionArgumentMappings ({}, Location (), nullptr, false);
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// 'char' should use DW_ATE_UTF
2-
fn main () {
3-
let c = 'x';
41
// { dg-do compile }
5-
// Use -w to avoid warnings about the unused variables
6-
// DW_ATE_UTF entered in DWARF 4.
2+
// { dg-skip-if "see https://github.com/Rust-GCC/gccrs/pull/1632" { *-*-darwin* } }
73
// { dg-options "-w -gdwarf-4 -dA" }
8-
// DW_ATE_UTF = 0x10
9-
// { dg-final { scan-assembler "0x10\[ \t]\[^\n\r]* DW_AT_encoding" } } */
4+
// 'char' should use DW_ATE_UTF
5+
fn main() {
6+
let c = 'x';
7+
// Use -w to avoid warnings about the unused variables
8+
// DW_ATE_UTF entered in DWARF 4.
9+
// DW_ATE_UTF = 0x10
10+
// { dg-final { scan-assembler "0x10\[ \t]\[^\n\r]* DW_AT_encoding" } } */
1011
}

0 commit comments

Comments
 (0)