From 0e03ab2a57f8f40d30a49117d0d452f62a6f1e57 Mon Sep 17 00:00:00 2001 From: Matthew Ballance Date: Sat, 6 Dec 2025 15:08:51 -0800 Subject: [PATCH] Fix crash when super.new() called without a base class (#6772) --- src/V3LinkDot.cpp | 2 +- .../t/t_class_super_new_noextend_bad.out | 5 +++++ test_regress/t/t_class_super_new_noextend_bad.py | 16 ++++++++++++++++ test_regress/t/t_class_super_new_noextend_bad.v | 12 ++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test_regress/t/t_class_super_new_noextend_bad.out create mode 100755 test_regress/t/t_class_super_new_noextend_bad.py create mode 100644 test_regress/t/t_class_super_new_noextend_bad.v diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 9f5be7aee..9f2d1f111 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -4851,7 +4851,7 @@ class LinkDotResolveVisitor final : public VNVisitor { iterateChildren(nodep); if (isNew) { const AstClassExtends* const classExtendsp = VN_AS(m_modp, Class)->extendsp(); - if (m_explicitSuperNewp && !m_explicitSuperNewp->isImplicit() + if (m_explicitSuperNewp && !m_explicitSuperNewp->isImplicit() && classExtendsp && classExtendsp->argsp()) { m_explicitSuperNewp->v3error( "Explicit super.new not allowed with class " diff --git a/test_regress/t/t_class_super_new_noextend_bad.out b/test_regress/t/t_class_super_new_noextend_bad.out new file mode 100644 index 000000000..b41a37a55 --- /dev/null +++ b/test_regress/t/t_class_super_new_noextend_bad.out @@ -0,0 +1,5 @@ +%Error: t/t_class_super_new_noextend_bad.v:10:12: 'super' used on non-extended class (IEEE 1800-2023 8.15) + 10 | super.new(); + | ^ + ... See the manual at https://verilator.org/verilator_doc.html?v=latest for more assistance. +%Error: Exiting due to diff --git a/test_regress/t/t_class_super_new_noextend_bad.py b/test_regress/t/t_class_super_new_noextend_bad.py new file mode 100755 index 000000000..55203b6c9 --- /dev/null +++ b/test_regress/t/t_class_super_new_noextend_bad.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2025 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('linter') + +test.lint(fails=True, expect_filename=test.golden_filename) + +test.passes() diff --git a/test_regress/t/t_class_super_new_noextend_bad.v b/test_regress/t/t_class_super_new_noextend_bad.v new file mode 100644 index 000000000..2e41d3bdd --- /dev/null +++ b/test_regress/t/t_class_super_new_noextend_bad.v @@ -0,0 +1,12 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2025 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 +// + +class Cls; + function new(); + super.new(); // Bad - no extends + endfunction +endclass