From 2288e15ec669ed852296a8ab2cbda3043866b009 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Sun, 29 Dec 2024 23:52:39 -0800 Subject: [PATCH] fix #20621 Comparing addresses of rvalue reference parameters not correct --- compiler/src/dmd/constfold.d | 13 ++++++++++++- compiler/src/dmd/e2ir.d | 2 +- compiler/test/runnable/rvalue1.d | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/compiler/src/dmd/constfold.d b/compiler/src/dmd/constfold.d index 1578ef770a09..9d5aa96416b5 100644 --- a/compiler/src/dmd/constfold.d +++ b/compiler/src/dmd/constfold.d @@ -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_) @@ -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 { diff --git a/compiler/src/dmd/e2ir.d b/compiler/src/dmd/e2ir.d index e120df28d3a7..c48b7265f545 100644 --- a/compiler/src/dmd/e2ir.d +++ b/compiler/src/dmd/e2ir.d @@ -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 diff --git a/compiler/test/runnable/rvalue1.d b/compiler/test/runnable/rvalue1.d index 07ea4270b881..f8134f718a9f 100644 --- a/compiler/test/runnable/rvalue1.d +++ b/compiler/test/runnable/rvalue1.d @@ -55,6 +55,8 @@ struct S4 { void* p; + this(ref S4) { } + this(S4 s) { assert(&s is &x); // confirm the rvalue reference