Skip to content

Conversation

@HazardyKnusperkeks
Copy link
Contributor

Just return early based on the SpacedRequiredBefore.

Just return early based on the SpacedRequiredBefore.
@llvmbot
Copy link
Member

llvmbot commented Oct 18, 2025

@llvm/pr-subscribers-clang-format

Author: Björn Schäpers (HazardyKnusperkeks)

Changes

Just return early based on the SpacedRequiredBefore.


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

1 Files Affected:

  • (modified) clang/lib/Format/WhitespaceManager.cpp (+13-15)
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 7348a3af8cf95..03a1e9a6bd80b 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -656,7 +656,6 @@ void WhitespaceManager::alignConsecutiveMacros() {
 
   auto AlignMacrosMatches = [](const Change &C) {
     const FormatToken *Current = C.Tok;
-    unsigned SpacesRequiredBefore = 1;
 
     if (Current->SpacesRequiredBefore == 0 || !Current->Previous)
       return false;
@@ -665,22 +664,21 @@ void WhitespaceManager::alignConsecutiveMacros() {
 
     // If token is a ")", skip over the parameter list, to the
     // token that precedes the "("
-    if (Current->is(tok::r_paren) && Current->MatchingParen) {
-      Current = Current->MatchingParen->Previous;
-      SpacesRequiredBefore = 0;
-    }
-
-    if (!Current || Current->isNot(tok::identifier))
-      return false;
-
-    if (!Current->Previous || Current->Previous->isNot(tok::pp_define))
+    if (const auto *MatchingParen = Current->MatchingParen;
+        Current->is(tok::r_paren) && MatchingParen) {
+      // For a macro function, 0 spaces are required between the
+      // identifier and the lparen that opens the parameter list.
+      if (MatchingParen->SpacesRequiredBefore > 0)
+        return false;
+      Current = MatchingParen->Previous;
+    } else if (Current->Next->SpacesRequiredBefore != 1) {
+      // For a simple macro, 1 space is required between the
+      // identifier and the first token of the defined value.
       return false;
+    }
 
-    // For a macro function, 0 spaces are required between the
-    // identifier and the lparen that opens the parameter list.
-    // For a simple macro, 1 space is required between the
-    // identifier and the first token of the defined value.
-    return Current->Next->SpacesRequiredBefore == SpacesRequiredBefore;
+    return Current && Current->is(tok::identifier) && Current->Previous &&
+           Current->Previous->is(tok::pp_define);
   };
 
   unsigned MinColumn = 0;

@HazardyKnusperkeks HazardyKnusperkeks enabled auto-merge (squash) October 20, 2025 08:18
@HazardyKnusperkeks HazardyKnusperkeks merged commit 8774128 into llvm:main Oct 20, 2025
9 of 10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 20, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/29344

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Driver/debug-options.c' FAILED ********************
Exit Code: 127

Command Output (stdout):
--
# RUN: at line 4
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -### -c -g /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu 2>&1              | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang '-###' -c -g /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu
# note: command had no output on stdout or stderr
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# note: command had no output on stdout or stderr
# RUN: at line 6
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -### -c -g2 /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu 2>&1              | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang '-###' -c -g2 /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu
# note: command had no output on stdout or stderr
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# note: command had no output on stdout or stderr
# RUN: at line 8
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -### -c -g3 /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu 2>&1              | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang '-###' -c -g3 /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu
# note: command had no output on stdout or stderr
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# note: command had no output on stdout or stderr
# RUN: at line 10
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -### -c -ggdb /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu 2>&1              | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang '-###' -c -ggdb /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu
# note: command had no output on stdout or stderr
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# note: command had no output on stdout or stderr
# RUN: at line 12
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -### -c -ggdb1 /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu 2>&1              | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=GLTO_ONLY -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang '-###' -c -ggdb1 /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu
# note: command had no output on stdout or stderr
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=GLTO_ONLY -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# note: command had no output on stdout or stderr
# RUN: at line 14
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -### -c -ggdb3 /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu 2>&1              | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang '-###' -c -ggdb3 /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu
# note: command had no output on stdout or stderr
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_GDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# note: command had no output on stdout or stderr
# RUN: at line 16
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -### -c -glldb /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu 2>&1              | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_STANDALONE -check-prefix=G_LLDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang '-###' -c -glldb /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu
# note: command had no output on stdout or stderr
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_STANDALONE -check-prefix=G_LLDB /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# note: command had no output on stdout or stderr
# RUN: at line 18
/Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang -### -c -gsce /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu 2>&1              | /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=G_LIMITED -check-prefix=G_SCE /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c
# executed command: /Volumes/RAMDisk/buildbot-root/aarch64-darwin/build/bin/clang '-###' -c -gsce /Users/buildbot/buildbot-root/llvm-project/clang/test/Driver/debug-options.c -target x86_64-linux-gnu
...

Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
Just return early based on the SpacedRequiredBefore.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
Just return early based on the SpacedRequiredBefore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants