Skip to content

Commit a0318c2

Browse files
authored
Merge pull request #4692 from kinke/merge_stable
Merge upstream stable
2 parents 5fa8e0d + 39e896b commit a0318c2

File tree

7 files changed

+95
-11
lines changed

7 files changed

+95
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ include(GetLinuxDistribution)
120120
set(LDC_VERSION "1.39.0") # May be overridden by git hash tag
121121
set(DMDFE_MAJOR_VERSION 2)
122122
set(DMDFE_MINOR_VERSION 109)
123-
set(DMDFE_PATCH_VERSION 0)
123+
set(DMDFE_PATCH_VERSION 1)
124124

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

dmd/optimize.d

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,18 +1238,21 @@ Expression optimize(Expression e, int result, bool keepLvalue = false)
12381238
if (expOptimize(e.e1, WANTvalue))
12391239
return;
12401240
const oror = e.op == EXP.orOr;
1241-
if (e.e1.toBool().hasValue(oror))
1241+
void returnE_e1()
12421242
{
1243-
// Replace with (e1, oror)
1244-
ret = IntegerExp.createBool(oror);
1245-
ret = Expression.combine(e.e1, ret);
1246-
if (e.type.toBasetype().ty == Tvoid)
1243+
ret = e.e1;
1244+
if (!e.e1.type.equals(e.type))
12471245
{
1248-
ret = new CastExp(e.loc, ret, Type.tvoid);
1246+
ret = new CastExp(e.loc, ret, e.type);
12491247
ret.type = e.type;
1248+
ret = optimize(ret, result, false);
12501249
}
1251-
ret = optimize(ret, result, false);
1252-
return;
1250+
}
1251+
if (e.e1.toBool().hasValue(oror))
1252+
{
1253+
// e_true || e2 -> e_true
1254+
// e_false && e2 -> e_false
1255+
return returnE_e1();
12531256
}
12541257
expOptimize(e.e2, WANTvalue);
12551258
if (e.e1.isConst())
@@ -1263,6 +1266,7 @@ Expression optimize(Expression e, int result, bool keepLvalue = false)
12631266
}
12641267
else if (e1Opt.hasValue(!oror))
12651268
{
1269+
12661270
if (e.type.toBasetype().ty == Tvoid)
12671271
ret = e.e2;
12681272
else
@@ -1272,6 +1276,29 @@ Expression optimize(Expression e, int result, bool keepLvalue = false)
12721276
}
12731277
}
12741278
}
1279+
else if (e.e2.isConst())
1280+
{
1281+
const e2Opt = e.e2.toBool();
1282+
if (e2Opt.hasValue(oror))
1283+
{
1284+
// e1 || true -> (e1, true)
1285+
// e1 && false -> (e1, false)
1286+
ret = IntegerExp.createBool(oror);
1287+
ret = Expression.combine(e.e1, ret);
1288+
if (e.type.toBasetype().ty == Tvoid)
1289+
{
1290+
ret = new CastExp(e.loc, ret, Type.tvoid);
1291+
ret.type = e.type;
1292+
}
1293+
ret = optimize(ret, result, false);
1294+
}
1295+
else if (e2Opt.hasValue(!oror))
1296+
{
1297+
// e1 || false -> e1
1298+
// e1 && true -> e1
1299+
return returnE_e1();
1300+
}
1301+
}
12751302
}
12761303

12771304
void visitCmp(CmpExp e)

dmd/semantic2.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,4 +898,11 @@ private extern(C++) final class StaticAAVisitor : SemanticTimeTransitiveVisitor
898898

899899
aaExp.lowering = loweredExp;
900900
}
901+
902+
// https://issues.dlang.org/show_bug.cgi?id=24602
903+
// TODO: Is this intionally not visited by SemanticTimeTransitiveVisitor?
904+
override void visit(ClassReferenceExp crExp)
905+
{
906+
this.visit(crExp.value);
907+
}
901908
}

packaging/dlang-tools_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.109.0
1+
v2.109.1

tests/dmd/compilable/issue24566.d

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// https://issues.dlang.org/show_bug.cgi?id=24566
2+
3+
void test24566a()
4+
{
5+
enum a = true;
6+
bool b = true;
7+
enum str = "a";
8+
if (a && str.length > 1 && str[1] == 'a') {}
9+
if (b && str.length > 1 && str[1] == 'a') {}
10+
if (!b && str.length > 1 && str[1] == 'a') {}
11+
if (str.length > 1 && b && str[1] == 'a') {}
12+
}
13+
14+
void test24566b()
15+
{
16+
enum a = false;
17+
bool b = false;
18+
enum str = "a";
19+
if (a || str.length <= 1 || str[1] == 'a') {}
20+
if (b || str.length <= 1 || str[1] == 'a') {}
21+
if (!b || str.length <= 1 || str[1] == 'a') {}
22+
if (str.length <= 1 || b || str[1] == 'a') {}
23+
}

tests/dmd/runnable/staticaa.d

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,32 @@ void testStaticArray()
181181

182182
/////////////////////////////////////////////
183183

184+
// https://issues.dlang.org/show_bug.cgi?id=24602
185+
186+
class Set
187+
{
188+
bool[string] aa;
189+
190+
this(bool[string] aa)
191+
{
192+
this.aa = aa;
193+
}
194+
}
195+
196+
class Bar
197+
{
198+
Set x = new Set(["a": 1, "b": 0]);
199+
}
200+
201+
void testClassLiteral()
202+
{
203+
assert(new Bar().x.aa["a"] == 1);
204+
assert(new Bar().x.aa["b"] == 0);
205+
}
206+
207+
/////////////////////////////////////////////
208+
209+
184210
void main()
185211
{
186212
testSimple();
@@ -192,4 +218,5 @@ void main()
192218
testLocalStatic();
193219
testEnumInit();
194220
testStaticArray();
221+
testClassLiteral();
195222
}

0 commit comments

Comments
 (0)