From 955ea13ee59cf0960012e38d53409a9319cd920a Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Mon, 18 Jun 2018 15:41:29 +0100 Subject: [PATCH] Lo asserts on fixes to unallocated objects. New MMQA test case conerr/62.c checks this. Copied from Perforce Change: 193909 --- mps/code/poollo.c | 7 ++++ mps/test/conerr/60.c | 2 +- mps/test/conerr/61.c | 2 +- mps/test/conerr/62.c | 75 ++++++++++++++++++++++++++++++++++++++ mps/test/testsets/conerr | 2 + mps/test/testsets/coolonly | 2 + 6 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 mps/test/conerr/62.c diff --git a/mps/code/poollo.c b/mps/code/poollo.c index 4a1ebea034a..8e17b7c0948 100644 --- a/mps/code/poollo.c +++ b/mps/code/poollo.c @@ -724,6 +724,13 @@ static Res LOFix(Pool pool, ScanState ss, Seg seg, Ref *refIO) } i = AddrOffset(SegBase(seg), base) >> lo->alignShift; + + /* Not a real reference if unallocated. */ + if (!BTGet(loseg->alloc, i)) { + AVER_CRITICAL(ss->rank == RankAMBIG); + return ResOK; + } + if(!BTGet(loseg->mark, i)) { ss->wasMarked = FALSE; /* */ if(ss->rank == RankWEAK) { diff --git a/mps/test/conerr/60.c b/mps/test/conerr/60.c index d8b62bcd249..de43e0953f6 100644 --- a/mps/test/conerr/60.c +++ b/mps/test/conerr/60.c @@ -45,9 +45,9 @@ static void test(void) /* p is in the LO pool */ p = allocone(ap_lo, 0, NULL, NULL, sizeof(mycell)); - unaligned = (void *)((char*)p + 1); /* q is in the AMS pool with unaligned exact reference to p */ + unaligned = (void *)((char*)p + 1); q = allocone(ap_ams, 1, p, unaligned, sizeof(mycell)); mps_arena_start_collect(arena); diff --git a/mps/test/conerr/61.c b/mps/test/conerr/61.c index 557375a8637..f17ee06f778 100644 --- a/mps/test/conerr/61.c +++ b/mps/test/conerr/61.c @@ -39,9 +39,9 @@ static void test(void) /* p is in the AWL pool */ p = allocone(ap, 0, NULL, NULL, sizeof(mycell)); - unaligned = (void *)((char*)p + 1); /* q is in the AWL pool with unaligned exact reference to p */ + unaligned = (void *)((char*)p + 1); q = allocone(ap, 1, p, unaligned, sizeof(mycell)); mps_arena_start_collect(arena); diff --git a/mps/test/conerr/62.c b/mps/test/conerr/62.c new file mode 100644 index 00000000000..55e86998ad6 --- /dev/null +++ b/mps/test/conerr/62.c @@ -0,0 +1,75 @@ +/* +TEST_HEADER + id = $Id$ + summary = LO pool asserts on exact reference to unallocated object + language = c + link = myfmt.o testlib.o +OUTPUT_SPEC + assert = true + assertfile P= poollo.c + assertcond = ss->rank == RankAMBIG +END_HEADER +*/ + +#include "testlib.h" +#include "mpscams.h" +#include "mpsclo.h" +#include "myfmt.h" + +static void test(void) +{ + void *marker = ▮ + mps_arena_t arena; + mps_pool_t pool_ams, pool_lo; + mps_thr_t thread; + mps_root_t root; + mps_fmt_t format; + mps_ap_t ap_ams, ap_lo; + mps_addr_t p, q, unallocated; + + cdie(mps_arena_create_k(&arena, mps_arena_class_vm(), mps_args_none), "create arena"); + mps_arena_park(arena); + cdie(mps_thread_reg(&thread, arena), "register thread"); + cdie(mps_root_create_thread(&root, arena, thread, marker), "create root"); + cdie(mps_fmt_create_A(&format, arena, &fmtA), "create format"); + MPS_ARGS_BEGIN(args) { + MPS_ARGS_ADD(args, MPS_KEY_FORMAT, format); + cdie(mps_pool_create_k(&pool_ams, arena, mps_class_ams(), args), "ams pool"); + } MPS_ARGS_END(args); + MPS_ARGS_BEGIN(args) { + MPS_ARGS_ADD(args, MPS_KEY_FORMAT, format); + cdie(mps_pool_create_k(&pool_lo, arena, mps_class_lo(), args), "lo pool"); + } MPS_ARGS_END(args); + cdie(mps_ap_create(&ap_ams, pool_ams, mps_rank_exact()), "ams ap"); + cdie(mps_ap_create_k(&ap_lo, pool_lo, mps_args_none), "lo ap"); + + /* p is in the LO pool */ + p = allocone(ap_lo, 0, NULL, NULL, sizeof(mycell)); + + /* Destroy the LO allocation point so that p's segment gets unbuffered. */ + mps_ap_destroy(ap_lo); + + /* q is in the AMS pool with exact reference to p and unallocated object */ + unallocated = (void *)((char*)p + sizeof(mycell)); + q = allocone(ap_ams, 1, p, unallocated, sizeof(mycell)); + + mps_arena_start_collect(arena); + mps_arena_park(arena); + + /* Keep q (and thus p) alive during the collection. */ + report("q", "%p", q); + + mps_ap_destroy(ap_ams); + mps_pool_destroy(pool_lo); + mps_pool_destroy(pool_ams); + mps_fmt_destroy(format); + mps_root_destroy(root); + mps_thread_dereg(thread); + mps_arena_destroy(arena); +} + +int main(void) +{ + easy_tramp(test); + return 0; +} diff --git a/mps/test/testsets/conerr b/mps/test/testsets/conerr index 98d2e53520c..5d3a0af8171 100644 --- a/mps/test/testsets/conerr +++ b/mps/test/testsets/conerr @@ -68,3 +68,5 @@ conerr/56.c % conerr/58.c -- see conerr/59.c % conerr/60.c -- assertion is on the critical path +% conerr/61.c -- assertion is on the critical path +% conerr/62.c -- assertion is on the critical path diff --git a/mps/test/testsets/coolonly b/mps/test/testsets/coolonly index 636ec8ee288..10fe30a6310 100644 --- a/mps/test/testsets/coolonly +++ b/mps/test/testsets/coolonly @@ -46,4 +46,6 @@ conerr/22.c conerr/23.c conerr/27.c conerr/60.c +conerr/61.c +conerr/62.c function/72.c