CompileHelper: guard null typespec in defaultPatternAssignment pattern op#4114
Merged
alaindargelas merged 1 commit intoJul 14, 2026
Conversation
…n op
The vpiAssignmentPatternOp case of defaultPatternAssignment dereferenced ptps
(the tagged pattern's actual typespec) without a null check. ptps stays null
when the pattern has no typespec, which happens when an assignment-pattern
member key is a cast expression -- e.g. `s x = '{ int'(0): 1 };` -- because
compileTypespec returns null for the cast key, so pattern->Typespec() is never
set. Dereferencing ptps at `ptps->VpiName()` then segfaults during elaboration.
Add `if (ptps == nullptr) break;`, matching the sibling vpiCastOp case in the
same function; a cast-key pattern is left unmodified instead of crashing.
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
A struct/array assignment pattern whose member key is a cast expression segfaults during elaboration:
surelog -parse repro.sv→Segmentation fault.Root cause
In
CompileHelper::defaultPatternAssignment, thevpiAssignmentPatternOpcase dereferences a possibly-null typespec:ptpsstays null when the tagged pattern has no typespec. A'{key: value}member sets its typespec only whencompileTypespecsucceeds for the key; for a cast-expression key (int'(0),byte'(0),4'(0)),compileTypespecreturns null, sopattern->Typespec()is never set andptpsis null at the dereference.The sibling
vpiCastOpcase a few lines above guards the identicalTypespec() -> Actual_typespec()pattern withif (optps == nullptr) break;; thevpiAssignmentPatternOpcase is missing it.Fix
Add the same null guard before dereferencing
ptps:A cast-key pattern is then left unmodified instead of crashing.
Test
Not a
*_test.cppunit test (the crash is in a full-elaboration function); reproducible end-to-end with the 3-line module above (segfault before the fix, clean after).