fix(instrument): SelectorExpr in IncDecStmt now instrumented (#30)#31
Merged
Conversation
Fixed Issue #30: s.x++ was not instrumented because shouldInstrument() skips all SelectorExpr to avoid method calls/package functions. Root cause: In visitSelectorInModifyContext(), we recorded Node as the SelectorExpr itself. But findParentStatement() then returned the outermost containing statement (BlockStmt), not the IncDecStmt. This caused stmtToPoints lookup to fail during instrumentation. Solution: Pass the parent statement (IncDecStmt) to visitSelectorInModifyContext() and use it as Node. This ensures findParentStatement() returns the correct statement for insertion. Technical details: - visitSelectorInModifyContext(parentStmt, expr) now takes parent stmt - Node field uses parentStmt instead of SelectorExpr - findParentStatement() returns statement directly (already a Stmt) Example (before): func update(s *S) { s.x++ } // No instrumentation! Example (after): func update(s *S) { race.RaceRead(uintptr(unsafe.Pointer(&s.x))) race.RaceWrite(uintptr(unsafe.Pointer(&s.x))) s.x++ } Tests: Added TestInstrumentFile_SelectorExprIncDec and TestInstrumentFile_SelectorExprInGoroutine for Issue #30 coverage. Reported-by: @thepudds Fixes: #30
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #31 +/- ##
==========================================
+ Coverage 69.45% 69.67% +0.22%
==========================================
Files 28 28
Lines 2933 2955 +22
==========================================
+ Hits 2037 2059 +22
Misses 777 777
Partials 119 119
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
- Update version to v0.8.3 (STABLE) - Add v0.8.2 section (Issue #27: *ptr++ fix by @thepudds) - Add v0.8.3 section (Issue #30: s.x++ fix by @thepudds) - Document known limitation with compiler directives (Issue #31) - Update version history with all v0.8.x releases - Credit @thepudds for community contributions
kolkov
added a commit
that referenced
this pull request
Dec 19, 2025
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.
Summary
Fixes #30:
s.x++was not being instrumented becauseshouldInstrument()skips allSelectorExprto avoid method calls/package functions.Root cause: In
visitSelectorInModifyContext(), we recordedNode: expr(SelectorExpr), butfindParentStatement()then returned the outermost containing statement (BlockStmt) instead of the IncDecStmt. This caused the instrumentation lookup to fail during code generation.Solution: Pass the parent statement (IncDecStmt) to
visitSelectorInModifyContext()and use it asNode. This ensuresfindParentStatement()returns the correct statement for insertion.Changes
visitSelectorInModifyContext(parentStmt, expr)to accept parent statementparentStmtasNodesofindParentStatement()returns correct statementTestInstrumentFile_SelectorExprIncDectest caseTestInstrumentFile_SelectorExprInGoroutinefor full reproductionBefore/After
Before fix:
After fix:
Test plan
TestInstrumentFile_SelectorExprIncDecpassesTestInstrumentFile_SelectorExprInGoroutinepassespre-release-check.shpasses with 0 errorsAcknowledgments
Thanks to @thepudds for finding this critical bug in Issue #27 comments.