Conversation
try_fuse_sequence() reinterprets the leading bytes of rv_insn_t as an opcode_fuse_t via memcpy, which is only valid while both structures agree on the offset of every field the fused handlers read back. The existing asserts cover opcode_fuse_t alone, so a change to rv_insn_t could break the contract silently. Add cross-structure offset asserts for the whole shared prefix.
alanhc
force-pushed
the
rvv-static-assert
branch
from
September 10, 2026 23:13
cc0eed3 to
9b6058c
Compare
jserv
requested changes
Sep 14, 2026
jserv
left a comment
Contributor
There was a problem hiding this comment.
Avoid decode tag in the subject of both pull request and git commits.
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.
Addresses the third item of #735.
try_fuse_sequence()populates the fuse array withmemcpy(ir->fuse + j, next_ir, sizeof(opcode_fuse_t)), reinterpreting theleading bytes of
rv_insn_tas anopcode_fuse_t. That is only valid whileboth structures agree on the offset of every field the fused handlers read
back, but the existing
_Static_asserts indecode.hpin the layout ofopcode_fuse_talone. Nothing catches a change on therv_insn_tside.The issue mentions
opcode, but since the memcpy copies the whole 12-byteprefix, the contract covers
imm,rd,rs1,rs2andopcode, so thispins all five plus a size relation.
Note that
rv_insn_tgains members underEXT_C,EXT_VandEXT_F, sothe prefix layout is configuration-dependent; the asserts were checked with
EXT_Vboth enabled and disabled.Verified by inserting a layout-shifting member ahead of
opcode, which thenew assert rejects at compile time. Note that a
uint8_tinserted there isabsorbed by existing alignment padding and does not shift
opcode, so thenegative test needs a wider type.
make checkpasses; clang-format 20.1.7 clean.Summary by cubic
Pins the shared prefix layout between
rv_insn_tandopcode_fuse_tso thememcpyintry_fuse_sequence()can't silently corrupt fused sequences when the structs drift. Addresses the third item of #735.imm,rd,rs1,rs2, andopcodematch, plus a size check.Written for commit 9b6058c. Summary will update on new commits.