public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103255] New: [10 Regression] optimization breaks address of struct member
@ 2021-11-15 17:59 lipnitsk at gmail dot com
  2021-11-15 18:18 ` [Bug tree-optimization/103255] [11/12 " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: lipnitsk at gmail dot com @ 2021-11-15 17:59 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-11-29  9:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 17:59 [Bug c/103255] New: [10 Regression] optimization breaks address of struct member lipnitsk at gmail dot com
2021-11-15 18:18 ` [Bug tree-optimization/103255] [11/12 " pinskia at gcc dot gnu.org
2021-11-15 18:32 ` lipnitsk at gmail dot com
2021-11-16  8:21 ` [Bug tree-optimization/103255] [11/12 Regression] optimization breaks address of struct member since r11-4984-g47923622c663ffad marxin at gcc dot gnu.org
2021-11-16  9:34 ` rguenth at gcc dot gnu.org
2021-11-16  9:53 ` nbd at nbd dot name
2021-11-16 15:34 ` jakub at gcc dot gnu.org
2021-11-16 18:18 ` amacleod at redhat dot com
2021-11-17 12:46 ` cvs-commit at gcc dot gnu.org
2021-11-17 19:37 ` [Bug tree-optimization/103255] [11 " jakub at gcc dot gnu.org
2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
2021-11-29  9:07 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).