Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 027fca5

Browse files
Geod24dlang-bot
authored andcommitted
Fix 21484: Infinite loop in core.memory : GC.{get,set,clr}Attr(const scope void*...)
Those functions never worked, and would cause an infinite recursion. In a non-optimized build that would exhaust the stack and trigger a SEGV, however in the optimized build we distribute, it results in an infinite loop as tail call optimization is performed.
1 parent 9a084ed commit 027fca5

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/core/memory.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ struct GC
408408
*/
409409
static uint getAttr( const scope void* p ) nothrow
410410
{
411-
return getAttr(cast()p);
411+
return gc_getAttr(cast(void*) p);
412412
}
413413

414414

@@ -435,7 +435,7 @@ struct GC
435435
*/
436436
static uint setAttr( const scope void* p, uint a ) nothrow
437437
{
438-
return setAttr(cast()p, a);
438+
return gc_setAttr(cast(void*) p, a);
439439
}
440440

441441

@@ -462,7 +462,7 @@ struct GC
462462
*/
463463
static uint clrAttr( const scope void* p, uint a ) nothrow
464464
{
465-
return clrAttr(cast()p, a);
465+
return gc_clrAttr(cast(void*) p, a);
466466
}
467467

468468

test/gc/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include ../common.mak
22

3-
TESTS := sentinel printf memstomp invariant logging precise precisegc forkgc forkgc2 sigmaskgc startbackgc \
4-
recoverfree nocollect
3+
TESTS := attributes sentinel printf memstomp invariant logging precise precisegc forkgc forkgc2 \
4+
sigmaskgc startbackgc recoverfree nocollect
55

66
SRC_GC = ../../src/gc/impl/conservative/gc.d
77
SRC = $(SRC_GC) ../../src/rt/lifetime.d
@@ -38,6 +38,9 @@ $(ROOT)/precise.done: RUN_ARGS += --DRT-gcopt=gc:precise
3838
$(ROOT)/precisegc: $(SRC)
3939
$(DMD) $(UDFLAGS) -gx -of$@ $(SRC) precisegc.d
4040

41+
$(ROOT)/attributes: attributes.d
42+
$(DMD) $(UDFLAGS) -of$@ attributes.d
43+
4144
$(ROOT)/forkgc: forkgc.d
4245
$(DMD) $(UDFLAGS) -of$@ forkgc.d
4346

test/gc/attributes.d

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import core.memory;
2+
3+
// TODO: The following should work, but L10 (second assert) fails.
4+
version(none) void dotest(T) (T* ptr)
5+
{
6+
GC.clrAttr(ptr, uint.max);
7+
assert(GC.getAttr(ptr) == 0);
8+
9+
GC.setAttr(ptr, GC.BlkAttr.NO_MOVE);
10+
assert(GC.getAttr(ptr) == GC.BlkAttr.NO_MOVE);
11+
12+
GC.clrAttr(ptr, GC.BlkAttr.NO_MOVE);
13+
assert(GC.getAttr(ptr) == 0);
14+
GC.clrAttr(ptr, GC.BlkAttr.NO_MOVE);
15+
assert(GC.getAttr(ptr) == 0);
16+
}
17+
else void dotest(T) (T* ptr)
18+
{
19+
// https://issues.dlang.org/show_bug.cgi?id=21484
20+
GC.clrAttr(ptr, uint.max);
21+
GC.setAttr(ptr, GC.BlkAttr.NO_MOVE);
22+
GC.getAttr(ptr);
23+
}
24+
25+
void main ()
26+
{
27+
auto ptr = new int;
28+
dotest!(const(int))(ptr);
29+
dotest!(int)(ptr);
30+
}

0 commit comments

Comments
 (0)