MikePopoloski / slang

SystemVerilog compiler and language services
MIT License
555 stars 121 forks source link

sigsegv for Diagnostics #451

Closed jrudess closed 2 years ago

jrudess commented 2 years ago

I'm seeing a diagnostic segfault on on the 325th error for a larger project (determined by playing around with --error-limit). The error doesn't print, so I can't easily create a minimal test-case.

Debug build assertion:

internal compiler error: Assertion 'location' failed
  in file slang/source/diagnostics/Diagnostics.cpp, line 77
  function: slang::Diagnostic& slang::Diagnostics::add(slang::DiagCode, slang::SourceLocation)

I've been unable to collect a useful backtrace with gdb. I think this may be the result of having such ancient software (SLES11.4).

Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module slang/build/bin/slang]
(gdb) run
Starting program: slang/build/bin/slang --error-limit=325  (... lots of -D, -I, files here ... )
Top level design unit:
     top

[New Thread 0x7ffff7fbb7820 (LWP 104817)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7fbb720 (LWP 1040817)]
(gdb) backtrace
#0  0x00000000005f3940

Do you have any recommendations on how to help narrow it down? I'm working on getting access to some SLES12 machines which have (slightly) newer software.

MikePopoloski commented 2 years ago

Any backtrace from gdb would tell you right away, so I would try to get that working. The assertion is because I require all issued diagnostics to have a valid location and for whatever reason one was issued with an empty location. That's a bug that should be fixed but more context needed to know where that's happening.

jrudess commented 2 years ago

Rebuilding with -gdwarf-2 resolved the backtrace collection. The redacted1.sv file only contains SV properties used by assertions elsewhere in the project.

To reproduce the segfault with the debug build, I commented out two assertions.

Diagnostics.cpp:77
MiscExpressions.cpp:814
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7fbb720 (LWP 169342)]
0x00000000005f3940 in slang::AssertionInstanceExpression::bindPort (symbol=@0xc21f488, range=
        {startLoc = {bufferName = {static npos = <optimized out>, _M_len = 48, _M_str = 0x9016990 "<redacted1>.sv"}, static NoLocation = <optimized out>, bufferID = 52284, charOf
fset = 16767}, endLoc = {bufferName = {static npos = <optimized out>, _M_len = 48, _M_str = 0x9016990 "<redacted1>.sv"}, static NoLocation = <optimized out>, bufferID = 52284, ch
arOffset = 16777}}, instanceCtx=@0x7fffffff1f10) at gcc/9.2.0/include/c++/9.2.0/bits/char_traits.h:318
318               return 0;

