https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120780

--- Comment #11 from Siddhesh Poyarekar <siddhesh at gcc dot gnu.org> ---
OK, so we don't really need a FAM based reproducer either, here's one without
it.  FAM just makes this case more likely because due to it, __bdos succeeds
more often in the kernel code:

typedef __SIZE_TYPE__ size_t;

struct inner
{
  int dummy;
};

struct container
{ 
  int mcast_rate[6];
  struct inner mesh;
};

extern void __warn (void)
     __attribute__ ((__warning__ ("__builtin_dynamic_object_size failed")));

static void
child (struct inner *ifmsh)
{ 
  struct container *sdata =
    (struct container *) ((void *) ifmsh
                          - __builtin_offsetof (struct container, mesh));

  if (__builtin_dynamic_object_size(sdata->mcast_rate, 1) 
      != sizeof (sdata->mcast_rate))
    __warn ();
}

int
parent (size_t sz)
{ 
  struct container *sdata = __builtin_malloc (sz);
  struct inner *ifmsh = &sdata->mesh;
  child (ifmsh);
} 

$ gcc/cc1 -fdump-tree-objsz-details -std=gnu17 -quiet -O2 -o /dev/null -Werror
../cfg-min.c
In function ‘child’,
    inlined from ‘parent’ at ../cfg-min.c:34:3:
../cfg-min.c:26:5: error: call to ‘__warn’ declared with attribute warning:
__builtin_dynamic_object_size failed [-Werror=attribute-warning]
   26 |     __warn ();
      |     ^~~~~~~~~
cc1: all warnings being treated as errors

Reply via email to