Skip to content

Commit

Permalink
fix #20621 Comparing addresses of rvalue reference parameters not cor…
Browse files Browse the repository at this point in the history
…rect
  • Loading branch information
WalterBright committed Dec 31, 2024
1 parent da1b69a commit ab75331
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
15 changes: 14 additions & 1 deletion compiler/src/dmd/backend/inliner.d
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,20 @@ private elem* initializeParamsWithArgs(elem* eargs, SYMIDX sistart, SYMIDX siend
{
if (log) printf("detected slice with %s\n", s.Sident.ptr);
auto s2 = nextSymbol(si);
if (!s2) { symbol_print(*s); elem_print(e); assert(0); }
if (!s2)

Check warning on line 519 in compiler/src/dmd/backend/inliner.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/inliner.d#L519

Added line #L519 was not covered by tests
{
for (size_t m = args.length; m; --m)

Check warning on line 521 in compiler/src/dmd/backend/inliner.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/inliner.d#L521

Added line #L521 was not covered by tests
{
elem* ex = args[m - 1];
printf("arg[%d]\n", cast(int) m);
elem_print(ex);

Check warning on line 525 in compiler/src/dmd/backend/inliner.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/inliner.d#L523-L525

Added lines #L523 - L525 were not covered by tests
}

printf("function: %s\n", funcsym_p.Sident.ptr);
printf("szs: %d sze: %d\n", cast(int)szs, cast(int)sze);
printf("detected slice with %s\n", s.Sident.ptr);
symbol_print(*s); elem_print(e); assert(0);

Check warning on line 531 in compiler/src/dmd/backend/inliner.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/inliner.d#L528-L531

Added lines #L528 - L531 were not covered by tests
}
assert(szs == type_size(s2.Stype));
const ty = s.Stype.Tty;

Expand Down
13 changes: 12 additions & 1 deletion compiler/src/dmd/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ UnionExp Equal(EXP op, const ref Loc loc, Type type, Expression e1, Expression e

UnionExp Identity(EXP op, const ref Loc loc, Type type, Expression e1, Expression e2)
{
//printf("Identity %s %s\n", e1.toChars(), e2.toChars());
UnionExp ue = void;
int cmp;
if (e1.op == EXP.null_)
Expand All @@ -820,7 +821,17 @@ UnionExp Identity(EXP op, const ref Loc loc, Type type, Expression e1, Expressio
{
SymOffExp es1 = e1.isSymOffExp();
SymOffExp es2 = e2.isSymOffExp();
cmp = (es1.var == es2.var && es1.offset == es2.offset);
cmp = es1.offset == es2.offset;
if (cmp)
{
cmp = es1.var == es2.var;
if (!cmp && (es1.var.isParameter() || es2.var.isParameter()))
{
// because of ref's, they may still be the same, we cannot tell
cantExp(ue);
return ue;
}
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/e2ir.d
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool ISX64REF(Declaration var)

if (var.isParameter())
{
if (target.os == Target.OS.Windows && target.isX86_64)
if (target.os == Target.OS.Windows /*&& target.isX86_64*/)
{
/* Use Microsoft C++ ABI
* https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#parameter-passing
Expand All @@ -126,7 +126,7 @@ bool ISX64REF(Declaration var)
*/
bool ISX64REF(ref IRState irs, Expression exp)
{
if (irs.target.os == Target.OS.Windows && irs.target.isX86_64)
if (irs.target.os == Target.OS.Windows /*&& irs.target.isX86_64*/)
{
return exp.type.size(Loc.initial) > registerSize
|| (exp.type.isTypeStruct() && exp.type.isTypeStruct().sym.hasCopyConstruction());
Expand Down
2 changes: 2 additions & 0 deletions compiler/test/runnable/rvalue1.d
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct S4
{
void* p;

this(ref S4) { }

this(S4 s)
{
assert(&s is &x); // confirm the rvalue reference
Expand Down

0 comments on commit ab75331

Please sign in to comment.