-
Notifications
You must be signed in to change notification settings - Fork 286
Fix goto-instrument --dump-c parameter/local variable name collision #8804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tautschnig
wants to merge
1
commit into
diffblue:develop
Choose a base branch
from
tautschnig:fix-6268-dump-c-name-clash
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
regression/goto-instrument/dump-param-local-collision/main.c
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Test case for parameter/local variable name collision in goto-instrument --dump-c | ||
| // This should generate valid C code with renamed local variables | ||
|
|
||
| int help(int x) | ||
| { | ||
| unsigned int x; // Should be renamed to x$1 in output | ||
| x = 42; | ||
| return (int)x; | ||
| } | ||
|
|
||
| int test_two_params(int y, int z) | ||
| { | ||
| int y; // Should be renamed to y$1 | ||
| int z; // Should be renamed to z$1 | ||
| y = 10; | ||
| z = 20; | ||
| return y + z; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| int result = help(1); | ||
| result += test_two_params(5, 6); | ||
| return result; | ||
| } |
19 changes: 19 additions & 0 deletions
19
regression/goto-instrument/dump-param-local-collision/test.desc
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| CORE | ||
| main.c | ||
| --dump-c | ||
| ^EXIT=0$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| ^warning: ignoring | ||
| -- | ||
| This test ensures that goto-instrument --dump-c produces valid C code when a | ||
| local variable has the same name as a function parameter. Previously, this | ||
| would generate invalid C code like: | ||
| int help(int x) { unsigned int x; } | ||
| which causes a compilation error. The fix renames the local variable to avoid | ||
| the collision, e.g.: | ||
| int help(int x) { unsigned int x$1; } | ||
|
|
||
| The generated C code should be valid and compilable. | ||
|
|
||
| Related to issue #6268 (similar to issue #6242 but for a different case). |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.