On 10/19/20 8:21 PM, Jakub Jelinek via Gcc-patches wrote:

On Mon, Oct 19, 2020 at 06:57:49PM +0100, Kwok Cheung Yeung wrote:
--- a/libgomp/target.c
+++ b/libgomp/target.c
...
Otherwise LGTM.

Unfortunately, the committed patch 
(r11-4121-g1bfc07d150790fae93184a79a7cce897655cb37b)
causes build errors.

The error seems to be provoked by function cloning – as the code
itself looks fine:


static void
gomp_target_init (void)
{
...
  num_devices = 0;
...
// NEW LINES:
  if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_DISABLED)
    return;
...
 struct gomp_device_descr *devices_s
    = malloc (num_devices * sizeof (struct gomp_device_descr));
...
  for (i = 0; i < num_devices; i++)
    if (!(devices[i].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400))
      devices_s[num_devices_after_openmp++] = devices[i];

I fail so see why this gives now the -Werror warning:

../../../repos/gcc/libgomp/target.c: In function ‘gomp_target_init.part.0’:
../../../repos/gcc/libgomp/target.c:3367:45: error: array subscript 
[-27450512014448737, 27450512014448737] is outside array bounds of ‘struct 
gomp_device_descr[0]’ [-Werror=array-bounds]
 3367 |       devices_s[num_devices_after_openmp++] = devices[i];
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
../../../repos/gcc/libgomp/target.c:3353:7: note: referencing an object of size 
0 allocated by ‘malloc’
 3353 |     = malloc (num_devices * sizeof (struct gomp_device_descr));
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../repos/gcc/libgomp/target.c:3363:39: error: array subscript 
[-27450512014448737, 27450512014448737] is outside array bounds of ‘struct 
gomp_device_descr[0]’ [-Werror=array-bounds]
 3363 |       devices_s[num_devices_openmp++] = devices[i];
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
../../../repos/gcc/libgomp/target.c:3353:7: note: referencing an object of size 
0 allocated by ‘malloc’
 3353 |     = malloc (num_devices * sizeof (struct gomp_device_descr));
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter

Reply via email to