https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/172627
>From b4f217e3db511708c3f2402c8b9fea31053b85f2 Mon Sep 17 00:00:00 2001 From: David Spickett <[email protected]> Date: Wed, 17 Dec 2025 10:15:44 +0000 Subject: [PATCH 1/3] [clang-format] Fix comparison warning in 32-bit builds In our 32-bit Arm builds we see: ``` UnwrappedLineFormatter.cpp:645:31: warning: comparison of integers of different signs: 'typename iterator_traits<AnnotatedLine *const *>::difference_type' (aka 'int') and 'const unsigned int' [-Wsign-compare] 645 | if (std::distance(I, E) <= N) | ~~~~~~~~~~~~~~~~~~~ ^ ~ ``` The existing comparison seems to assume that the distance will not be negative. So to fix this warning I've asserted that that is the case, then cast the distance to the unsigned type. I think this warning does not occur in 64-bit builds becuase there it is safe to extend the unsigned 32-bit integer to the 64-bit signed distance type. --- clang/lib/Format/UnwrappedLineFormatter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 913789afd9919..3a6ab8de7c476 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -642,7 +642,9 @@ class LineJoiner { return 0; const auto N = MergedLines + LinesToBeMerged; // Check if there is even a line after the inner result. - if (std::distance(I, E) <= N) + auto Distance = std::distance(I, E); + assert(Distance >= 0); + if (static_cast<decltype(N)>(Distance) <= N) return 0; // Check that the line after the inner result starts with a closing brace // which we are permitted to merge into one line. >From 541c4ef98ba92e0cb56714e3d903c99f64ae14d9 Mon Sep 17 00:00:00 2001 From: David Spickett <[email protected]> Date: Wed, 17 Dec 2025 11:33:10 +0000 Subject: [PATCH 2/3] Update clang/lib/Format/UnwrappedLineFormatter.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Björn Schäpers <[email protected]> --- clang/lib/Format/UnwrappedLineFormatter.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 3a6ab8de7c476..8ce6388c34da7 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -642,9 +642,7 @@ class LineJoiner { return 0; const auto N = MergedLines + LinesToBeMerged; // Check if there is even a line after the inner result. - auto Distance = std::distance(I, E); - assert(Distance >= 0); - if (static_cast<decltype(N)>(Distance) <= N) + if (auto Distance = std::distance(I, E); static_cast<decltype(N)>(Distance) <= N) return 0; // Check that the line after the inner result starts with a closing brace // which we are permitted to merge into one line. >From 8d2e1df7e66e95b627cecf55fb37b3fd1668de9b Mon Sep 17 00:00:00 2001 From: David Spickett <[email protected]> Date: Wed, 17 Dec 2025 11:40:18 +0000 Subject: [PATCH 3/3] formatting --- clang/lib/Format/UnwrappedLineFormatter.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 8ce6388c34da7..d8e139b44fce3 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -604,7 +604,7 @@ class LineJoiner { if (BraceOpenLine[0]->Last->isNot(TT_NamespaceLBrace)) return 0; - if (std::distance(BraceOpenLine, E) <= 2) + if ((BraceOpenLine, E) <= 2) return 0; if (BraceOpenLine[0]->Last->is(tok::comment)) @@ -642,8 +642,10 @@ class LineJoiner { return 0; const auto N = MergedLines + LinesToBeMerged; // Check if there is even a line after the inner result. - if (auto Distance = std::distance(I, E); static_cast<decltype(N)>(Distance) <= N) - return 0; + if (auto Distance = std::distance(I, E); + static_cast<decltype(N)>(Distance) <= N) { + return 0; + } // Check that the line after the inner result starts with a closing brace // which we are permitted to merge into one line. if (I[N]->First->is(TT_NamespaceRBrace) && _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
