Fix goto-instrument --dump-c parameter/local variable name collision#8804
Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
Open
Fix goto-instrument --dump-c parameter/local variable name collision#8804tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig wants to merge 1 commit intodiffblue:developfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8804 +/- ##
========================================
Coverage 80.00% 80.01%
========================================
Files 1700 1700
Lines 188271 188302 +31
Branches 73 73
========================================
+ Hits 150632 150661 +29
- Misses 37639 37641 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7189c10 to
61c99bf
Compare
There was a problem hiding this comment.
Pull request overview
Fixes goto-instrument --dump-c producing invalid C when a function parameter name collides with a local variable name, by renaming locals to a unique suffixed name.
Changes:
- Collect function parameter base-names before conversion to detect collisions.
- Rename local declarations on collision by updating the symbol’s
base_namewith a unique suffix. - Add a regression test that exercises parameter/local collisions under
--dump-c.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/goto-instrument/goto_program2code.h |
Adds state for tracking parameter names and used local names; declares build_param_names(). |
src/goto-instrument/goto_program2code.cpp |
Implements parameter name collection and local renaming on declaration when collisions are detected. |
regression/goto-instrument/dump-param-local-collision/test.desc |
Adds regression test driver for --dump-c collision case. |
regression/goto-instrument/dump-param-local-collision/main.c |
Test input containing parameter/local shadowing intended to trigger the dump-c renaming. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When goto-instrument --dump-c outputs C code, local variables that share a base name with a function parameter produce invalid C (redeclaration in the same scope). Collect parameter base names before conversion and rename any colliding local declarations by appending a unique suffix. Store func_name by value instead of by reference to avoid undefined behavior when a temporary irep_idt is passed at construction. Clear used_local_names at the start of each conversion run so that stale entries do not cause unnecessary renaming. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
61c99bf to
3258237
Compare
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.
Local variables are automatically renamed with a unique suffix when a name collision is detected, producing valid compilable C code.
Co-authored-by: Kiro autonomous agent
Fixes: #6268