From 2bdef084ba336c3f52e24dae81c87ad00a2067a6 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Sun, 13 Mar 2016 14:16:39 +0000 Subject: [PATCH] Avoid warnings when compiling argerr/{146,147,148}.c with gcc. Test cases conerr/{53,54}.c rely on junk in uninitialized local variables, so ensure that there is some. Test case function/72.c relies on an object moving, but it might be pinned by an ambiguous reference from the stack, so don't register the stack as a root. Copied from Perforce Change: 189964 ServerID: perforce.ravenbrook.com --- mps/test/argerr/146.c | 69 ++--------------------------------------- mps/test/argerr/147.c | 69 ++--------------------------------------- mps/test/argerr/148.c | 70 ++---------------------------------------- mps/test/conerr/53.c | 5 +++ mps/test/conerr/54.c | 5 +++ mps/test/function/72.c | 48 ++++++++++++++--------------- 6 files changed, 40 insertions(+), 226 deletions(-) diff --git a/mps/test/argerr/146.c b/mps/test/argerr/146.c index c6d465671eb..55880de0267 100644 --- a/mps/test/argerr/146.c +++ b/mps/test/argerr/146.c @@ -142,41 +142,7 @@ struct mps_fmt_A_s fmtA = the allocated object to have */ -mycell *allocdumb(mps_ap_t ap, size_t size) -{ - mps_addr_t p; - mycell *q; - size_t bytes; - size_t alignment; - - bytes = offsetof(struct data, ref) + size; - - alignment = MPS_PF_ALIGN; /* needed to make it as wide as size_t */ - -/* twiddle the value of size to make it aligned */ - bytes = (bytes+alignment-1) & ~(alignment-1); - - do - { - die(mps_reserve(&p, ap, bytes), "Reserve: "); - INCCOUNT(RESERVE_COUNT); - q=p; - q->data.tag = MCdata; - q->data.id = nextid; - q->data.copycount = 0; - q->data.numrefs = 0; - q->data.checkedflag = 0; - q->data.size = bytes; - } - while (!mps_commit(ap, p, bytes)); - INCCOUNT(ALLOC_COUNT); - commentif(alloccomments, "allocated id %li at %p.", nextid, q); - nextid += 1; - - return q; -} - -mycell *allocone(mps_ap_t ap, int size) +static mycell *allocone(mps_ap_t ap, int size) { mps_addr_t p; mycell *q; @@ -222,7 +188,6 @@ static mps_res_t myscan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit) int i; INCCOUNT(SCANCALL_COUNT); - MPS_SCAN_BEGIN(ss) { while (base < limit) { @@ -273,7 +238,6 @@ static mps_res_t myscan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit) } } } - MPS_SCAN_END(ss); return MPS_RES_OK; } @@ -390,7 +354,7 @@ static void myfwd(mps_addr_t object, mps_addr_t to) /* set the nth reference of obj to to (n from 0 to size-1) */ -void setref(mycell *obj, int n, mycell *to) +static void setref(mycell *obj, int n, mycell *to) { asserts(obj->tag = MCdata, "setref: from non-data object."); asserts(to->tag = MCdata, "setref: to non-data object."); @@ -400,35 +364,6 @@ void setref(mycell *obj, int n, mycell *to) obj->data.ref[n].id = to->data.id; } -mycell *getref(mycell *obj, int n) -{ - asserts(obj->tag = MCdata, "getref: from non-data object."); - asserts(obj->data.numrefs > n, "getref: access beyond object size."); - return obj->data.ref[n].addr; -} - -mps_addr_t getdata(mycell *obj) -{ - return (mps_addr_t) &(obj->data.ref[0]); -} - -long int getid(mycell *obj) -{ - asserts(obj->tag = MCdata, "getid: non-data object."); - return obj->data.id; -} - -long int getcopycount(mycell *obj) -{ - asserts(obj->tag = MCdata, "getcopycount: non-data object."); - return obj->data.copycount; -} - -long int getsize(mycell *obj) -{ - asserts(obj->tag = MCdata, "getsize: non-data object."); - return obj->data.numrefs; -} /* ---- Now the test itself! ---- */ diff --git a/mps/test/argerr/147.c b/mps/test/argerr/147.c index 0b11507cc81..0b17ec430fe 100644 --- a/mps/test/argerr/147.c +++ b/mps/test/argerr/147.c @@ -142,41 +142,8 @@ struct mps_fmt_A_s fmtA = the allocated object to have */ -mycell *allocdumb(mps_ap_t ap, size_t size) -{ - mps_addr_t p; - mycell *q; - size_t bytes; - size_t alignment; - bytes = offsetof(struct data, ref) + size; - - alignment = MPS_PF_ALIGN; /* needed to make it as wide as size_t */ - -/* twiddle the value of size to make it aligned */ - bytes = (bytes+alignment-1) & ~(alignment-1); - - do - { - die(mps_reserve(&p, ap, bytes), "Reserve: "); - INCCOUNT(RESERVE_COUNT); - q=p; - q->data.tag = MCdata; - q->data.id = nextid; - q->data.copycount = 0; - q->data.numrefs = 0; - q->data.checkedflag = 0; - q->data.size = bytes; - } - while (!mps_commit(ap, p, bytes)); - INCCOUNT(ALLOC_COUNT); - commentif(alloccomments, "allocated id %li at %p.", nextid, q); - nextid += 1; - - return q; -} - -mycell *allocone(mps_ap_t ap, int size) +static mycell *allocone(mps_ap_t ap, int size) { mps_addr_t p; mycell *q; @@ -222,7 +189,6 @@ static mps_res_t myscan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit) int i; INCCOUNT(SCANCALL_COUNT); - MPS_SCAN_BEGIN(ss) { while (base < limit) { @@ -273,7 +239,6 @@ static mps_res_t myscan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit) } } } - MPS_SCAN_END(ss); return MPS_RES_OK; } @@ -390,7 +355,7 @@ static void myfwd(mps_addr_t object, mps_addr_t to) /* set the nth reference of obj to to (n from 0 to size-1) */ -void setref(mycell *obj, int n, mycell *to) +static void setref(mycell *obj, int n, mycell *to) { asserts(obj->tag = MCdata, "setref: from non-data object."); asserts(to->tag = MCdata, "setref: to non-data object."); @@ -400,36 +365,6 @@ void setref(mycell *obj, int n, mycell *to) obj->data.ref[n].id = to->data.id; } -mycell *getref(mycell *obj, int n) -{ - asserts(obj->tag = MCdata, "getref: from non-data object."); - asserts(obj->data.numrefs > n, "getref: access beyond object size."); - return obj->data.ref[n].addr; -} - -mps_addr_t getdata(mycell *obj) -{ - return (mps_addr_t) &(obj->data.ref[0]); -} - -long int getid(mycell *obj) -{ - asserts(obj->tag = MCdata, "getid: non-data object."); - return obj->data.id; -} - -long int getcopycount(mycell *obj) -{ - asserts(obj->tag = MCdata, "getcopycount: non-data object."); - return obj->data.copycount; -} - -long int getsize(mycell *obj) -{ - asserts(obj->tag = MCdata, "getsize: non-data object."); - return obj->data.numrefs; -} - /* ---- Now the test itself! ---- */ #define genCOUNT (3) diff --git a/mps/test/argerr/148.c b/mps/test/argerr/148.c index 814429c1cdb..ca66e2b348f 100644 --- a/mps/test/argerr/148.c +++ b/mps/test/argerr/148.c @@ -142,41 +142,7 @@ struct mps_fmt_A_s fmtA = the allocated object to have */ -mycell *allocdumb(mps_ap_t ap, size_t size) -{ - mps_addr_t p; - mycell *q; - size_t bytes; - size_t alignment; - - bytes = offsetof(struct data, ref) + size; - - alignment = MPS_PF_ALIGN; /* needed to make it as wide as size_t */ - -/* twiddle the value of size to make it aligned */ - bytes = (bytes+alignment-1) & ~(alignment-1); - - do - { - die(mps_reserve(&p, ap, bytes), "Reserve: "); - INCCOUNT(RESERVE_COUNT); - q=p; - q->data.tag = MCdata; - q->data.id = nextid; - q->data.copycount = 0; - q->data.numrefs = 0; - q->data.checkedflag = 0; - q->data.size = bytes; - } - while (!mps_commit(ap, p, bytes)); - INCCOUNT(ALLOC_COUNT); - commentif(alloccomments, "allocated id %li at %p.", nextid, q); - nextid += 1; - - return q; -} - -mycell *allocone(mps_ap_t ap, int size) +static mycell *allocone(mps_ap_t ap, int size) { mps_addr_t p; mycell *q; @@ -222,7 +188,6 @@ static mps_res_t myscan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit) int i; INCCOUNT(SCANCALL_COUNT); - MPS_SCAN_BEGIN(ss) { while (base < limit) { @@ -273,7 +238,6 @@ static mps_res_t myscan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit) } } } - MPS_SCAN_END(ss); return MPS_RES_OK; } @@ -390,7 +354,7 @@ static void myfwd(mps_addr_t object, mps_addr_t to) /* set the nth reference of obj to to (n from 0 to size-1) */ -void setref(mycell *obj, int n, mycell *to) +static void setref(mycell *obj, int n, mycell *to) { asserts(obj->tag = MCdata, "setref: from non-data object."); asserts(to->tag = MCdata, "setref: to non-data object."); @@ -400,36 +364,6 @@ void setref(mycell *obj, int n, mycell *to) obj->data.ref[n].id = to->data.id; } -mycell *getref(mycell *obj, int n) -{ - asserts(obj->tag = MCdata, "getref: from non-data object."); - asserts(obj->data.numrefs > n, "getref: access beyond object size."); - return obj->data.ref[n].addr; -} - -mps_addr_t getdata(mycell *obj) -{ - return (mps_addr_t) &(obj->data.ref[0]); -} - -long int getid(mycell *obj) -{ - asserts(obj->tag = MCdata, "getid: non-data object."); - return obj->data.id; -} - -long int getcopycount(mycell *obj) -{ - asserts(obj->tag = MCdata, "getcopycount: non-data object."); - return obj->data.copycount; -} - -long int getsize(mycell *obj) -{ - asserts(obj->tag = MCdata, "getsize: non-data object."); - return obj->data.numrefs; -} - /* ---- Now the test itself! ---- */ #define genCOUNT (3) diff --git a/mps/test/conerr/53.c b/mps/test/conerr/53.c index 0cd7a08ac37..d156e3d7f05 100644 --- a/mps/test/conerr/53.c +++ b/mps/test/conerr/53.c @@ -11,6 +11,8 @@ OUTPUT_SPEC END_HEADER */ +#include + #include "testlib.h" #include "mpscamc.h" #include "myfmt.h" @@ -20,6 +22,9 @@ static void test(void) mps_arena_t arena; mps_ld_s ld; + /* overwrite ld with junk */ + memset(&ld, 0xff, sizeof ld); + cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); /* diff --git a/mps/test/conerr/54.c b/mps/test/conerr/54.c index 994a5f73b7d..f5474c6e318 100644 --- a/mps/test/conerr/54.c +++ b/mps/test/conerr/54.c @@ -11,6 +11,8 @@ OUTPUT_SPEC END_HEADER */ +#include + #include "testlib.h" #include "mpscamc.h" #include "myfmt.h" @@ -20,6 +22,9 @@ static void test(void) mps_arena_t arena; mps_ld_s ld; + /* overwrite ld with junk */ + memset(&ld, 0xff, sizeof ld); + cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); /* diff --git a/mps/test/function/72.c b/mps/test/function/72.c index 6a761742cc2..c1d3c158f2d 100644 --- a/mps/test/function/72.c +++ b/mps/test/function/72.c @@ -15,35 +15,33 @@ END_HEADER #include "mpscamc.h" #include "exfmt.h" +void *stackpointer; + #define genCOUNT (3) static mps_gen_param_s testChain[genCOUNT] = { { 6000, 0.90 }, { 8000, 0.65 }, { 16000, 0.50 } }; -void *stackpointer; -mycell *z; - static void test(void) { mps_arena_t arena; mps_pool_t pool; - mps_thr_t thread; mps_root_t root; mps_chain_t chain; mps_fmt_t format; mps_ap_t ap; - mycell *a, *b; + mycell *a[3], *bad; + int i; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); - cdie(mps_thread_reg(&thread, arena), "register thread"); + /* Clamp the arena so that we can be sure that objects don't move. */ + mps_arena_clamp(arena); - cdie( - mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, - mps_stack_scan_ambig, stackpointer, 0), - "create root"); + cdie(mps_root_create_area(&root, arena, mps_rank_exact(), 0, &a[0], &a[3], + mps_scan_area, NULL), "create area"); cdie( mps_fmt_create_A(&format, arena, &fmtA), @@ -59,22 +57,27 @@ static void test(void) mps_ap_create(&ap, pool, mps_rank_exact()), "create ap"); - a = allocone(ap, 1024, 1); - z = a; - - b = allocone(ap, 1024, 1); - setref(b, 0, a); - - a = allocdumb(ap, 1024*64, 1); - a = allocdumb(ap, 1024*64, 1); + /* Remember the first allocation at a[0] (which is a root) and also + * at bad (which is not reachable). */ + bad = a[0] = a[1] = allocone(ap, 1, 1); + for (i = 0; i < 1000; ++i) { + a[2] = allocone(ap, 1, 1); + setref(a[2], 0, a[1]); + a[1] = a[2]; + } + /* The first collection will cause a[0] to move, but because bad + * isn't scanned it doesn't get updated, and ends up pointing to + * oldspace. */ comment("Collecting..."); mps_arena_collect(arena); - asserts(z != a, "Didn't move!"); + asserts(bad != a[0], "Didn't move!"); + /* Write the bad pointer into a scannable part of the heap. The MPS + * should spot this when it collects. Note that we can't use setref + * here because we need to bypass the check. */ comment("Writing bad pointer..."); - - b->data.ref[0].addr = z; + a[0]->data.ref[0].addr = bad; mps_arena_collect(arena); comment("Bad pointer not spotted in collection"); @@ -96,9 +99,6 @@ static void test(void) mps_root_destroy(root); comment("Destroyed root."); - mps_thread_dereg(thread); - comment("Deregistered thread."); - mps_arena_destroy(arena); comment("Destroyed arena.");