Skip to content

Conversation

@SergejSalnikov
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Nov 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2025

@llvm/pr-subscribers-clang

Author: Sergej Salnikov (SergejSalnikov)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/166631.diff

1 Files Affected:

  • (modified) clang/lib/Frontend/PrintPreprocessedOutput.cpp (+1-1)
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 9e046633328d7..32e2b8cdcf4c6 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -306,7 +306,7 @@ bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo,
     *OS << '\n';
     StartedNewLine = true;
   } else if (!DisableLineMarkers) {
-    if (LineNo - CurLine <= 8) {
+    if (LineNo >= CurLine && LineNo - CurLine <= 8) {
       const char *NewLines = "\n\n\n\n\n\n\n\n";
       OS->write(NewLines, LineNo - CurLine);
     } else {

@SergejSalnikov SergejSalnikov changed the title Correctly handle negative line changes [clang]Correctly handle negative line changes in MoveToLine Nov 5, 2025
@SergejSalnikov SergejSalnikov changed the title [clang]Correctly handle negative line changes in MoveToLine [clang]Correctly handle negative line changes in PrintPreprocessedOutput::MoveToLine Nov 5, 2025
Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needs a summary explaining the problem and how this fixes it. It is not obvious what your are fixing and without more narrative I can't review this properly. It also needs a test.

Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am waiting for an update but want to make sure this does not get merged by accident.

@SergejSalnikov
Copy link
Contributor Author

SergejSalnikov commented Dec 11, 2025

After #163982 the debug symbols inside macro arguments are now resolved to the line they appear rather than the line of macro statement.
#168402 will make the new macro argument expansion behaviour to be used for more cases.
Eventually we want the clang -E command to produce the pre-processed code which can be then compiled and the line numbers of debug symbols to match the source file.

The example is a #define SWAP(X, Y) Y; X where the line numbers in generated file will not always increment, but could decrement. that's why we need that new behaviour (see the video attached to #163982).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants