Skip to content

Commit

Permalink
Fix potential crash with bind directives targeting invalid nested mod…
Browse files Browse the repository at this point in the history
…ule declarations
  • Loading branch information
MikePopoloski committed Apr 7, 2024
1 parent 1071869 commit 3636b1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 5 additions & 5 deletions source/ast/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2209,11 +2209,11 @@ void Compilation::resolveDefParamsAndBinds() {
}
else {
auto def = c.getDefinition(*c.root, *entry.definitionTarget);
SLANG_ASSERT(def);

// const_cast is fine; we accessed the private data of the compilation
// through a public interface that added the const on top.
const_cast<DefinitionSymbol*>(def)->bindDirectives.push_back(entry.info);
if (def) {
// const_cast is fine; we accessed the private data of the compilation
// through a public interface that added the const on top.
const_cast<DefinitionSymbol*>(def)->bindDirectives.push_back(entry.info);
}
}
}
else {
Expand Down
16 changes: 15 additions & 1 deletion tests/unittests/ast/HierarchyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ TEST_CASE("Nested modules with infinite recursion regress") {
compilation.getAllDiagnostics();
}

TEST_CASE("Bind corner case crash regress") {
TEST_CASE("Bind corner case crash regress 1") {
auto tree = SyntaxTree::fromText(R"(
module AL i,bind d,i AL,i
)");
Expand All @@ -2355,6 +2355,20 @@ module AL i,bind d,i AL,i
compilation.getAllDiagnostics();
}

TEST_CASE("Bind corner case crash regress 2") {
auto tree = SyntaxTree::fromFileInMemory(R"(
begin
program p(a,endprogram bind p
)",
SyntaxTree::getDefaultSourceManager());

Compilation compilation;
compilation.addSyntaxTree(tree);

// Check that it doesn't crash.
compilation.getAllDiagnostics();
}

TEST_CASE("Nested modules with binds, parameterized, info task") {
auto tree = SyntaxTree::fromText(R"(
module m #(parameter P);
Expand Down

0 comments on commit 3636b1f

Please sign in to comment.