(gdb) backtrace
#0  0x00000000005f3940 in slang::AssertionInstanceExpression::bindPort (symbol=@0xc21f488, range=
        {startLoc = {bufferName = {static npos = <optimized out>, _M_len = 48, _M_str = 0x9016990 "<redacted1>.sv"}, static NoLocation = <optimized out>, bufferID = 52284, charOf
fset = 16767}, endLoc = {bufferName = {static npos = <optimized out>, _M_len = 48, _M_str = 0x9016990 "<redacted1>.sv"}, static NoLocation = <optimized out>, bufferID = 52284, ch
arOffset = 16777}}, instanceCtx=@0x7fffffff1f10) at gcc/9.2.0/include/c++/9.2.0/bits/char_traits.h:318
#1  0x00000000005cce34 in slang::Expression::bindLookupResult (compilation=@0x7fffffff5070, result=@0x7fffffff1b90, syntax=@0xaafc890, invocation=0x0, withClause=0x0, context=@0x7fffffff1f10)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#2  0x00000000005cc84d in slang::Expression::bindName (compilation=@0x7fffffff5070, syntax=@0xaafc890, invocation=0x0, withClause=0x0, context=@0x7fffffff1f10)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#3  0x00000000005cc105 in slang::Expression::create (compilation=@0x7fffffff5070, syntax=@0xaafc890, ctx=@0x7fffffff2190, extraFlags={static mask_value = <optimized out>, m_bits = 16}, assignmentTarget=0x0)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#4  0x00000000005d1966 in slang::Expression::selfDetermined (compilation=@0x7fffffff5070, syntax=@0xaafc890, context=@0x7fffffff2190, extraFlags={static mask_value = <optimized out>, m_bits = 16})
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#5  0x00000000005c7733 in slang::Expression::bind (syntax=@0xaafc890, context=@0x7fffffff2190, extraFlags={static mask_value = <optimized out>, m_bits = 16})
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#6  0x000000000068bb82 in slang::Builtins::BitsFunction::bindArgument (this=0xb74380, context=@0x7fffffff2240, syntax=@0xaafc890)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#7  0x00000000005a4d49 in slang::CallExpression::createSystemCall (compilation=@0x7fffffff5070, subroutine=@0xb74380, firstArg=0x0, syntax=0xaafc978, withClause=0x0, range=
        {startLoc = {bufferName = {static npos = <optimized out>, _M_len = 48, _M_str = 0x9016990 "<redacted1>.sv"}, static NoLocation = <optimized out>, bufferID = 52284, charOf
fset = 16761}, endLoc = {bufferName = {static npos = <optimized out>, _M_len = 48, _M_str = 0x9016990 "<redacted1>.sv"}, static NoLocation = <optimized out>, bufferID = 52284, ch
arOffset = 16778}}, context=@0x7fffffff2f60, randomizeScope=0x0) at gcc/9.2.0/include/c++/9.2.0/bits/char_traits.h:318
#8  0x00000000005a228d in slang::CallExpression::fromLookup (compilation=@0x7fffffff5070, subroutine=@0x7fffffff2df0, thisClass=0x0, syntax=0xaafc978, withClause=0x0, range=
        {startLoc = {bufferName = {static npos = <optimized out>, _M_len = 48, _M_str = 0x9016990 "<redacted1>.sv"}, static NoLocation = <optimized out>, bufferID = 52284, charOf
fset = 16761}, endLoc = {bufferName = {static npos = <optimized out>, _M_len = 48, _M_str = 0x9016990 "<redacted1>.sv"}, static NoLocation = <optimized out>, bufferID = 52284, ch
arOffset = 16778}}, context=@0x7fffffff2f60) at gcc/9.2.0/include/c++/9.2.0/bits/char_traits.h:318
#9  0x00000000005cc80c in slang::Expression::bindName (compilation=@0x7fffffff5070, syntax=@0xaafc810, invocation=0xaafc978, withClause=0x0, context=@0x7fffffff2f60)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#10 0x00000000005a21a7 in slang::CallExpression::fromSyntaxImpl (compilation=@0x7fffffff5070, left=@0xaafc810, invocation=0xaafc978, withClause=0x0, context=@0x7fffffff2f60)
    at gcc/9.2.0/include/c++/9.2.0/bits/char_traits.h:318
#11 0x00000000005a1f7a in slang::CallExpression::fromSyntax (compilation=@0x7fffffff5070, syntax=@0xaafc978, withClause=0x0, context=@0x7fffffff2f60)
    at gcc/9.2.0/include/c++/9.2.0/bits/char_traits.h:318
#12 0x00000000005cbbc2 in slang::Expression::create (compilation=@0x7fffffff5070, syntax=@0xaafc978, ctx=@0x7fffffff3200, extraFlags={static mask_value = <optimized out>, m_bits = 0}, assignmentTarget=0x0)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#13 0x0000000000600892 in slang::BinaryExpression::fromSyntax (compilation=@0x7fffffff5070, syntax=@0xaafca58, context=@0x7fffffff3200)
    at gcc/9.2.0/include/c++/9.2.0/bits/char_traits.h:318
