Skip to content

Commit 683ed44

Browse files
authored
merge main into amd-staging (llvm#4571)
2 parents 458e895 + b269942 commit 683ed44

File tree

34 files changed

+498
-649
lines changed

34 files changed

+498
-649
lines changed

.github/workflows/containers/github-action-ci-tooling/Dockerfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
ARG LLVM_VERSION=21.1.0
2+
# FIXME: Use "${LLVM_VERSION%%.*}" instead of "LLVM_VERSION_MAJOR" once we update runners to Ubuntu-26.04 with Buildah >= 1.37
3+
ARG LLVM_VERSION_MAJOR=21
24

35
FROM docker.io/library/ubuntu:24.04 AS llvm-downloader
46
ARG LLVM_VERSION
7+
ARG LLVM_VERSION_MAJOR
58

69
RUN apt-get update && \
710
apt-get install -y wget xz-utils && \
811
wget -O llvm.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/LLVM-${LLVM_VERSION}-Linux-X64.tar.xz && \
912
mkdir -p /llvm-extract && \
1013
tar -xvJf llvm.tar.xz -C /llvm-extract \
1114
# Only unpack these tools to save space on Github runner.
15+
LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-${LLVM_VERSION_MAJOR} \
16+
LLVM-${LLVM_VERSION}-Linux-X64/lib/clang/${LLVM_VERSION_MAJOR}/include \
1217
LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-tidy \
1318
LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-format \
1419
LLVM-${LLVM_VERSION}-Linux-X64/bin/git-clang-format && \
@@ -50,12 +55,27 @@ RUN pip install -r requirements_formatting.txt --break-system-packages && \
5055

5156
FROM base AS ci-container-code-lint
5257
ARG LLVM_VERSION
58+
ARG LLVM_VERSION_MAJOR
5359

54-
COPY --from=llvm-downloader /llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-tidy ${LLVM_SYSROOT}/bin/
60+
COPY --from=llvm-downloader /llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-tidy \
61+
/llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-${LLVM_VERSION_MAJOR} \
62+
${LLVM_SYSROOT}/bin/
63+
COPY --from=llvm-downloader /llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/lib/clang/${LLVM_VERSION_MAJOR}/include \
64+
${LLVM_SYSROOT}/lib/clang/${LLVM_VERSION_MAJOR}/include
5565
COPY clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py ${LLVM_SYSROOT}/bin/clang-tidy-diff.py
5666

67+
RUN ln -s ${LLVM_SYSROOT}/bin/clang-${LLVM_VERSION_MAJOR} ${LLVM_SYSROOT}/bin/clang && \
68+
ln -s ${LLVM_SYSROOT}/bin/clang ${LLVM_SYSROOT}/bin/clang++
69+
5770
ENV PATH=${LLVM_SYSROOT}/bin:${PATH}
5871

72+
RUN apt-get update && \
73+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
74+
cmake \
75+
ninja-build && \
76+
apt-get clean && \
77+
rm -rf /var/lib/apt/lists/*
78+
5979
# Install dependencies for 'pr-code-lint.yml' job
6080
COPY llvm/utils/git/requirements_linting.txt requirements_linting.txt
6181
RUN pip install -r requirements_linting.txt --break-system-packages && \

clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,9 @@ static void lengthExprHandle(const Expr *LengthExpr,
309309
// Try to obtain an 'IntegerLiteral' and adjust it.
310310
if (!IsMacroDefinition) {
311311
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(LengthExpr)) {
312-
size_t NewLength = LengthIL->getValue().getZExtValue() +
313-
(LengthHandle == LengthHandleKind::Increase
314-
? (isInjectUL(Result) ? 1UL : 1)
315-
: -1);
312+
uint64_t NewLength =
313+
LengthIL->getValue().getZExtValue() +
314+
(LengthHandle == LengthHandleKind::Increase ? 1 : -1);
316315

317316
const auto NewLengthFix = FixItHint::CreateReplacement(
318317
LengthIL->getSourceRange(),

clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ void UseIntegerSignComparisonCheck::check(
152152
if (const auto *RHSCast = llvm::dyn_cast<ExplicitCastExpr>(RHS)) {
153153
SubExprRHS = RHSCast->getSubExpr();
154154
R2.setEnd(SubExprRHS->getBeginLoc().getLocWithOffset(-1));
155+
R3.setBegin(Lexer::getLocForEndOfToken(
156+
SubExprRHS->getEndLoc(), 0, *Result.SourceManager, getLangOpts()));
155157
}
156158
DiagnosticBuilder Diag =
157159
diag(BinaryOp->getBeginLoc(),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ Changes in existing checks
276276

277277
- Improved :doc:`bugprone-not-null-terminated-result
278278
<clang-tidy/checks/bugprone/not-null-terminated-result>` check by fixing
279+
bogus fix-its for ``strncmp`` and ``wcsncmp`` on Windows and
279280
a crash caused by certain value-dependent expressions.
280281

281282
- Improved :doc:`bugprone-reserved-identifier
@@ -363,6 +364,11 @@ Changes in existing checks
363364
<clang-tidy/checks/modernize/use-designated-initializers>` check to
364365
suggest using designated initializers for aliased aggregate types.
365366

367+
- Improved :doc:`modernize-use-integer-sign-comparison
368+
<clang-tidy/checks/modernize/use-integer-sign-comparison>` by providing
369+
correct fix-its when the right-hand side of a comparison contains a
370+
non-C-style cast.
371+
366372
- Improved :doc:`modernize-use-nullptr
367373
<clang-tidy/checks/modernize/use-nullptr>` check by fixing a crash
368374
on Windows when the check was enabled with a 32-bit :program:`clang-tidy`

clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
22
// RUN: -- -I %S/Inputs/not-null-terminated-result
33

4-
// FIXME: Something wrong with the APInt un/signed conversion on Windows:
5-
// in 'strncmp(str6, "string", 7);' it tries to inject '4294967302' as length.
6-
7-
// UNSUPPORTED: system-windows
8-
94
#include "not-null-terminated-result-c.h"
105

116
#define __STDC_LIB_EXT1__ 1

clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-wcslen.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-not-null-terminated-result %t -- \
22
// RUN: -- -I %S/Inputs/not-null-terminated-result
33

4-
// FIXME: Something wrong with the APInt un/signed conversion on Windows:
5-
// in 'wcsncmp(wcs6, L"string", 7);' it tries to inject '4294967302' as length.
6-
7-
// UNSUPPORTED: system-windows
8-
94
#include "not-null-terminated-result-cxx.h"
105

116
#define __STDC_LIB_EXT1__ 1

clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison-qt.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ int AllComparisons() {
9292
if (static_cast<unsigned int>(uArray[2]) < static_cast<int>(sArray[2]))
9393
return 0;
9494
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
95-
// CHECK-FIXES: if (q20::cmp_less(uArray[2],sArray[2])))
96-
// FIXME: There should only be 2 closing braces. The fix-it inserts an unbalanced one.
95+
// CHECK-FIXES: if (q20::cmp_less(uArray[2],sArray[2]))
9796

9897
if ((unsigned int)uArray[3] < (int)sArray[3])
9998
return 0;
@@ -116,6 +115,11 @@ int AllComparisons() {
116115
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
117116
// CHECK-FIXES: if (q20::cmp_greater(uArray[6] , VALUE))
118117

118+
if (unsigned(uArray[7]) >= int(sArray[7]))
119+
return 0;
120+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
121+
// CHECK-FIXES: if (q20::cmp_greater_equal(uArray[7],sArray[7]))
122+
119123

120124
FuncParameters(uVar);
121125
TemplateFuncParameter(sVar);

clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ int AllComparisons() {
9191
if (static_cast<unsigned int>(uArray[2]) < static_cast<int>(sArray[2]))
9292
return 0;
9393
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
94-
// CHECK-FIXES: if (std::cmp_less(uArray[2],sArray[2])))
95-
// FIXME: There should only be 2 closing braces. The fix-it inserts an unbalanced one.
94+
// CHECK-FIXES: if (std::cmp_less(uArray[2],sArray[2]))
9695

9796
if ((unsigned int)uArray[3] < (int)sArray[3])
9897
return 0;
@@ -115,6 +114,11 @@ int AllComparisons() {
115114
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
116115
// CHECK-FIXES: if (std::cmp_greater(uArray[6] , VALUE))
117116

117+
if (unsigned(uArray[7]) >= int(sArray[7]))
118+
return 0;
119+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
120+
// CHECK-FIXES: if (std::cmp_greater_equal(uArray[7],sArray[7]))
121+
118122

119123
FuncParameters(uVar);
120124
TemplateFuncParameter(sVar);

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,11 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
432432
// right-justified. It is used to align compound assignments like `+=` and `=`.
433433
// When RightJustify and ACS.PadOperators are true, operators in each block to
434434
// be aligned will be padded on the left to the same length before aligning.
435-
template <typename F>
435+
//
436+
// The simple check will not look at the indentaion and nesting level to recurse
437+
// into the line for alignment. It will also not count the commas. This is e.g.
438+
// for aligning macro definitions.
439+
template <typename F, bool SimpleCheck = false>
436440
static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
437441
SmallVector<WhitespaceManager::Change, 16> &Changes,
438442
unsigned StartAt,
@@ -465,9 +469,9 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
465469

466470
// Measure the scope level (i.e. depth of (), [], {}) of the first token, and
467471
// abort when we hit any token in a higher scope than the starting one.
468-
auto IndentAndNestingLevel = StartAt < Changes.size()
469-
? Changes[StartAt].indentAndNestingLevel()
470-
: std::tuple<unsigned, unsigned, unsigned>();
472+
const auto IndentAndNestingLevel =
473+
StartAt < Changes.size() ? Changes[StartAt].indentAndNestingLevel()
474+
: std::tuple<unsigned, unsigned, unsigned>();
471475

472476
// Keep track of the number of commas before the matching tokens, we will only
473477
// align a sequence of matching tokens if they are preceded by the same number
@@ -536,14 +540,17 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
536540
if (CurrentChange.Tok->isNot(tok::comment))
537541
LineIsComment = false;
538542

539-
if (CurrentChange.Tok->is(tok::comma)) {
540-
++CommasBeforeMatch;
541-
} else if (CurrentChange.indentAndNestingLevel() > IndentAndNestingLevel) {
542-
// Call AlignTokens recursively, skipping over this scope block.
543-
unsigned StoppedAt =
544-
AlignTokens(Style, Matches, Changes, i, ACS, RightJustify);
545-
i = StoppedAt - 1;
546-
continue;
543+
if (!SimpleCheck) {
544+
if (CurrentChange.Tok->is(tok::comma)) {
545+
++CommasBeforeMatch;
546+
} else if (CurrentChange.indentAndNestingLevel() >
547+
IndentAndNestingLevel) {
548+
// Call AlignTokens recursively, skipping over this scope block.
549+
const auto StoppedAt =
550+
AlignTokens(Style, Matches, Changes, i, ACS, RightJustify);
551+
i = StoppedAt - 1;
552+
continue;
553+
}
547554
}
548555

549556
if (!Matches(CurrentChange))
@@ -683,61 +690,8 @@ void WhitespaceManager::alignConsecutiveMacros() {
683690
return Current->Next->SpacesRequiredBefore == SpacesRequiredBefore;
684691
};
685692

686-
unsigned MinColumn = 0;
687-
688-
// Start and end of the token sequence we're processing.
689-
unsigned StartOfSequence = 0;
690-
unsigned EndOfSequence = 0;
691-
692-
// Whether a matching token has been found on the current line.
693-
bool FoundMatchOnLine = false;
694-
695-
// Whether the current line consists only of comments
696-
bool LineIsComment = true;
697-
698-
unsigned I = 0;
699-
for (unsigned E = Changes.size(); I != E; ++I) {
700-
if (Changes[I].NewlinesBefore != 0) {
701-
EndOfSequence = I;
702-
703-
// Whether to break the alignment sequence because of an empty line.
704-
bool EmptyLineBreak = (Changes[I].NewlinesBefore > 1) &&
705-
!Style.AlignConsecutiveMacros.AcrossEmptyLines;
706-
707-
// Whether to break the alignment sequence because of a line without a
708-
// match.
709-
bool NoMatchBreak =
710-
!FoundMatchOnLine &&
711-
!(LineIsComment && Style.AlignConsecutiveMacros.AcrossComments);
712-
713-
if (EmptyLineBreak || NoMatchBreak) {
714-
AlignMatchingTokenSequence(StartOfSequence, EndOfSequence, MinColumn,
715-
AlignMacrosMatches, Changes);
716-
}
717-
718-
// A new line starts, re-initialize line status tracking bools.
719-
FoundMatchOnLine = false;
720-
LineIsComment = true;
721-
}
722-
723-
if (Changes[I].Tok->isNot(tok::comment))
724-
LineIsComment = false;
725-
726-
if (!AlignMacrosMatches(Changes[I]))
727-
continue;
728-
729-
FoundMatchOnLine = true;
730-
731-
if (StartOfSequence == 0)
732-
StartOfSequence = I;
733-
734-
unsigned ChangeMinColumn = Changes[I].StartOfTokenColumn;
735-
MinColumn = std::max(MinColumn, ChangeMinColumn);
736-
}
737-
738-
EndOfSequence = I;
739-
AlignMatchingTokenSequence(StartOfSequence, EndOfSequence, MinColumn,
740-
AlignMacrosMatches, Changes);
693+
AlignTokens<decltype(AlignMacrosMatches) &, /*SimpleCheck=*/true>(
694+
Style, AlignMacrosMatches, Changes, 0, Style.AlignConsecutiveMacros);
741695
}
742696

743697
void WhitespaceManager::alignConsecutiveAssignments() {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: grep -q $'^\xEF\xBB\xBF' %S/Inputs/rewrite-includes-bom.h
1+
// RUN: cat %S/Inputs/rewrite-includes-bom.h | od -t x1 | grep -q 'ef\s*bb\s*bf'
22
// RUN: %clang_cc1 -E -frewrite-includes -I %S/Inputs %s -o %t.c
3-
// RUN: ! grep -q $'\xEF\xBB\xBF' %t.c
3+
// RUN: cat %t.c | od -t x1 | not grep -q 'ef\s*bb\s*bf'
44
// RUN: %clang_cc1 -fsyntax-only -verify %t.c
55
// expected-no-diagnostics
6-
// REQUIRES: shell
6+
// UNSUPPORTED: system-windows
77

88
#include "rewrite-includes-bom.h"

0 commit comments

Comments
 (0)