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.