public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114597] New: [GCC-14] Miscompilation of pointer assignment with inline assembly
@ 2024-04-05  3:42 141242068 at smail dot nju.edu.cn
  2024-04-05  3:52 ` [Bug c/114597] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: 141242068 at smail dot nju.edu.cn @ 2024-04-05  3:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114597
           Summary: [GCC-14] Miscompilation of pointer assignment with
                    inline assembly
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 141242068 at smail dot nju.edu.cn
  Target Milestone: ---

Compiler Explorer: https://gcc.godbolt.org/z/Pn4EG3zzj

```
struct node { void *p; } n;
struct head { struct node *n; } h;

int main () {
  n.p = &h;
  asm("":"=m"(n.p):"r"(n.p));
  if (n.p != &h)
    __builtin_abort();
  return 0;
}
```

I sanitized this program with all sanitizers I know, they report nothing.
When compile this program with `gcc-14 -O2`, the compiled program aborts, while
`-O0` normally exits.

Any potential undefined behavior:
1. strict aliasing, I added option `-fno-strict-aliasing` to `-O2`, the abort
still exists.
2. If there is some other undefined behavior unknown to me cause this
compilation inconsistency, please let me know.

Regarding the inline assembly, it's important to note that even though `n.p` is
specified as an output operand with `=m`, this doesn't necessarily imply that
`n.p` will be altered. The inline assembly might simply reassign the original
value to `n.p`, leaving it effectively unchanged.

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

end of thread, other threads:[~2024-04-05  7:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05  3:42 [Bug c/114597] New: [GCC-14] Miscompilation of pointer assignment with inline assembly 141242068 at smail dot nju.edu.cn
2024-04-05  3:52 ` [Bug c/114597] " pinskia at gcc dot gnu.org
2024-04-05  3:54 ` pinskia at gcc dot gnu.org
2024-04-05  4:10 ` 141242068 at smail dot nju.edu.cn
2024-04-05  6:03 ` xry111 at gcc dot gnu.org
2024-04-05  7:57 ` 141242068 at smail dot nju.edu.cn

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).