Branch: Tag:

2021-09-04

2021-09-04 13:29:52 by Henrik Grubbström (Grubba) <grubba@grubba.org>

GC: Make gcc 11 happy.

Gcc 11 complains about the pointer arithmetic previously used
on mc_work_queue (especially the free(mc_work_queue - 1)).
Get rid of the need for the pointer arithmetic by wasting one
pointer of unused memory. This seems to make gcc 11 happy.

4891:       else {    if (mc_wq_used > mc_wq_size) { -  struct mc_marker **p; +  void *p;    mc_wq_size *= 2; -  p = realloc (mc_work_queue + 1, mc_wq_size * sizeof (mc_work_queue[0])); +  /* NB: Add 1 to size to compensate for 1-based indexing. */ +  p = realloc (mc_work_queue, (mc_wq_size + 1) * sizeof (mc_work_queue[0]));    if (!p) { -  make_error (msg_out_of_mem_2, mc_wq_size * sizeof (mc_work_queue[0])); +  make_error (msg_out_of_mem_2, +  (mc_wq_size + 1) * sizeof (mc_work_queue[0]));    free_svalue (&throw_value);    move_svalue (&throw_value, --Pike_sp);    mc_wq_size /= 2;    return;    } -  mc_work_queue = p - 1; /* Compensate for 1-based indexing. */ +  mc_work_queue = p;    }    pos = mc_wq_used++;    }
5607:    }       assert (mc_work_queue == NULL); -  mc_work_queue = malloc (MC_WQ_START_SIZE * sizeof (mc_work_queue[0])); +  /* NB: Add 1 to size to compensate for 1-based indexing. */ +  mc_work_queue = malloc ((MC_WQ_START_SIZE + 1) * sizeof (mc_work_queue[0]));    if (!mc_work_queue) {    stop_mc();    SIMPLE_OUT_OF_MEMORY_ERROR ("Pike.count_memory", -  MC_WQ_START_SIZE * sizeof (mc_work_queue[0])); +  (MC_WQ_START_SIZE + 1) * +  sizeof (mc_work_queue[0]));    }    mc_wq_size = MC_WQ_START_SIZE; -  mc_work_queue--; /* Compensate for 1-based indexing. */ +     mc_wq_used = 1;       assert (!mc_pass);
5634:    continue;       else if (!REFCOUNTED_TYPE(TYPEOF(*s))) { -  mc_work_queue++; /* Compensate for 1-based indexing. */ +     free(mc_work_queue);    mc_work_queue = NULL;    stop_mc();
5647:    if (TYPEOF(*s) == T_FUNCTION) {    struct svalue s2;    if (!(s2.u.program = program_from_function (s))) { -  mc_work_queue++; /* Compensate for 1-based indexing. */ +     free(mc_work_queue);    mc_work_queue = NULL;    stop_mc();
5672:    if (!mc_block_pike_cycle_depth && TYPEOF(*s) == T_OBJECT) {    int cycle_depth = mc_cycle_depth_from_obj (s->u.object);    if (TYPEOF(throw_value) != PIKE_T_FREE) { -  mc_work_queue++; /* Compensate for 1-based indexing. */ +     free(mc_work_queue);    mc_work_queue = NULL;    stop_mc();
5802:    }       if (TYPEOF(throw_value) != PIKE_T_FREE) { -  mc_work_queue++; /* Compensate for 1-based indexing. */ +     free(mc_work_queue);    mc_work_queue = NULL;    stop_mc();
6051:   #endif       assert (mc_wq_used == 1); -  mc_work_queue++; /* Compensate for 1-based indexing. */ +     free(mc_work_queue);    mc_work_queue = NULL;    stop_mc();
6168:    }       assert (mc_work_queue == NULL); -  mc_work_queue = malloc (MC_WQ_START_SIZE * sizeof (mc_work_queue[0])); +  /* NB: Add 1 to size to compensate for 1-based indexing. */ +  mc_work_queue = malloc ((MC_WQ_START_SIZE + 1) * sizeof (mc_work_queue[0]));    if (!mc_work_queue) {    stop_mc();    SIMPLE_OUT_OF_MEMORY_ERROR ("Pike.count_memory", -  MC_WQ_START_SIZE * sizeof (mc_work_queue[0])); +  (MC_WQ_START_SIZE + 1) * sizeof (mc_work_queue[0]));    } -  /* NB: 1-based indexing in mc_work_queue. */ -  mc_work_queue--; +     mc_wq_size = MC_WQ_START_SIZE;    mc_wq_used = 1;    mc_lookahead = -1;
6212:    mc_ref_from = (void *) (ptrdiff_t) -1;   #endif    -  mc_work_queue++; /* Compensate for 1-based indexing. */ +     free(mc_work_queue);    mc_work_queue = NULL;