Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure EoL at the end of trivia to prevent inlining issues #916

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/parsing/Preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ Token Preprocessor::nextRaw() {
}
}

// Ensure EoL at the end of trivia to prevent inlining issues
if (trivia.empty() || trivia.back().kind != TriviaKind::EndOfLine)
trivia.push_back(Trivia(TriviaKind::EndOfLine, ""sv));

// finally found a real token to return, so update trivia and get out of here
return token.withTrivia(alloc, trivia.copy(alloc));
}
Expand Down
13 changes: 13 additions & 0 deletions tests/unittests/DriverTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ TEST_CASE("Driver single-unit parsing") {
CHECK(driver.reportParseDiags());
}

TEST_CASE("Driver single-unit parsing files with no EOL") {
Driver driver;
driver.addStandardArgs();

auto args = fmt::format("testfoo \"{0}file_with_no_eol.sv\" "
"\"{0}file_uses_define_in_file_with_no_eol.sv\" --single-unit",
findTestDir());
CHECK(driver.parseCommandLine(args));
CHECK(driver.processOptions());
CHECK(driver.parseAllSources());
CHECK(driver.reportParseDiags());
}

TEST_CASE("Driver parsing with library modules") {
auto guard = OS::captureOutput();

Expand Down
5 changes: 5 additions & 0 deletions tests/unittests/data/file_uses_define_in_file_with_no_eol.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module main;
initial begin
$display("Something: %d", `SOMETHING);
end
endmodule
1 change: 1 addition & 0 deletions tests/unittests/data/file_with_no_eol.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`define SOMETHING 1337
Loading