From 73fd2fdc478a9460ea343f762a8be5689395b481 Mon Sep 17 00:00:00 2001 From: Stan Lee Date: Tue, 26 May 2026 22:47:03 -0700 Subject: [PATCH] warn for scopes --- kernel/fstdata.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/kernel/fstdata.cc b/kernel/fstdata.cc index 65abee311..92f12e480 100644 --- a/kernel/fstdata.cc +++ b/kernel/fstdata.cc @@ -168,7 +168,7 @@ void FstData::extractVarNames() std::string fst_scope_name; /* Variables for resolving unions with $fork. */ - bool in_fork = false; // if we are inside a $fork scope + bool detect_union = false; // if we should be detecting unions with $fork std::string fork_parent_scope; // parent scope of fork (used to resolve union location) std::string fork_name; // name of fork (used to resolve union name) std::vector fork_vars; // stores all variables in the fork scope @@ -177,18 +177,26 @@ void FstData::extractVarNames() switch (h->htyp) { case FST_HT_SCOPE: { // Handle tracking for potential union structs with $fork. - if (!in_fork && h->u.scope.typ == FST_ST_VCD_FORK) { - in_fork = true; + if (!detect_union && h->u.scope.typ == FST_ST_VCD_FORK) { + detect_union = true; fork_parent_scope = fst_scope_name; fork_name = h->u.scope.name; fork_vars.clear(); + } else if (in_fork && h->u.scope.typ == FST_ST_VCD_STRUCT) { + // Signal that a nested $fork can not be a candidate for union struct detection. + log_warning("Nested $fork '%s' inside $fork '%s'; " + "abandoning union detection for this scope...\n", + h->u.scope.name, fork_name.c_str()); + for (auto &v : fork_vars) registerVar(v); + detect_union = false; + fork_vars.clear(); } // Push the scope onto the stack to 'descend' into the hierarchy. fst_scope_name = fstReaderPushScope(ctx, h->u.scope.name, NULL); break; } case FST_HT_UPSCOPE: { - if (in_fork) { + if (detect_union) { // A union is detected if there are at least 2 variables in the fork scope and they all have the same fstHandle. bool is_union = fork_vars.size() >= 2 && std::all_of(fork_vars.begin() + 1, fork_vars.end(), @@ -207,7 +215,7 @@ void FstData::extractVarNames() registerVar(v); } } - in_fork = false; + detect_union = false; fork_vars.clear(); } // Pop the scope off the stack. @@ -224,7 +232,7 @@ void FstData::extractVarNames() normalize_brackets(var.scope); var.width = h->u.var.length; - if (in_fork) fork_vars.push_back(var); // store all variables in fork scope into a vector + if (detect_union) fork_vars.push_back(var); // store all variables in fork scope into a vector else registerVar(var); // otherwise, register the variable as normal break; }