Skip to content

Fix goto-instrument --dump-c parameter/local variable name collision#8804

Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:fix-6268-dump-c-name-clash
Open

Fix goto-instrument --dump-c parameter/local variable name collision#8804
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:fix-6268-dump-c-name-clash

Conversation

@tautschnig
Copy link
Collaborator

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

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.01%. Comparing base (7ff43f7) to head (3258237).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tautschnig tautschnig force-pushed the fix-6268-dump-c-name-clash branch from 7189c10 to 61c99bf Compare December 9, 2025 14:48
@tautschnig tautschnig self-assigned this Feb 24, 2026
@tautschnig tautschnig marked this pull request as ready for review March 4, 2026 14:30
Copilot AI review requested due to automatic review settings March 4, 2026 14:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_name with 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>
@tautschnig tautschnig force-pushed the fix-6268-dump-c-name-clash branch from 61c99bf to 3258237 Compare March 4, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

goto-instrument --dump-c still produces invalid code when parameter name overlaps with local variable name

4 participants