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

            Bug ID: 89799
           Summary: no warning declaring an misaligned array of
                    overaligned structs
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Attribute warn_if_not_aligned is documented like so:

    This attribute specifies a threshold for the structure field, measured in
bytes. If the structure field is aligned below the threshold, a warning will be
issued.

The test case below shows that the attributed does not have the documented
effect when an object of a type of a struct with an overaligned member is
defined with a less restrictive alignment.

$ cat z.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout  z.c
#define ALIGN(N) __attribute__ ((aligned (N), warn_if_not_aligned (N)))

struct ALIGN (64) S { ALIGN (64) char a[64]; };

struct S __attribute__ ((aligned (8))) s;   // unaligned, missing warning

int f (void) { return __alignof__ (s); }


typedef struct S __attribute__ ((aligned (8))) A[1];   // unaligned, missing
warning

A a;   // unaligned, missing warning

int g (void) { return __alignof__ (a); }
int h (void) { return __alignof__ (a[0]); }

;; Function f (f, funcdef_no=0, decl_uid=1909, cgraph_uid=1, symbol_order=1)

f ()
{
  <bb 2> [local count: 1073741824]:
  return 8;

}



;; Function g (g, funcdef_no=4, decl_uid=1914, cgraph_uid=2, symbol_order=3)

g ()
{
  <bb 2> [local count: 1073741824]:
  return 8;

}



;; Function h (h, funcdef_no=2, decl_uid=1917, cgraph_uid=3, symbol_order=4)

h ()
{
  <bb 2> [local count: 1073741824]:
  return 64;

}

Reply via email to