#14 0x00000000005cbb55 in slang::Expression::create (compilation=@0x7fffffff5070, syntax=@0xaafca58, ctx=@0x7fffffff3480, extraFlags={static mask_value = <optimized out>, m_bits = 0}, assignmentTarget=0x0)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#15 0x00000000005d1966 in slang::Expression::selfDetermined (compilation=@0x7fffffff5070, syntax=@0xaafca58, context=@0x7fffffff3480, extraFlags={static mask_value = <optimized out>, m_bits = 0})
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#16 0x00000000005c7733 in slang::Expression::bind (syntax=@0xaafca58, context=@0x7fffffff3480, extraFlags={static mask_value = <optimized out>, m_bits = 0})
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#17 0x00000000005c25d8 in slang::BindContext::evalInteger (this=0x7fffffff3900, syntax=@0xaafca58, extraFlags={static mask_value = <optimized out>, m_bits = 0})
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#18 0x00000000005c3460 in slang::BindContext::evalRangeDimension (this=0x7fffffff3900, syntax=@0xaafcb28, isPacked=true, result=@0x7fffffff37f0)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#19 0x00000000005c2afe in slang::BindContext::evalDimension (this=0x7fffffff3900, syntax=@0xaafcb70, requireRange=true, isPacked=true)
    at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#20 0x00000000005c2da1 in slang::BindContext::evalPackedDimension (this=0x7fffffff3900, syntax=@0xaafcb70) at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#21 0x0000000000554044 in slang::IntegralType::fromSyntax (compilation=@0x7fffffff5070, integerKind=245, dimensions={data_ = 0xaafcbe0, size_ = 1}, isSigned=false, location=
      {static max = <optimized out>, static min = <optimized out>, scope = 0xc21f398, index = 7}, scope=@0xc21f398) at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#22 0x0000000000554365 in slang::IntegralType::fromSyntax (compilation=@0x7fffffff5070, syntax=@0xaafcc40, location={static max = <optimized out>, static min = <optimized out>, scope = 0xc21f398, index = 7},
    scope=@0xc21f398) at gcc/9.2.0/include/c++/9.2.0/bits/stl_deque.h:95
#23 0x000000000057232b in slang::Type::fromSyntax (compilation=@0x7fffffff5070, node=@0xaafcc40, location={static max = <optimized out>, static min = <optimized out>, scope = 0xc21f398, index = 7},
    parent=@0xc21f398, typedefTarget=0x0) at gcc/9.2.0/include/c++/9.2.0/bits/char_traits.h:318
#24 0x0000000000458fb9 in slang::Compilation::getType (this=0x7fffffff5070, node=@0xaafcc40, location={static max = <optimized out>, static min = <optimized out>, scope = 0xc21f398, index = 7},
    parent=@0xc21f398, typedefTarget=0x0) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#25 0x0000000000560f82 in slang::DeclaredType::resolveType (this=0xc21f878, initializerContext=@0x7fffffff3d00)
