summaryrefslogtreecommitdiffstats
path: root/tests/bugs
diff options
context:
space:
mode:
authorTheresa Foley <10618364+tangent-vector@users.noreply.github.com>2025-04-24 14:19:45 -0700
committerGitHub <noreply@github.com>2025-04-25 00:19:45 +0300
commita4dc6247ade19eac03e0643d56f0877d39aaec6e (patch)
tree3dbb88077ec38ce3c16ef9ac688f351aea13a958 /tests/bugs
parent212d2f5978c514332783e3dd0355f207e9f1ba77 (diff)
Fix attempt to construct an abstract AST node (#6905)
Work on #6892 The function `tryInferLoopMaxIterations` in `slang-check-stmt.cpp` was doing: auto litExpr = m_astBuilder->create<LiteralExpr>(); but the declaration of `LiteralExpr` in `slang-ast-expr.h` had been marked as abstract, during the switch to using the `slang-fiddle` tool to generate code: FIDDLE(abstract) class LiteralExpr : public Expr { ... } In this case, the intention of the AST design is that `LiteralExpr` should be kept abstract, and only the concrete subclasses should ever be instantiated. Because of some historical design choices, the `ASTNodeType` enumeration includes both the concrete and abstract AST classes, so the code ended up constructing a `LiteralExpr` that had the tag `ASTNodeType::LiteralExpr`. Then attempts to use the `ASTNodeDispatcher` code on such a node caused crashes, because the dispatcher code only included `case` statements for the non-abstract `ASTNodeType`s. The quick fix here was to change the `tryInferLoopMaxIterations` function to instead do: auto litExpr = m_astBuilder->create<IntegerLiteralExpr>(); A test case was added to help catch any future regressions on this specific issue. A more long-term fix should involve introducing code that statically and/or dynamically prohibits the creation of instances of AST node classes that have been marked abstract.
Diffstat (limited to 'tests/bugs')
-rw-r--r--tests/bugs/serialization/gh-6892.slang9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/bugs/serialization/gh-6892.slang b/tests/bugs/serialization/gh-6892.slang
new file mode 100644
index 000000000..1235c292c
--- /dev/null
+++ b/tests/bugs/serialization/gh-6892.slang
@@ -0,0 +1,9 @@
+//TEST:COMPILE: tests/bugs/serialization/gh-6892.slang -o tests/bugs/serialization/gh-6892.slang-module
+
+// assertion failure when compiling to a slang module
+
+void f()
+{
+ for (int i = 0; i < 1; ++i)
+ ;
+}