formatter: avoid crash on attribute instance in for-loop header - #2585
Open
EylonKrause wants to merge 1 commit into
Open
formatter: avoid crash on attribute instance in for-loop header#2585EylonKrause wants to merge 1 commit into
EylonKrause wants to merge 1 commit into
Conversation
TreeUnwrapper::ReshapeTokenPartitions' kForSpec case assumed the for-loop header always yields two semicolon-leading partitions and CHECK-failed (SIGABRT) otherwise. An attribute instance ((* ... *)) in the for-loop init/condition changes the partition structure so those partitions are absent, aborting the formatter on otherwise valid input, e.g.: module m; initial for(int i=0(* a *);i<4;i++) x=i; endmodule Replace the two CHECKs with graceful early-outs: when a required semicolon-leading partition is not found, leave the partitions unreshaped instead of aborting. Normal for-loops (both partitions present) reshape exactly as before. Adds a formatter regression test. Signed-off-by: Eylon Krause <eylon1909@gmail.com>
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.
Problem
verible-verilog-formataborts with aCHECKfailure (SIGABRT, exit 134)when an attribute instance
(* ... *)appears in a for-loop header.TreeUnwrapper::ReshapeTokenPartitions'kForSpeccase assumes the headeralways produces two semicolon-leading partitions:
When an attribute instance appears in the init/condition, the partition
structure differs and a semicolon-leading partition is missing, firing the
CHECK and aborting the process on otherwise valid input.
Minimal repro
Before this change both abort:
Fix
Replace the two unconditional
CHECKs with graceful early-outs: when arequired semicolon-leading partition is not found, leave the partitions
unreshaped instead of aborting. Normal for-loops (both partitions present)
reshape exactly as before.
After the change the same inputs format without aborting, e.g.:
Testing
bazel test -c opt //verible/verilog/formatting:tree-unwrapper_test //verible/verilog/formatting:formatter_test— both pass.for (int i=0; i<4; i++)) formats unchanged.Disclosure: this contribution was authored with an AI coding assistant (Claude) and reviewed before submission.