Skip to content

verilog: fix parser "if" memory errors. #5193

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

Merged
merged 1 commit into from
Jun 23, 2025
Merged

Conversation

garytwong
Copy link
Contributor

Fix buggy memory allocation introduced in #5152:

  1. clean up ast_stack to reflect AST node rearrangement when necessary, to avoid dangling pointer;
  2. call free_attr() on unused attribute list when no new syntax node is created, to avoid leaking it.

What are the reasons/motivation for this change?
To fix the allocation bug discussed in #5152 and #5189.

This also assists #5180, which was blocked by this bug.

Explain how this is achieved.
Commit 370d587 handles an else if branch within a unique if by replacing the current AST_COND/AST_DEFAULT/AST_BLOCK "else" construction with a new AST_COND/(expr)/AST_BLOCK within the original AST_CASE. However, it mistakenly left a dangling reference to the original (now orphaned) structure reachable via ast_stack. This commit updates the ast_stack state to point to the replacement instead of the orphan.

If applicable, please suggest to reviewers how they can test the change.
Build with clang and SANITIZER=address. Then make test (in particular tests/verilog/unique_if_enc.ys) should succeed. (The test case in #5152 (comment) is a smaller example triggering the same logic.)

Fix buggy memory allocation introduced in YosysHQ#5152:

1) clean up ast_stack to reflect AST node rearrangement when necessary,
to avoid dangling pointer;
2) call free_attr() on unused attribute list when no new syntax node is
created, to avoid leaking it.
@garytwong garytwong requested a review from zachjs as a code owner June 23, 2025 03:17
@zachjs zachjs merged commit 34a2abe into YosysHQ:main Jun 23, 2025
25 checks passed
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.

2 participants