#26 0x0000000000560aaf in slang::DeclaredType::getType (this=0xc21f878)
#27 0x0000000000486784 in slang::DiagnosticVisitor::handleDefault<slang::LocalAssertionVarSymbol> (this=0x7fffffff46e0, symbol=@0xc21f828)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#28 0x000000000047347d in slang::DiagnosticVisitor::handle<slang::LocalAssertionVarSymbol> (this=0x7fffffff46e0, symbol=@0xc21f828) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#29 0x0000000000466a1b in slang::ASTVisitor<slang::DiagnosticVisitor, false, false>::visit<slang::LocalAssertionVarSymbol> (this=0x7fffffff46e0, t=@0xc21f828)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#30 0x000000000045fe19 in _ZNK5slang6Symbol5visitIRNS_17DiagnosticVisitorEJEEEDcOT_DpOT0_ (this=0xc21f828, visitor=@0x7fffffff46e0) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#31 0x0000000000472b0d in slang::ASTVisitor<slang::DiagnosticVisitor, false, false>::visitDefault<slang::PropertySymbol> (this=0x7fffffff46e0, t=@0xc21f348)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#32 0x0000000000465e3a in slang::DiagnosticVisitor::handleDefault<slang::PropertySymbol> (this=0x7fffffff46e0, symbol=@0xc21f348) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#33 0x000000000045f6d9 in slang::DiagnosticVisitor::handle (this=0x7fffffff46e0, symbol=@0xc21f348) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#34 0x0000000000466983 in slang::ASTVisitor<slang::DiagnosticVisitor, false, false>::visit<slang::PropertySymbol> (this=0x7fffffff46e0, t=@0xc21f348)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#35 0x000000000045fda1 in _ZNK5slang6Symbol5visitIRNS_17DiagnosticVisitorEJEEEDcOT_DpOT0_ (this=0xc21f348, visitor=@0x7fffffff46e0) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#36 0x0000000000497a3f in slang::ASTVisitor<slang::DiagnosticVisitor, false, false>::visitDefault<slang::CompilationUnitSymbol> (this=0x7fffffff46e0, t=@0xa339080)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#37 0x00000000004849a8 in slang::DiagnosticVisitor::handleDefault<slang::CompilationUnitSymbol> (this=0x7fffffff46e0, symbol=@0xa339080)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#38 0x000000000047302f in slang::DiagnosticVisitor::handle<slang::CompilationUnitSymbol> (this=0x7fffffff46e0, symbol=@0xa339080) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#39 0x0000000000466347 in slang::ASTVisitor<slang::DiagnosticVisitor, false, false>::visit<slang::CompilationUnitSymbol> (this=0x7fffffff46e0, t=@0xa339080)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#40 0x000000000045f897 in _ZNK5slang6Symbol5visitIRNS_17DiagnosticVisitorEJEEEDcOT_DpOT0_ (this=0xa339080, visitor=@0x7fffffff46e0) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#41 0x000000000049799f in slang::ASTVisitor<slang::DiagnosticVisitor, false, false>::visitDefault<slang::RootSymbol> (this=0x7fffffff46e0, t=@0xb6dc50)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#42 0x00000000004848ae in slang::DiagnosticVisitor::handleDefault<slang::RootSymbol> (this=0x7fffffff46e0, symbol=@0xb6dc50) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#43 0x0000000000473009 in slang::DiagnosticVisitor::handle<slang::RootSymbol> (this=0x7fffffff46e0, symbol=@0xb6dc50) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#44 0x0000000000466321 in slang::ASTVisitor<slang::DiagnosticVisitor, false, false>::visit<slang::RootSymbol> (this=0x7fffffff46e0, t=@0xb6dc50)
    at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#45 0x000000000045f879 in _ZNK5slang6Symbol5visitIRNS_17DiagnosticVisitorEJEEEDcOT_DpOT0_ (this=0xb6dc50, visitor=@0x7fffffff46e0) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#46 0x0000000000457df3 in slang::Compilation::getSemanticDiagnostics (this=0x7fffffff5070) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#47 0x00000000004589bd in slang::Compilation::getAllDiagnostics (this=0x7fffffff5070) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#48 0x000000000040c5b4 in Compiler::run (this=0x7fffffff4db0) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#49 0x00000000004122bc in driverMain<char**> (argc=69, argv=0x7fffffff6778, suppressColorsStdout=false, suppressColorsStderr=false) at gcc/9.2.0/include/c++/9.2.0/typeinfo:100
#50 0x0000000000409c4a in main (argc=69, argv=0x7fffffff6778)
MikePopoloski commented 2 years ago

I think this is two separate issues here. The first assertion inside Diagnostic is telling us that a proper diagnostic was being issued but the code didn't provide a valid location for it. A backtrace on that assert should tell us which code has that bug.

The second assert in bindPort() is saying some internal logic is wrong whereby we managed to look up an assertion port without actually being in the middle of expanding an assertion, which shouldn't be possible. Commenting out that assert just ensures you'll crash because the context pointer is null. I think I need some example source code that led to this being hit.

jrudess commented 2 years ago

Sure thing. Will try to get a backtrace at the point of the first assertion and also see if I can minimize the code down.

jrudess commented 2 years ago

Here's a backtrace at the ASSERT just before it fires. May still not be too useful, but might help me narrow down where to find the SV-assertion that I believe is the root cause since parseIfGenerateConstruct is in the backtrace.

