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

            Bug ID: 67254
           Summary: On-stack memory regions with aligned attribute overlap
                    on ARM
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gmarkhor at gmail dot com
  Target Milestone: ---

Consider the following program:

#include <stdio.h>
#include <stdint.h>

int main() {
  uint16_t data[] __attribute__ ((aligned (32))) = {
      12288, 16777, 18103, 49820, 17421, 18573, 18420, 49771, 24528,
      12288, 12288, 12288, 12288, 64512, 31744, 32256, 2, 32785, 168,
      32768, 0, 0, 0, 0, 0, 0, 32768, 0, 0, 0, 0, 0, 0, 12288 };
  float reference[] __attribute__ ((aligned (32))) = {
      0.125, 2.76757812, 6.71484375, -3.3046875, 4.05078125, 9.1015625,
      7.953125, -3.20898438, 500.066406, 0.125, 0.125, 0.125, 0.125,
      -0, 0, 0, 0.0000001, -0.000001,
      0.00001, -0, 0, 0, 0, 0, 0, 0, -0, 0, 0, 0, 0, 0, 0, 0.125 };
  int data_length = sizeof(data) / sizeof(data[0]);
  printf("data: %p <-> %p\n", &data[0], &data[data_length - 1]);
  printf("reference: %p <-> %p\n", &reference[0], &reference[sizeof(reference)
/ sizeof(reference[0]) - 1]);
  if ((void*)(data + data_length - 1) >= (void*)(&reference[0])) {
    printf("overlap!\n");
  }
  return 0;
}

I compile it and run on armv7 development board. It prints something like

data: 0xbea7f500 <-> 0xbea7f542
reference: 0xbea7f460 <-> 0xbea7f4e4
overlap!

In other words, memory allocated for data and reference overlap.

I checked it on gcc 4.8.2 and gcc 5.1.0. It works as expected on x86_64.

Reply via email to