chipsalliance / verible

Verible is a suite of SystemVerilog developer tools, including a parser, style-linter, formatter and language server
https://chipsalliance.github.io/verible/
Other
1.38k stars 214 forks source link

[assertion failed] Check failed: format_token.before.spaces >= 0 (-123 vs. 0) #255

Closed fangism closed 4 years ago

fangism commented 4 years ago

Reduced test case:

task S;
`ppgJH3JoxhwyTmZ2dgPiuMQzpRAWiSs(
 {xYtxuh6.FIMcVPEWfhtoI2FSe, xYtxuh6.ZVL5XASVGLYz32} == SqRgavM[15:2];
JgQLBG == 4'h0;,
"foo")
endtask

crashes the formatter with:

F0406 15:01:48.521232  132193 state_node.cc:354] Check failed: format_token.before.spaces >= 0 (-123 vs. 0) 
*** Check failure stack trace: ***
    @     0x55d84729defb  absl::logging_internal::LogMessage::DieIfFatal()
    @     0x55d84729d056  absl::logging_internal::LogMessage::SendToLog()
    @     0x55d84729cb3e  absl::logging_internal::LogMessage::Flush()
    @     0x55d84729eb09  absl::logging_internal::LogMessageFatal::~LogMessageFatal()
    @     0x55d847229a91  verible::StateNode::ReconstructFormatDecisions()
    @     0x55d847227155  verible::SearchLineWraps()
    @     0x55d847212d62  verilog::formatter::Formatter::Format()
    @     0x55d847211919  verilog::formatter::FormatVerilog()
    @     0x55d84720cdee  main
    @     0x7fc28522cbbd  __libc_start_main
    @     0x55d84720b869  _start

This was caused by recent handling of multi-line tokens in SearchLineWraps, and needs to be properly handled in ReconstructFormatDecisions().

Leading up to the crash (-v=4 --alsologtostderr):

---- line wrapping search state 6 ----
current cost: 15
current column: 23
I0406 16:05:17.990674  166995 line_wrap_searcher.cc:99] winning path cost: 15
I0406 16:05:17.990679  166995 line_wrap_searcher.cc:78] 
---- line wrapping search state 7 ----
current cost: 27
current column: 15
I0406 16:05:17.990686  166995 state_node.cc:343] reconstructing: )
I0406 16:05:17.990690  166995 state_node.cc:343] reconstructing: "foo"
I0406 16:05:17.990694  166995 state_node.cc:343] reconstructing: ,
I0406 16:05:17.990698  166995 state_node.cc:343] reconstructing: {xYtxuh6.FIMcVPEWfhtoI2FSe, xYtxuh6.ZVL5XASVGLYz32} == SqRgavM[15:2];
JgQLBG == 4'h0;
I0406 16:05:17.990703  166995 state_node.cc:352]   wrapped, with -70 leading spaces.

Diagnosis:

In ReconstructFormatDecisions() the trouble is here:

      format_token.before.spaces =
          reverse_iter->current_column - format_token.token->text.length();

use of text.length() is incorrect for multi-line tokens. this information alone is insufficient to determine the spaces that should go into format_token.before.spaces. (this is the bigger problem)

Fix coming.

fangism commented 4 years ago

b/153376023