Skip to content

Commit f2fbdca

Browse files
ibuclawdlang-bot
authored andcommitted
fix Issue 22122 - [REG 2.097][ICE] Segmentation fault in in dmd.access.hasPackageAccess
1 parent c0a206d commit f2fbdca

File tree

3 files changed

+67
-15
lines changed

3 files changed

+67
-15
lines changed

src/dmd/statementsem.d

+9-15
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ private extern (C++) final class StatementSemanticVisitor : Visitor
533533
const inLoopSave = sc.inLoop;
534534
sc.inLoop = true;
535535
if (ds._body)
536-
ds._body = ds._body.semanticScope(sc, ds, ds);
536+
ds._body = ds._body.semanticScope(sc, ds, ds, null);
537537
sc.inLoop = inLoopSave;
538538

539539
if (ds.condition.op == TOK.dotIdentifier)
@@ -2342,7 +2342,7 @@ private extern (C++) final class StatementSemanticVisitor : Visitor
23422342
CtorFlow ctorflow_then = sc.ctorflow; // move flow results
23432343
sc.ctorflow = ctorflow_root; // reset flow analysis back to root
23442344
if (ifs.elsebody)
2345-
ifs.elsebody = ifs.elsebody.semanticScope(sc, null, null);
2345+
ifs.elsebody = ifs.elsebody.semanticScope(sc, null, null, null);
23462346

23472347
// Merge 'then' results into 'else' results
23482348
sc.merge(ifs.loc, ctorflow_then);
@@ -3922,13 +3922,9 @@ private extern (C++) final class StatementSemanticVisitor : Visitor
39223922
enum FLAGcpp = 1;
39233923
enum FLAGd = 2;
39243924

3925-
tcs.tryBody = sc.tryBody;
3926-
3927-
scope sc2 = sc.push();
3928-
sc2.tryBody = tcs;
3929-
tcs._body = tcs._body.semanticScope(sc2, null, null);
3925+
tcs.tryBody = sc.tryBody; // chain on the in-flight tryBody
3926+
tcs._body = tcs._body.semanticScope(sc, null, null, tcs);
39303927
assert(tcs._body);
3931-
sc2.pop();
39323928

39333929
/* Even if body is empty, still do semantic analysis on catches
39343930
*/
@@ -4009,12 +4005,8 @@ private extern (C++) final class StatementSemanticVisitor : Visitor
40094005
override void visit(TryFinallyStatement tfs)
40104006
{
40114007
//printf("TryFinallyStatement::semantic()\n");
4012-
tfs.tryBody = sc.tryBody;
4013-
4014-
auto sc2 = sc.push();
4015-
sc2.tryBody = tfs;
4016-
tfs._body = tfs._body.statementSemantic(sc2);
4017-
sc2.pop();
4008+
tfs.tryBody = sc.tryBody; // chain on in-flight tryBody
4009+
tfs._body = tfs._body.semanticScope(sc, null, null, tfs);
40184010

40194011
sc = sc.push();
40204012
sc.tf = tfs;
@@ -4445,7 +4437,7 @@ Statement semanticNoScope(Statement s, Scope* sc)
44454437
}
44464438

44474439
// Same as semanticNoScope(), but do create a new scope
4448-
Statement semanticScope(Statement s, Scope* sc, Statement sbreak, Statement scontinue)
4440+
private Statement semanticScope(Statement s, Scope* sc, Statement sbreak, Statement scontinue, Statement tryBody)
44494441
{
44504442
auto sym = new ScopeDsymbol();
44514443
sym.parent = sc.scopesym;
@@ -4454,6 +4446,8 @@ Statement semanticScope(Statement s, Scope* sc, Statement sbreak, Statement scon
44544446
scd.sbreak = sbreak;
44554447
if (scontinue)
44564448
scd.scontinue = scontinue;
4449+
if (tryBody)
4450+
scd.tryBody = tryBody;
44574451
s = s.semanticNoScope(scd);
44584452
scd.pop();
44594453
return s;

test/compilable/imports/imp22122.d

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module imports.imp22122;
2+
3+
package struct Imp22122
4+
{
5+
}

test/compilable/test22122.d

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// EXTRA_FILES: imports/imp22122.d
2+
module imports.test22122;
3+
4+
struct S22122
5+
{
6+
import imports.imp22122;
7+
Variant!(Imp22122)[] array;
8+
}
9+
10+
void test22122_catch(S22122 s)
11+
{
12+
try
13+
{
14+
foreach(elem; s.array)
15+
{
16+
import imports.imp22122;
17+
with(elem.get!Imp22122)
18+
{
19+
}
20+
}
21+
}
22+
catch (Exception)
23+
{
24+
}
25+
}
26+
27+
void test22122_finally(S22122 s)
28+
{
29+
try
30+
{
31+
foreach(elem; s.array)
32+
{
33+
import imports.imp22122;
34+
with(elem.get!Imp22122)
35+
{
36+
}
37+
}
38+
}
39+
finally
40+
{
41+
}
42+
}
43+
44+
private struct Variant(T)
45+
{
46+
union Impl
47+
{
48+
}
49+
auto get(E)()
50+
{
51+
return Impl();
52+
}
53+
}

0 commit comments

Comments
 (0)