Repository navigation
Conversation
Cerberus desugars ++E and --E to E += 1 and E -= 1. Since rems-project/cerberus@636b75880 the synthesized 1 carries the location of the whole ++E, so the store-op instrumentation took it for the right-hand operand of a compound assignment and emitted an edit whose end precedes its start. With ownership checking, any prefix increment or decrement then made `cn instrument` fail with Invalid_argument("Bytes.create") in Source_injection.move_to. The earlier path for an unlocated 1 (before that Cerberus change) did not work with give_parenthesis_aware_precedence_map either: its empty injections have no last character to look for a closing parenthesis in, so it failed with an index out of bounds (or reached its `assert false`). Handle both forms of a prefix operator the same way: replace the operator with "CN_STORE_OP(" and close the call after E. E's source, and the instrumentation of any loads inside it, stay in place, so --*p, ++a[i] and --q->x work as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zncxneLMKZJE5V7oqV7mo
Contributor
|
I might like to implement this fix on the Cerberus side instead of hacking around the positions any further (taking this opportunity to clean it up a bit). Once that's in place I'll close this PR. |
This branch has not been deployed
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.
This PR was prepared with Claude Code. I have reviewed it (but admit I do not understand the code fully).
With ownership checking on (the default),
cn instrumentfails on any prefix increment or decrement. Onmainthis minimal programgives
Cerberus desugars
++Eand--EtoE += 1andE -= 1. Since rems-project/cerberus@636b75880 (in the Cerberus pin since #701) the synthesized1has the location of the whole--E, so theStoreOpcase ofmemory_accesses_injectionstreats it as the right operand of a compound assignment and emits a,-,edit from the end ofEback to the start of--E. That edit runs backwards, andmove_toasksreally_input_stringfor a negative length. Before that Cerberus change, the1had no location and took the`Otherbranch added in #84. That branch does not work withgive_parenthesis_aware_precedence_mapeither: its empty injection strings have no last character, so instrumenting such a file failed with an index out of bounds there.This change handles both forms of a prefix operator the same way: the operator becomes
CN_STORE_OP(and the call is closed after the lvalue. The lvalue's source, and the instrumentation of any loads inside it, stay in place, so--*pbecomesCN_STORE_OP(*CN_LOAD(p),-,1), and++a[i]and--q->xwork too. Ordinary compound assignments are instrumented as before.The new test
tests/cn/prefix_increments.cis a prefix counterpart ofincrements.c. It covers prefix operators on locals, inside a condition and an assignment, and on*p,a[i]andq->x, with postconditions that check the results. It verifies, and runs undertests/run-cn-exec.sh. It crashedcn instrumentbefore this change.Testing:
tests/diff-prog.py cn tests/cn/verify.json(214 passed) andtests/run-cn-exec.sh(213 passed) pass, anddune build @fmtis clean. A prefix--on memory the function does not own now fails at run time with "Store failed", as a plain store does.Related: #80 (the same
Bytes.createcrash on++a, fixed then by #84) and rems-project/cerberus#807.