#0  slang::Diagnostics::add (this=0x7fffffff2950, code=..., location=...) at slang/source/diagnostics/Diagnostics.cpp:80
#1  0x000000000080b541 in slang::Lexer::addDiag (this=0x7fffffff26e0, code=..., offset=1) at slang/source/parsing/Lexer.cpp:1107
#2  0x0000000000809f59 in slang::Lexer::lexStringLiteral (this=0x7fffffff26e0) at slang/source/parsing/Lexer.cpp:630
#3  0x0000000000808be8 in slang::Lexer::lexToken (this=0x7fffffff26e0, keywordVersion=slang::KeywordVersion::v1800_2017) at slang/source/parsing/Lexer.cpp:232
#4  0x00000000008088f6 in slang::Lexer::lex (this=0x7fffffff26e0, keywordVersion=slang::KeywordVersion::v1800_2017) at slang/source/parsing/Lexer.cpp:185
#5  0x0000000000808020 in slang::Lexer::stringify (alloc=..., location=..., trivia=..., begin=0x7fffffff2e28, end=0x7fffffff2e28) at slang/source/parsing/Lexer.cpp:122
#6  0x000000000073c2a7 in slang::Preprocessor::applyMacroOps (this=0x7fffffff5a10, tokens=..., dest=...) at slang/source/parsing/Preprocessor_macros.cpp:235
#7  0x000000000073b5b6 in slang::Preprocessor::handleTopLevelMacro (this=0x7fffffff5a10, directive=...) at slang/source/parsing/Preprocessor_macros.cpp:80
#8  0x000000000072d7e2 in slang::Preprocessor::handleMacroUsage (this=0x7fffffff5a10, directive=...) at slang/source/parsing/Preprocessor.cpp:542
#9  0x000000000072b63d in slang::Preprocessor::handleDirectives (this=0x7fffffff5a10, token=...) at slang/source/parsing/Preprocessor.cpp:210
#10 0x000000000072b22a in slang::Preprocessor::nextProcessed (this=0x7fffffff5a10) at slang/source/parsing/Preprocessor.cpp:176
#11 0x00000000007312d6 in slang::Preprocessor::peek (this=0x7fffffff5a10) at slang/source/parsing/Preprocessor.cpp:1195
#12 0x0000000000731316 in slang::Preprocessor::consume (this=0x7fffffff5a10) at slang/source/parsing/Preprocessor.cpp:1200
#13 0x000000000072b1a6 in slang::Preprocessor::next (this=0x7fffffff5a10) at slang/source/parsing/Preprocessor.cpp:150
#14 0x0000000000728b76 in slang::ParserBase::Window::addNew (this=0x7fffffff5628) at slang/source/parsing/ParserBase.cpp:232
#15 0x0000000000727fe4 in slang::ParserBase::peek (this=0x7fffffff5620) at slang/source/parsing/ParserBase.cpp:55
#16 0x000000000070c873 in slang::Parser::parseMemberList<slang::MemberSyntax, slang::Parser::parseGenerateBlock()::<lambda(slang::SyntaxKind, bool&)> >(slang::TokenKind, slang::Token &, slang::SyntaxKind, slang::Parser::<lambda(slang::SyntaxKind, bool&)> &) (this=0x7fffffff5620, endKind=slang::TokenKind::EndKeyword, endToken=..., parentKind=slang::SyntaxKind::GenerateBlock, parseFunc=...)
    at slang/source/parsing/Parser_members.cpp:377
#17 0x00000000006fe381 in slang::Parser::parseGenerateBlock (this=0x7fffffff5620) at slang/source/parsing/Parser_members.cpp:844
#18 0x00000000006fda10 in slang::Parser::parseIfGenerateConstruct (this=0x7fffffff5620, attributes=...) at slang/source/parsing/Parser_members.cpp:757
#19 0x00000000006fa88a in slang::Parser::parseMember (this=0x7fffffff5620, parentKind=slang::SyntaxKind::GenerateRegion, anyLocalModules=@0x7fffffff45bf: false)
    at slang/source/parsing/Parser_members.cpp:235
