Skip to content

Fix memmove()#16

Open
zturtleman wants to merge 1 commit into
drh:masterfrom
zturtleman:memmove
Open

Fix memmove()#16
zturtleman wants to merge 1 commit into
drh:masterfrom
zturtleman:memmove

Conversation

@zturtleman
Copy link
Copy Markdown

[The lcc source] overrides the libc memmove() with its own implementation,
but that implementation fails to follow the specification. In particular,
it returns NULL rather than memmove()'s first parameter.

GCC now optimizes based on this aspect of the specification, so things go
wrong at runtime.

[Text & patch from http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56881#c8]

[The lcc source] overrides the libc memmove() with its own implementation,
but that implementation fails to follow the specification. In particular,
it returns NULL rather than memmove()'s first parameter.

GCC now optimizes based on this aspect of the specification, so things go
wrong at runtime.

[Text & patch from http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56881#c8]
ibara pushed a commit to ibara/LiteBSD-Ports that referenced this pull request Feb 23, 2016
AJBats added a commit to AJBats/saturncc that referenced this pull request Apr 18, 2026
Archive the sanitize-phase checklist as TODO_sanitize.md (history
intact via git mv) and create a fresh TODO.md scoped to tier-1
byte-match. Starting state: 1 byte-identical (drh#8), 2 pinned with
non-zero baselines (drh#16=438, #179=26), 6 Gap 18 skips, 187 unmeasured.
Workflow points at asmdiff.sh for review, validate_byte_match.sh pin
for gating, and flags Gap 15 void-sanitized functions (#135/#136/#183/#188)
for r0:r1 return-convention reconstruction.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
AJBats added a commit to AJBats/saturncc that referenced this pull request Apr 25, 2026
sh_fill_branch_delays would chain-walk a delay-slot instruction OUT of
an earlier branch's slot to fill a later one.  When the killed line was
the only thing between two branches, the lexical neighbour after the
emitted-stream collapse silently slid into the now-vacated slot — and
when that neighbour was itself a branch, we shipped a `bra` (or other
branch) literally inside a `jsr` delay slot.  That's forbidden by the
SH7604 spec ("any branch, MOVA, or TRAPA in a delay slot is illegal").
HEAD's checked-in FUN_06040EA0.s line 60 was a concrete example.

Guard: before accepting candidate k, walk back one non-empty line; if
that's a branch, k is in its delay slot — refuse.

Two effects:

  1. IPA Phase E.1b regtest now passes end-to-end.  The synthesized
     `add drh#16, r4` lands in jsr 1's delay slot (executed before the
     branch fires, so both helpers see r4 = p1+16); the chain-walk
     used to displace it past both calls into dead-code territory.
     Also fixes an awk bug in the regtest itself: the prior pattern
     `flag; /^_[a-zA-Z]/{if(seen)exit; seen=1}` exited at the FIRST
     `_<letter>:` label (which is `_helper_a:`, drained before
     `_caller:` in source order), so caller_body was always empty and
     the test always failed regardless of compiler output.

  2. Cleans up illegal-SH-2 emissions across the corpus.  Net byte-
     match impact: 4 functions improved (FUN_06040EA0 standalone +
     FUN_06045378, FUN_060477FC, FUN_06047A08 in TU), 17 functions
     drift +1 to +4 bytes (all in functions already 22..1024 bytes
     off prod — line-shift noise, none breaking byte-match).  The
     improvements include cases where the chain-walk's illegal output
     was the only thing keeping us from matching prod's spec-correct
     sequencing.

No previously byte-matched (diff=0) function regressed.  The IPA
mechanism itself is unchanged — this is a pre-existing filler bug
that the IPA test happened to surface because the synthesized add is
exactly the kind of instruction the chain-walk likes to grab.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant