Skip to content

Commit

Permalink
Merge pull request #4692 from kinke/merge_stable
Browse files Browse the repository at this point in the history
Merge upstream stable
  • Loading branch information
kinke authored Jul 1, 2024
2 parents 5fa8e0d + 39e896b commit a0318c2
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ include(GetLinuxDistribution)
set(LDC_VERSION "1.39.0") # May be overridden by git hash tag
set(DMDFE_MAJOR_VERSION 2)
set(DMDFE_MINOR_VERSION 109)
set(DMDFE_PATCH_VERSION 0)
set(DMDFE_PATCH_VERSION 1)

set(DMD_VERSION ${DMDFE_MAJOR_VERSION}.${DMDFE_MINOR_VERSION}.${DMDFE_PATCH_VERSION})

Expand Down
43 changes: 35 additions & 8 deletions dmd/optimize.d
Original file line number Diff line number Diff line change
Expand Up @@ -1238,18 +1238,21 @@ Expression optimize(Expression e, int result, bool keepLvalue = false)
if (expOptimize(e.e1, WANTvalue))
return;
const oror = e.op == EXP.orOr;
if (e.e1.toBool().hasValue(oror))
void returnE_e1()
{
// Replace with (e1, oror)
ret = IntegerExp.createBool(oror);
ret = Expression.combine(e.e1, ret);
if (e.type.toBasetype().ty == Tvoid)
ret = e.e1;
if (!e.e1.type.equals(e.type))
{
ret = new CastExp(e.loc, ret, Type.tvoid);
ret = new CastExp(e.loc, ret, e.type);
ret.type = e.type;
ret = optimize(ret, result, false);
}
ret = optimize(ret, result, false);
return;
}
if (e.e1.toBool().hasValue(oror))
{
// e_true || e2 -> e_true
// e_false && e2 -> e_false
return returnE_e1();
}
expOptimize(e.e2, WANTvalue);
if (e.e1.isConst())
Expand All @@ -1263,6 +1266,7 @@ Expression optimize(Expression e, int result, bool keepLvalue = false)
}
else if (e1Opt.hasValue(!oror))
{

if (e.type.toBasetype().ty == Tvoid)
ret = e.e2;
else
Expand All @@ -1272,6 +1276,29 @@ Expression optimize(Expression e, int result, bool keepLvalue = false)
}
}
}
else if (e.e2.isConst())
{
const e2Opt = e.e2.toBool();
if (e2Opt.hasValue(oror))
{
// e1 || true -> (e1, true)
// e1 && false -> (e1, false)
ret = IntegerExp.createBool(oror);
ret = Expression.combine(e.e1, ret);
if (e.type.toBasetype().ty == Tvoid)
{
ret = new CastExp(e.loc, ret, Type.tvoid);
ret.type = e.type;
}
ret = optimize(ret, result, false);
}
else if (e2Opt.hasValue(!oror))
{
// e1 || false -> e1
// e1 && true -> e1
return returnE_e1();
}
}
}

void visitCmp(CmpExp e)
Expand Down
7 changes: 7 additions & 0 deletions dmd/semantic2.d
Original file line number Diff line number Diff line change
Expand Up @@ -898,4 +898,11 @@ private extern(C++) final class StaticAAVisitor : SemanticTimeTransitiveVisitor

aaExp.lowering = loweredExp;
}

// https://issues.dlang.org/show_bug.cgi?id=24602
// TODO: Is this intionally not visited by SemanticTimeTransitiveVisitor?
override void visit(ClassReferenceExp crExp)
{
this.visit(crExp.value);
}
}
2 changes: 1 addition & 1 deletion packaging/dlang-tools_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.109.0
v2.109.1
2 changes: 1 addition & 1 deletion runtime/phobos
23 changes: 23 additions & 0 deletions tests/dmd/compilable/issue24566.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// https://issues.dlang.org/show_bug.cgi?id=24566

void test24566a()
{
enum a = true;
bool b = true;
enum str = "a";
if (a && str.length > 1 && str[1] == 'a') {}
if (b && str.length > 1 && str[1] == 'a') {}
if (!b && str.length > 1 && str[1] == 'a') {}
if (str.length > 1 && b && str[1] == 'a') {}
}

void test24566b()
{
enum a = false;
bool b = false;
enum str = "a";
if (a || str.length <= 1 || str[1] == 'a') {}
if (b || str.length <= 1 || str[1] == 'a') {}
if (!b || str.length <= 1 || str[1] == 'a') {}
if (str.length <= 1 || b || str[1] == 'a') {}
}
27 changes: 27 additions & 0 deletions tests/dmd/runnable/staticaa.d
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,32 @@ void testStaticArray()

/////////////////////////////////////////////

// https://issues.dlang.org/show_bug.cgi?id=24602

class Set
{
bool[string] aa;

this(bool[string] aa)
{
this.aa = aa;
}
}

class Bar
{
Set x = new Set(["a": 1, "b": 0]);
}

void testClassLiteral()
{
assert(new Bar().x.aa["a"] == 1);
assert(new Bar().x.aa["b"] == 0);
}

/////////////////////////////////////////////


void main()
{
testSimple();
Expand All @@ -192,4 +218,5 @@ void main()
testLocalStatic();
testEnumInit();
testStaticArray();
testClassLiteral();
}

0 comments on commit a0318c2

Please sign in to comment.