[Bug c/103255] New: [10 Regression] optimization breaks address of struct member
lipnitsk at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Nov 15 17:59:37 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103255
Bug ID: 103255
Summary: [10 Regression] optimization breaks address of struct
member
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: lipnitsk at gmail dot com
Target Milestone: ---
---CODE---
#include <stdio.h>
#include <stdint.h>
struct header {
uint32_t a;
uint32_t b;
uint32_t c;
};
int main(void)
{
struct header *hdr = NULL;
unsigned long ofs;
for (ofs = 0x20; ofs <= 0x20; ofs += 0x1000) {
struct header *tmp;
tmp = (struct header *)(0x555555558060 + ofs);
printf("a: 0x%08x", tmp->a);
if (tmp->a == 0) {
hdr = tmp;
break;
}
}
if (hdr == NULL)
return 0;
printf("found at %p %p %p\n", hdr, &hdr->b, &hdr->c);
return 0;
}
---END CODE---
After disabling ASLR and compiling with -Os (ensure that 0x555555558080 is
valid on your system, or just look at assembly output) I get:
a: 0x00000000found at 0x555555558080 0x555555558080 0x555555558080
This reproduces on trunk[0]
This reproduces on multiple targets, including MIPS and AARCH64[1]. This has
been linked to -ftree-vrp on AARCH64[2].
[0]: https://godbolt.org/z/KPor6qf34
[1]: https://github.com/openwrt/openwrt/pull/4732#issuecomment-968412881
[2]: https://github.com/openwrt/openwrt/pull/4732#issuecomment-968901545
More information about the Gcc-bugs
mailing list