verilog: fix parser "if" memory errors. #5193
Merged
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.
Fix buggy memory allocation introduced in #5152:
ast_stack
to reflect AST node rearrangement when necessary, to avoid dangling pointer;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 aunique if
by replacing the currentAST_COND
/AST_DEFAULT
/AST_BLOCK
"else" construction with a newAST_COND
/(expr)/AST_BLOCK
within the originalAST_CASE
. However, it mistakenly left a dangling reference to the original (now orphaned) structure reachable viaast_stack
. This commit updates theast_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
andSANITIZER=address
. Thenmake test
(in particulartests/verilog/unique_if_enc.ys
) should succeed. (The test case in #5152 (comment) is a smaller example triggering the same logic.)