MikePopoloski / slang

SystemVerilog compiler and language services
MIT License
592 stars 132 forks source link

Missing `endif not caught in included file #876

Closed abradd closed 7 months ago

abradd commented 8 months ago

Describe the bug

With the following code in file slang_test.sv:

`ifdef __slang__
`define SBY(x) 1
`else
`define SBY(x) x
`endif

module m;

  `ifdef FORMAL
    `include "slang_include.sv"
  `endif

endmodule

where slang_include.sv is given by:

`ifdef __slang__
`define TEST(x) 1
`else
`define TEST(x) x
`endif

Removing the `endif from slang_include.sv reports no errors. Removing either `endif in slang_test.sv will report an error for the missing `endif directive.

To Reproduce

Create the two files above and run:

slang -Weverything slang_test.sv
jrudess commented 8 months ago

Because +define+FORMAL is not on the slang command line, the pre-processor completely removes all code within the `ifdef FORMAL, so compile can't flag the error because the code doesn't exist now.

MikePopoloski commented 8 months ago

Yes, that's right. slang won't even try to open the include file here so it doesn't matter what you put into it.

abradd commented 8 months ago

Because +define+FORMAL is not on the slang command line

Sorry about that, I was testing with and without -DFORMAL, but it seems I posted the one without.

If I run:

slang -Weverything -DFORMAL slang_test.sv

after removing the `endif from slang_include.sv I still don't see an error. Is there something else I'm missing?

MikePopoloski commented 8 months ago

Ok yeah, looks like there's still a bug here, specifically with include files.

MikePopoloski commented 7 months ago

Fixed in 918f4f44a81b5e5aab56e09caf89a4c5a2ec7697