<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154443>154443</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
git-clang-format misformats CGCoroutine.cpp, adding spurious indentation across a large block
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
snarkmaster
</td>
</tr>
</table>
<pre>
I wasn't able to quickly minify the repro, but it keeps coming up on the CI of https://github.com/llvm/llvm-project/pull/152623, so I wanted to make sure to report the formatter bug so that either:
- it can be fixed, preventing future confusion and red signals on PRs
- a maintainer can suggest a workaround I can add to the code to avoid tripping the misformat
These repro steps use a commit ID available as part of https://github.com/llvm/llvm-project/pull/152623.
- 0732693d81975d92399ec6b63823ac27c83ab9fb just happens to be my merge base from LLVM `main`, nothing special about this commit
- e6b636744ec11778685d9944fee48377774a28ec has my changes that trigger the misformat
Per the below repro instructions, it seems like there might be an issue with how `git-clang-format` invokes `clang-format`, rather than with the formatter itself. Also relevant (from the PR with the problem):
> @efriedma-quic:
> git-clang-format uses the "--lines" option to clang-format restrict formatting updates. If that isn't working correctly, please file a bug. You can ignore the bot after that.
```
cd llvm-project
# I'm using `clang-format` built from trunk via `ninja clang-format`
tail -n 2 .git/config
[clangFormat]
binary = /home/username/llvm-build-github/bin/clang-format
git checkout e6b636744ec11778685d9944fee48377774a28ec
# Working method -- but this is NOT what LLVM CI uses
git diff -U0 --no-color 0732693d8197 | python3 clang/tools/clang-format/clang-format-diff.py -i -p1
git diff
# No changes
# Broken method
clang/tools/clang-format/git-clang-format 0732693d8197
git diff
diff --git i/clang/lib/CodeGen/CGCoroutine.cpp w/clang/lib/CodeGen/CGCoroutine.cpp
index ab972dda1c7c..d47553d0b688 100644
--- i/clang/lib/CodeGen/CGCoroutine.cpp
+++ w/clang/lib/CodeGen/CGCoroutine.cpp
@@ -219,205 +219,207 @@ namespace {
LValue LV;
RValue RV;
};
-}
+ } // namespace
+
...
```
I am not including the entire large diff generated by` git-clang-format`. It can be found here: https://github.com/llvm/llvm-project/actions/runs/17076699075/job/48426056089?pr=152623
However, the core of the problem is a bunch of global-scope lines end up indented 2 spaces, incorrectly.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVk2P47gR_TX0pSBBpr6sgw9u93pjYLIZDDYT5EhRZYljilRIyr3-90FR8vZ0zyKYRhoGWhbpqlevXn0I71VvEPesfGLl80bMYbBu741w11H4gG7T2u6-P8OL8IbxOoBoNUKw8J9Zyau-w6iMutwhDAgOJ2cZP0I7B1ABroiTB2lHZXqYJ7AmXjuewV5gCGHyLD8wfmL81KswzG0q7cj4Sevb418yOfsNZWD8NM1aM37alrziOXnxFgiXCdgRoFFcEfzsIjqHk3UhurtYN4oQ0EE79_SjMIgAqMKAjvxnB4CE4EphoEW4qD-wI_uTwxuaQOAvcyDD0prL7JU1IEwHDjsg-oT2FNrnL361JWAUygShDLpo1c99jz6AgBfrrsLZ2XRwjkeii-AJqLRdxC5uVnUQnJom8k1Ho_JLGCwjwL8P6Fe6wQciefYIgqgeVYDzM4ibUDqmSniYhAv_P-XpGl1W57xq8m63beqya3jeNCirtsp3PBeS13KXi7a5tPBt9gEGMU1oPMXVIox3GNH1CK3wCBdnR_j06evfgVUZUcaqjIg3NgwUuZ9QKqFBtHamXCq_RrgiQfJa1UWBcrut6121K7umKYoLYrHL67quC8F3KGEQnlzLQZge_SKA4FTfo_srej-vr1vU9mWlWRkf3CyDssYTRhXAI44etLoi3XZkph8ChSkMKO9nhBcVBhjsCwXYq5BILUyfrL6qDJS52St6On53RD6cILsE1yyW3spZBY_6ksJBexK8xpswARjfRV7p7ucvr7-bnG01jow3i-jpk_8CrMjw4hR2o0iopNfD_Bd4j5c05qMpxnmSaGXQM87BTkQKJfjNbYc-OCXDA_DSAzoR0KdwvixJUGtTobKgC9I6hzLoe6w_jVElilRMxZvCv-0cq0b1xjpckmQDiE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