Skip to content

[flang] Don't insert spaces in -E output after line continuation #135063

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

Merged
merged 1 commit into from
Apr 10, 2025
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
34 changes: 18 additions & 16 deletions flang/lib/Parser/parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void Parsing::EmitPreprocessedSource(
const auto getOriginalChar{[&](char ch) {
if (IsLetter(ch) && provenance && provenance->size() == 1) {
if (const char *orig{allSources.GetSource(*provenance)}) {
const char upper{ToUpperCaseLetter(ch)};
char upper{ToUpperCaseLetter(ch)};
if (*orig == upper) {
return upper;
}
Expand Down Expand Up @@ -184,21 +184,23 @@ void Parsing::EmitPreprocessedSource(
std::optional<SourcePosition> position{provenance
? allSources.GetSourcePosition(provenance->start())
: std::nullopt};
if (lineDirectives && column == 1 && position) {
if (&*position->path != sourcePath) {
out << "#line \"" << *position->path << "\" " << position->line
<< '\n';
} else if (position->line != sourceLine) {
if (sourceLine < position->line &&
sourceLine + 10 >= position->line) {
// Emit a few newlines to catch up when they'll likely
// require fewer bytes than a #line directive would have
// occupied.
while (sourceLine++ < position->line) {
out << '\n';
if (column == 1 && position) {
if (lineDirectives) {
if (&*position->path != sourcePath) {
out << "#line \"" << *position->path << "\" " << position->line
<< '\n';
} else if (position->line != sourceLine) {
if (sourceLine < position->line &&
sourceLine + 10 >= position->line) {
// Emit a few newlines to catch up when they'll likely
// require fewer bytes than a #line directive would have
// occupied.
while (sourceLine++ < position->line) {
out << '\n';
}
} else {
out << "#line " << position->line << '\n';
}
} else {
out << "#line " << position->line << '\n';
}
}
sourcePath = &*position->path;
Expand Down Expand Up @@ -244,7 +246,7 @@ void Parsing::EmitPreprocessedSource(
}
}
} else if (!inContinuation && !inDirectiveSentinel && position &&
position->column <= 72) {
position->line == sourceLine && position->column < 72) {
// Preserve original indentation
for (; column < position->column; ++column) {
out << ' ';
Expand Down
5 changes: 5 additions & 0 deletions flang/test/Preprocessing/bug134986.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
! RUN: %flang -E %s 2>&1 | FileCheck %s
! CHECK: print *, "HELLO "//" WORLD"
print *, "HELLO "/&
&/" WORLD"
end