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

            Bug ID: 109585
           Summary: Carla/sord miscompiled with -O2 on ARM64 (inlining
                    issue)
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hector at marcansoft dot com
  Target Milestone: ---

Created attachment 54900
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54900&action=edit
Manually annotated disassembly identifying the problem

GCC 12.1.0 miscompiles sord_free() with -O2 due to bad inlining on ARM64.
Reproducible on Compiler Explorer on 12.2 and also trunk.

https://godbolt.org/z/rvxP1oodh (includes full preprocessed input)

I've attached an annotated disassembly. The problem is that
zix_btree_iter_increment() and zix_btree_iter_is_end() are inlined together
into sord_free(), but the `i->stack[0].node == NULL` check in
zix_btree_iter_is_end() somehow got hoisted before the `f->node = NULL;` in
zix_btree_iter_increment(), so the check fails when it pass (ending the loop),
and then the loop body goes on to deref a NULL pointer.

Reply via email to