Build problem with latest GCC (auto-load.c fails to compile)

Pedro Alves palves@redhat.com
Thu Dec 22 16:04:00 GMT 2016


On 12/21/2016 09:15 PM, Steve Ellcey wrote:
> Has anyone tried building gdb with the latest (top-of-tree) GCC sources?
> I just did that and the build died with message shown below.

I don't see the warning/error here, with ToT GCC.

> 
> 
> 
> ../../../src/binutils-gdb/gdb/auto-load.c: In function ‘void print_scripts(VEC_loaded_script_ptr*)’:
> ../../../src/binutils-gdb/gdb/auto-load.c:1317:52: error: argument 1 null where non-null expected [-Werror=nonnull]
>    sizeof (loaded_script_ptr), sort_scripts_by_name);
>                                                     ^


That's:

static void
print_scripts (VEC (loaded_script_ptr) *scripts)
{
  int i;
  loaded_script_ptr script;

  qsort (VEC_address (loaded_script_ptr, scripts),
	 VEC_length (loaded_script_ptr, scripts),
	 sizeof (loaded_script_ptr), sort_scripts_by_name);
  for (i = 0; VEC_iterate (loaded_script_ptr, scripts, i, script); ++i)
    print_script (script);
}

By design, a NULL VEC pointer is an empty VEC (though empty VECs can
be non-NULL if memory has already been reserved).  And VEC_address
returns NULL on such NULL VECs.

So sounds like GCC thinks that "scripts" here may be NULL
somehow?    I'm not immediately seeing how, given:

  script_files = VEC_alloc (loaded_script_ptr, 10);
  script_texts = VEC_alloc (loaded_script_ptr, 10);

Might be a GCC bug.  There's ongoing discussion on the gcc-patches
list about these -Wnonnull warnings.

Calling qsort with a null base is undefined, even if nmemb is 0.  So
fix could be simply to skip the qsort if the VEC is
empty (or len <= 1, since it's pointless to sort one element), like
we do in other places.  Something like:

static void
print_scripts (VEC (loaded_script_ptr) *scripts)
{
  int i;
  loaded_script_ptr script;

  if (VEC_length (int, ids) > 1)
    qsort (VEC_address (loaded_script_ptr, scripts),
	 VEC_length (loaded_script_ptr, scripts),
	 sizeof (loaded_script_ptr), sort_scripts_by_name);
  for (i = 0; VEC_iterate (loaded_script_ptr, scripts, i, script); ++i)
    print_script (script);
}

Thanks,
Pedro Alves



More information about the Gdb-patches mailing list