Skip to content

Commit

Permalink
Fix bugzilla 24498 - Multidimensional array not scanned by GC (#16400)
Browse files Browse the repository at this point in the history
For expression `new int[][][](2, 2)` the relevant element type is
`int[]` and not `int`, because only two dimensions are allocated.
  • Loading branch information
tim-dlang authored Apr 19, 2024
1 parent ec25e56 commit f1307d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -5335,7 +5335,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
lowering = new DotIdExp(exp.loc, lowering, Id.object);

auto tbn = exp.type.nextOf();
while (tbn.ty == Tarray)
size_t i = nargs;
while (tbn.ty == Tarray && --i)
tbn = tbn.nextOf();
auto unqualTbn = tbn.unqualify(MODFlags.wild | MODFlags.const_ |
MODFlags.immutable_ | MODFlags.shared_);
Expand Down
21 changes: 21 additions & 0 deletions compiler/test/runnable/test24498.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import core.memory;

void main()
{
{
int[][] a = new int[][](2, 2);
assert(!(GC.getAttr(a.ptr) & GC.BlkAttr.NO_SCAN));
assert(GC.getAttr(a[0].ptr) & GC.BlkAttr.NO_SCAN);
}
{
void*[][] a = new void*[][](2, 2);
assert(!(GC.getAttr(a.ptr) & GC.BlkAttr.NO_SCAN));
assert(!(GC.getAttr(a[0].ptr) & GC.BlkAttr.NO_SCAN));
}
{
int[][][] a = new int[][][](2, 2);
assert(!(GC.getAttr(a.ptr) & GC.BlkAttr.NO_SCAN));
assert(!(GC.getAttr(a[0].ptr) & GC.BlkAttr.NO_SCAN));
assert(a[0][0].ptr is null);
}
}

0 comments on commit f1307d6

Please sign in to comment.