#20 0x00000000006f9d1d in slang::Parser::<lambda(slang::SyntaxKind, bool&)>::operator()(slang::SyntaxKind, bool &) const (__closure=0x7fffffff47d8, parentKind=slang::SyntaxKind::GenerateRegion, 
    anyLocalModules=@0x7fffffff45bf: false) at slang/source/parsing/Parser_members.cpp:112
#21 0x000000000070b9a5 in slang::Parser::parseMemberList<slang::MemberSyntax, slang::Parser::parseMember(slang::SyntaxKind, bool&)::<lambda(slang::SyntaxKind, bool&)> >(slang::TokenKind, slang::Token &, slang::SyntaxKind, slang::Parser::<lambda(slang::SyntaxKind, bool&)> &) (this=0x7fffffff5620, endKind=slang::TokenKind::EndGenerateKeyword, endToken=..., parentKind=slang::SyntaxKind::GenerateRegion, parseFunc=...)
    at slang/source/parsing/Parser_members.cpp:381
#22 0x00000000006f9f11 in slang::Parser::parseMember (this=0x7fffffff5620, parentKind=slang::SyntaxKind::ModuleDeclaration, anyLocalModules=@0x7fffffff4c5f: false)
    at slang/source/parsing/Parser_members.cpp:113
#23 0x00000000006f995d in slang::Parser::<lambda(slang::SyntaxKind, bool&)>::operator()(slang::SyntaxKind, bool &) const (__closure=0x7fffffff4db8, parentKind=slang::SyntaxKind::ModuleDeclaration, 
    anyLocalModules=@0x7fffffff4c5f: false) at slang/source/parsing/Parser_members.cpp:64
#24 0x000000000070b799 in slang::Parser::parseMemberList<slang::MemberSyntax, slang::Parser::parseModule(slang::Parser::AttrList, slang::SyntaxKind, bool&)::<lambda(slang::SyntaxKind, bool&)> >(slang::TokenKind, slang::Token &, slang::SyntaxKind, slang::Parser::<lambda(slang::SyntaxKind, bool&)> &) (this=0x7fffffff5620, endKind=slang::TokenKind::EndModuleKeyword, endToken=..., 
    parentKind=slang::SyntaxKind::ModuleDeclaration, parseFunc=...) at slang/source/parsing/Parser_members.cpp:381
#25 0x00000000006f9b31 in slang::Parser::parseModule (this=0x7fffffff5620, attributes=..., parentKind=slang::SyntaxKind::CompilationUnit, anyLocalModules=@0x7fffffff543f: false)
    at slang/source/parsing/Parser_members.cpp:65
#26 0x00000000006fa0a6 in slang::Parser::parseMember (this=0x7fffffff5620, parentKind=slang::SyntaxKind::CompilationUnit, anyLocalModules=@0x7fffffff543f: false)
    at slang/source/parsing/Parser_members.cpp:134
#27 0x00000000006f97a5 in slang::Parser::<lambda(slang::SyntaxKind, bool&)>::operator()(slang::SyntaxKind, bool &) const (__closure=0x7fffffff5548, parentKind=slang::SyntaxKind::CompilationUnit, 
    anyLocalModules=@0x7fffffff543f: false) at slang/source/parsing/Parser_members.cpp:18
#28 0x000000000070b58d in slang::Parser::parseMemberList<slang::MemberSyntax, slang::Parser::parseCompilationUnit()::<lambda(slang::SyntaxKind, bool&)> >(slang::TokenKind, slang::Token &, slang::SyntaxKind, slang::Parser::<lambda(slang::SyntaxKind, bool&)> &) (this=0x7fffffff5620, endKind=slang::TokenKind::EndOfFile, endToken=..., parentKind=slang::SyntaxKind::CompilationUnit, parseFunc=...)
    at slang/source/parsing/Parser_members.cpp:381
