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

            Bug ID: 66804
           Summary: Alignment issue caused by auto vectorization
           Product: gcc
           Version: 4.9.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.yang at huawei dot com
                CC: rguenther at suse dot de
  Target Milestone: ---
              Host: x86_64-SUSE-LINUX
            Target: x86_64
             Build: x86_64-SUSE-LINUX

testcase(test.c):

#pragma pack(1)
typedef struct
{
    unsigned char x[344];
} TEST1;

typedef struct
{
    unsigned int x[12];
    unsigned char y[2396];
    TEST1 u;
} TEST2;

typedef struct
{
    TEST2 v;
    unsigned char reserved[4];
} TEST3;
#pragma pack()

TEST3 xxx;

void foo ()
{
    TEST3 *q = &xxx;
    unsigned char **p;
    unsigned int i, len = 0;

    p = (unsigned char **)(void *)&q->v.u;
    len = sizeof (TEST1);

    for (i = 0; i < len; i += sizeof (unsigned char *))
      {
        *p = q->v.y;
        p++;
      }
}

int main ()
{
  foo ();
  return 0;
}

compile options: gcc -O2 test.c -ftree-loop-vectorize -fvect-cost-model
-fopt-info
test.c:32:5: note: loop vectorized
test.c:32:5: note: loop peeled for vectorization to enhance alignment
test.c:32:5: note: loop turned into non-loop; it never loops
test.c:23:6: note: loop turned into non-loop; it never loops
test.c:32:5: note: loop vectorized
test.c:32:5: note: loop peeled for vectorization to enhance alignment
test.c:32:5: note: loop turned into non-loop; it never loops
test.c:39:5: note: loop turned into non-loop; it never loops

The generated code will trigger a Segmentation Fault on x86_64-SUSE-Linux.

Reply via email to