Fix memmove()#16
Open
zturtleman wants to merge 1 commit into
Open
Conversation
[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
…he fix is obvious). From drh/lcc#16
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[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]