#29 0x00000000006f97fa in slang::Parser::parseCompilationUnit (this=0x7fffffff5620) at slang/source/parsing/Parser_members.cpp:19
#30 0x0000000000805240 in slang::SyntaxTree::create (sourceManager=..., sources=..., options=..., guess=false) at slang/source/syntax/SyntaxTree.cpp:86
#31 0x0000000000804f08 in slang::SyntaxTree::fromBuffer (buffer=..., sourceManager=..., options=...) at slang/source/syntax/SyntaxTree.cpp:50
#32 0x0000000000408edc in loadAllSources (compilation=..., sourceManager=..., buffers=std::vector of length 5, capacity 8 = {...}, options=..., singleUnit=false, onlyLint=false, 
    libraryFiles=std::vector of length 0, capacity 0, libDirs=std::vector of length 0, capacity 0, libExts=std::vector of length 0, capacity 0)
    at slang/tools/driver/driver.cpp:129
#33 0x0000000000411fd2 in driverMain<char**> (argc=16, argv=0x7fffffff80a8, suppressColorsStdout=false, suppressColorsStderr=false) at slang/tools/driver/driver.cpp:690
#34 0x0000000000409c4a in main (argc=16, argv=0x7fffffff80a8) at slang/tools/driver/driver.cpp:809
jrudess commented 2 years ago

Minimized sigsegv example

`define default_clk 1'b0
property prop(a, b, c, d, clk=`default_clk, rst=1'b0);
    logic [$bits(b)-1:0] e;
    @(clk) disable iff(rst)
    (a, e = b) ##0
      (c or (!c ##1 (!a through d[->1])))
            |-> e == c);
endproperty: prop
MikePopoloski commented 2 years ago

Thanks, the sigsegv is easily reproducible with that snippet.

I have a general idea of what's causing that diagnostic assert -- something to do with stringifying via the preprocessor, but having a reproducer would be very helpful. If you have trouble tracking it down you can look at the backtrace when you hit that assert and try to find a SourceLocation object anywhere on the stack; in DEBUG builds that should contain the file name and byte offset of general area where the problem is happening.

jrudess commented 2 years ago

It turns out that the code-example from #455 is the reproducer for the first ASSERT. I hadn't noticed this because previously I was not running my test cases using a Debug build. I'll start primarily running with debug build going forward to help weed issues out.

MikePopoloski commented 2 years ago

The crash should be fixed as of a3c6a29f9fce359972838764cf6551c63bf473a7

MikePopoloski commented 2 years ago

I can't reproduce the assert with the code examples in #455 -- are you sure that's the reproducer?

jrudess commented 2 years ago

It looks like it might be gcc version dependent. On SLES11 using gcc 9.2.0 the example reproduces. On my home system using gcc 11.1.0 it doesn't.

EDIT: Installed gcc 8.4.0 on home system and it reproduced, so fortunately that removes libc as being the culprit.

MikePopoloski commented 2 years ago

Hmm, so I tried with gcc 8.4 locally (on Ubuntu 20.04) and haven't reproduced the issue. Just to confirm, the code that causes it is as follows?

`define MAKE_INST(NAME, SIG) \
    (* instance_name = `"inst_``NAME`" *) \
    mod \inst_``NAME (.sig(SIG));

module mod(input logic sig);
endmodule
module top;
    logic sig1, sig2;
    `MAKE_INST(A, sig1)
    `MAKE_INST(B, sig2)
endmodule
jrudess commented 2 years ago

Ack, sorry, I have found my mistake. The example in #455 passes because it has a slight syntax difference with continuations I was glossing over. Here is one that should fail and it's probably nothing to do with gcc versions. The only change is for the module name and signal list to be split out onto their own lines which is more common syntax when there are lots of signals.

`define MAKE_INST(NAME, SIG) \
    (* instance_name = `"\inst_``NAME`" *) \
    mod \inst_``NAME ( \
        .sig(SIG) \
    );

module mod(input logic sig);
endmodule
module top;
    logic sig1, sig2;
    `MAKE_INST(A, sig1)
    `MAKE_INST(B, sig2)
endmodule
MikePopoloski commented 2 years ago

Ok yeah, that reproduces it.

MikePopoloski commented 2 years ago

Assert should be fixed in cac1a4df9afc5dc46491ab03a179bfe88605b950