Bug 17450 - resolve_dynamic_type_internal misunderstands check_typedef -> internal error
Summary: resolve_dynamic_type_internal misunderstands check_typedef -> internal error
Status: RESOLVED DUPLICATE of bug 17642
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2014-10-01 17:57 UTC by dje
Modified: 2014-11-27 23:49 UTC (History)
1 user (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description dje 2014-10-01 17:57:24 UTC
Clang is emitting no bounds info for the "x" in
class c { char x[0]; char more_x[42]; };

This causes has_static_range for "x" to return false (lower bound is defaulted to zero, upper bound is unknown), which in turn causes is_dynamic_type to return true and we enter resolve_dynamic_type (which is just a wrapper on resolve_dynamic_type_internal).

In the example at hand (I don't have an easy to provide testcase, at least not yet), the type is defined in another CU so what resolve_dynamic_type gets is an opaque type.  We then hit this assert in resolve_dynamic_struct and crash:

  gdb_assert (TYPE_NFIELDS (type) > 0);

resolve_dynamic_type_internal seems to not understand that check_typedef has (at least) two main purposes:

1) check for typedefs (duh ... :-)),
2) AND resolve opaque types.

It's easy to understand this happening given how poorly named check_typedef is.

static struct type *
resolve_dynamic_type_internal (struct type *type, CORE_ADDR addr,
                               int top_level)
  struct type *real_type = check_typedef (type);
  struct type *resolved_type = type;
  const struct dynamic_prop *prop;
  CORE_ADDR value;

  if (!is_dynamic_type_internal (real_type, top_level))
    return type;

  switch (TYPE_CODE (type))


      resolved_type = resolve_dynamic_struct (type, addr);


Note that we've called check_typedef, BUT we're passing type to resolve_dynamic_struct not real_type.  If type is an opaque type we in fact do want to pass real_type to resolve_dynamic_struct.

Either that or call check_typedef again in resolve_dynamic_struct.  Since this collection of functions is all just implementation detail for resolve_dynamic_type I'm ok with not sprinkling calls to check_typedef everywhere it might be needed (and in fact since the function is so badly named sprinkling it about doesn't improve readability).  It would be reasonable to create a resolve_opaque_type function that handles this part of what check_typedef does, and use that instead, but I'm ok with just passing real_type to resolve_dynamic_struct here.
Comment 1 dje 2014-11-27 00:23:38 UTC
See also PR 17642
Comment 2 Jan Kratochvil 2014-11-27 23:09:13 UTC
I do not see how this is clang specific.

echo 'class c { char x[0]; char more_x[42]; };'|clang++ -c -g -o o.out -x c++ -
gdb ./o.out

does not crash for me.  IMO there have to be at least two CUs to make there the stub type but then it is PR 17642.

*** This bug has been marked as a duplicate of bug 17642 ***
Comment 3 dje 2014-11-27 23:49:52 UTC
Just because I report a bug I'm seeing with clang does not mean I'm claiming the bug is clang specific.