Skip to content

Commit

Permalink
Fix bad assignment for virtual interface element select by reversing …
Browse files Browse the repository at this point in the history
…the order of the selectors so that we encounter element select syntax first followed by member selectors. We can remove the reverse on the nameParts as a result (#1118)
  • Loading branch information
micron-ian authored Sep 15, 2024
1 parent 4e9b249 commit 1010137
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
11 changes: 4 additions & 7 deletions source/ast/Lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,12 +1340,14 @@ void Lookup::selectChild(const Type& virtualInterface, SourceRange range,
SmallVector<const ElementSelectSyntax*> elementSelects;
auto& comp = context.getCompilation();

for (auto& selector : selectors) {
for (auto& selector : std::views::reverse(selectors)) {
if (auto memberSel = std::get_if<LookupResult::MemberSelector>(&selector)) {
NamePlusLoc npl;
npl.dotLocation = memberSel->dotLocation;
npl.name.text = memberSel->name;
npl.name.range = memberSel->nameRange;
std::ranges::reverse(elementSelects); // reverse the element selects since we initially
// saw them in reverse order
npl.name.selectors = elementSelects.copy(comp);

nameParts.push_back(npl);
Expand All @@ -1356,13 +1358,8 @@ void Lookup::selectChild(const Type& virtualInterface, SourceRange range,
}
}

// lookupDownward expects names in reverse order...
SmallVector<NamePlusLoc, 4> namePartsReversed(nameParts.size(), UninitializedTag());
for (auto& npl : std::views::reverse(nameParts))
namePartsReversed.push_back(npl);

result.found = getVirtualInterfaceTarget(virtualInterface, context, range);
lookupDownward(namePartsReversed, unused, context, LookupFlags::None, result);
lookupDownward(nameParts, unused, context, LookupFlags::None, result);
}

const ClassType* Lookup::findClass(const NameSyntax& className, const ASTContext& context,
Expand Down
30 changes: 30 additions & 0 deletions tests/unittests/ast/TypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,3 +2214,33 @@ logic [-2147483648:-2147483649] a;
CHECK(diags[1].code == diag::SignedIntegerOverflow);
CHECK(diags[2].code == diag::SignedIntegerOverflow);
}

TEST_CASE("Virtual interface element select of member") {
auto tree = SyntaxTree::fromText(R"(
interface iface;
logic [255:0] data[2048];
logic [255:0] data_3d[2048][128][128];
endinterface
class cls1;
virtual iface vif;
endclass
class cls2;
cls1 c;
logic [255:0] data;
function set(int idx);
c.vif.data[idx] = data;
c.vif.data_3d[idx][64][8] = data;
c.vif.data_3d[idx][64][8][10:0] = data[10:0]; // index + range select
endfunction
endclass
module top;
endmodule
)");

Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

0 comments on commit 1010137

Please sign in to comment.