Skip to content

Commit 12dbff0

Browse files
committed
rebase
Created using spr 1.3.4
2 parents 0efe8f6 + a636b7b commit 12dbff0

File tree

138 files changed

+4360
-1908
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+4360
-1908
lines changed

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def main():
177177
parser.add_argument(
178178
"-j",
179179
type=int,
180-
default=1,
180+
default=0,
181181
help="number of tidy instances to be run in parallel.",
182182
)
183183
parser.add_argument(
@@ -318,6 +318,7 @@ def main():
318318
if max_task_count == 0:
319319
max_task_count = multiprocessing.cpu_count()
320320
max_task_count = min(len(lines_by_file), max_task_count)
321+
print(f"Running clang-tidy in {max_task_count} threads...")
321322

322323
combine_fixes = False
323324
export_fixes_dir = None

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ async def main() -> None:
548548
files = {f for f in files if file_name_re.search(f)}
549549

550550
print(
551-
"Running clang-tidy for",
551+
f"Running clang-tidy in {max_task} threads for",
552552
len(files),
553553
"files out of",
554554
number_files_in_database,

clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,9 @@ FormatStringConverter::FormatStringConverter(
207207
ArgsOffset(FormatArgOffset + 1), LangOpts(LO) {
208208
assert(ArgsOffset <= NumArgs);
209209
FormatExpr = llvm::dyn_cast<StringLiteral>(
210-
Args[FormatArgOffset]->IgnoreImplicitAsWritten());
210+
Args[FormatArgOffset]->IgnoreUnlessSpelledInSource());
211211

212-
if (!FormatExpr || !FormatExpr->isOrdinary()) {
213-
// Function must have a narrow string literal as its first argument.
214-
conversionNotPossible("first argument is not a narrow string literal");
215-
return;
216-
}
212+
assert(FormatExpr && FormatExpr->isOrdinary());
217213

218214
if (const std::optional<StringRef> MaybeMacroName =
219215
formatStringContainsUnreplaceableMacro(Call, FormatExpr, SM, PP);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ Improvements to clang-query
9393
Improvements to clang-tidy
9494
--------------------------
9595

96+
- The :program:`run-clang-tidy.py` and :program:`clang-tidy-diff.py` scripts
97+
now run checks in parallel by default using all available hardware threads.
98+
Both scripts display the number of threads being used in their output.
99+
96100
New checks
97101
^^^^^^^^^^
98102

@@ -124,6 +128,16 @@ Changes in existing checks
124128
- Improved :doc:`misc-header-include-cycle
125129
<clang-tidy/checks/misc/header-include-cycle>` check performance.
126130

131+
- Improved :doc:`modernize-use-std-format
132+
<clang-tidy/checks/modernize/use-std-format>` check to correctly match
133+
when the format string is converted to a different type by an implicit
134+
constructor call.
135+
136+
- Improved :doc:`modernize-use-std-print
137+
<clang-tidy/checks/modernize/use-std-print>` check to correctly match
138+
when the format string is converted to a different type by an implicit
139+
constructor call.
140+
127141
- Improved :doc:`portability-template-virtual-member-function
128142
<clang-tidy/checks/portability/template-virtual-member-function>` check to
129143
avoid false positives on pure virtual member functions.

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// RUN: -std=c++20 %s modernize-use-std-format %t -- \
33
// RUN: -config="{CheckOptions: { \
44
// RUN: modernize-use-std-format.StrictMode: true, \
5-
// RUN: modernize-use-std-format.StrFormatLikeFunctions: '::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
5+
// RUN: modernize-use-std-format.StrFormatLikeFunctions: '::strprintf; mynamespace::strprintf2; any_format_type_strprintf', \
66
// RUN: modernize-use-std-format.ReplacementFormatFunction: 'fmt::format', \
77
// RUN: modernize-use-std-format.FormatHeader: '<fmt/core.h>' \
88
// RUN: }}" \
99
// RUN: -- -isystem %clang_tidy_headers
1010
// RUN: %check_clang_tidy -check-suffixes=,NOTSTRICT \
1111
// RUN: -std=c++20 %s modernize-use-std-format %t -- \
1212
// RUN: -config="{CheckOptions: { \
13-
// RUN: modernize-use-std-format.StrFormatLikeFunctions: '::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
13+
// RUN: modernize-use-std-format.StrFormatLikeFunctions: '::strprintf; mynamespace::strprintf2; any_format_type_strprintf', \
1414
// RUN: modernize-use-std-format.ReplacementFormatFunction: 'fmt::format', \
1515
// RUN: modernize-use-std-format.FormatHeader: '<fmt/core.h>' \
1616
// RUN: }}" \
@@ -56,12 +56,17 @@ std::string A(const std::string &in)
5656
struct S {
5757
S(...);
5858
};
59-
std::string bad_format_type_strprintf(const S &, ...);
59+
std::string any_format_type_strprintf(const S &, ...);
6060

61-
std::string unsupported_format_parameter_type()
61+
void unsupported_format_parameter_types()
6262
{
6363
// No fixes here because the format parameter of the function called is not a
6464
// string.
65-
return bad_format_type_strprintf("");
66-
// CHECK-MESSAGES: [[@LINE-1]]:10: warning: unable to use 'fmt::format' instead of 'bad_format_type_strprintf' because first argument is not a narrow string literal [modernize-use-std-format]
65+
auto s1 = any_format_type_strprintf(L"");
66+
auto s2 = any_format_type_strprintf(42);
67+
68+
// But if we do pass a character string then that ought to be acceptable.
69+
auto s3 = any_format_type_strprintf("Hello %s", "world");
70+
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'fmt::format' instead of 'any_format_type_strprintf' [modernize-use-std-format]
71+
// CHECK-FIXES: auto s3 = fmt::format("Hello {}", "world");
6772
}

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
namespace absl
1818
{
19-
template <typename S, typename... Args>
20-
std::string StrFormat(const S &format, const Args&... args);
19+
template <typename... Args>
20+
std::string StrFormat(const std::string_view &format, const Args&... args);
2121
} // namespace absl
2222

2323
template <typename T>

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
#include <cstdio>
1111
#include <string.h>
12+
#include <string>
1213

1314
namespace absl
1415
{
15-
// Use const char * for the format since the real type is hard to mock up.
1616
template <typename... Args>
17-
int PrintF(const char *format, const Args&... args);
17+
int PrintF(const std::string_view &format, const Args&... args);
1818

1919
template <typename... Args>
20-
int FPrintF(FILE* output, const char *format, const Args&... args);
20+
int FPrintF(FILE* output, const std::string_view &format, const Args&... args);
2121
}
2222

2323
void printf_simple() {

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %check_clang_tidy -std=c++23 %s modernize-use-std-print %t -- \
22
// RUN: -config="{CheckOptions: \
33
// RUN: { \
4-
// RUN: modernize-use-std-print.PrintfLikeFunctions: 'unqualified_printf;::myprintf; mynamespace::myprintf2; bad_format_type_printf; fmt::printf', \
5-
// RUN: modernize-use-std-print.FprintfLikeFunctions: '::myfprintf; mynamespace::myfprintf2; bad_format_type_fprintf; fmt::fprintf' \
4+
// RUN: modernize-use-std-print.PrintfLikeFunctions: 'unqualified_printf;::myprintf; mynamespace::myprintf2; any_format_type_printf; fmt::printf', \
5+
// RUN: modernize-use-std-print.FprintfLikeFunctions: '::myfprintf; mynamespace::myfprintf2; any_format_type_fprintf; fmt::fprintf' \
66
// RUN: } \
77
// RUN: }" \
88
// RUN: -- -isystem %clang_tidy_headers
@@ -98,18 +98,25 @@ void wide_string_not_supported() {
9898
struct S {
9999
S(...) {}
100100
};
101-
int bad_format_type_printf(const S &, ...);
102-
int bad_format_type_fprintf(FILE *, const S &, ...);
101+
int any_format_type_printf(const S &, ...);
102+
int any_format_type_fprintf(FILE *, const S &, ...);
103103

104104
void unsupported_format_parameter_type()
105105
{
106106
// No fixes here because the format parameter of the function called is not a
107107
// string.
108-
bad_format_type_printf("Hello %s", "world");
109-
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: unable to use 'std::print' instead of 'bad_format_type_printf' because first argument is not a narrow string literal [modernize-use-std-print]
110-
111-
bad_format_type_fprintf(stderr, "Hello %s", "world");
112-
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: unable to use 'std::print' instead of 'bad_format_type_fprintf' because first argument is not a narrow string literal [modernize-use-std-print]
108+
any_format_type_printf(L"Hello %s", "world");
109+
any_format_type_fprintf(stderr, L"Hello %s", "world");
110+
any_format_type_printf(42);
111+
any_format_type_fprintf(stderr, 42L);
112+
113+
// But if we do pass a character string then that ought to be acceptable.
114+
any_format_type_printf("Hello %s\n", "world");
115+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'any_format_type_printf' [modernize-use-std-print]
116+
// CHECK-FIXES: std::println("Hello {}", "world");
117+
any_format_type_fprintf(stderr, "Hello %s\n", "world");
118+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'any_format_type_fprintf' [modernize-use-std-print]
119+
// CHECK-FIXES: std::println(stderr, "Hello {}", "world");
113120
}
114121

115122
namespace fmt {

clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-diff.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// REQUIRES: shell
22
// RUN: sed 's/placeholder_for_f/f/' %s > %t.cpp
33
// RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
4-
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s
4+
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-JMAX
55
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
66
// RUN: mkdir -p %T/compilation-database-test/
77
// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 %t.cpp", "file": "%t.cpp"}]' > %T/compilation-database-test/compile_commands.json
88
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
9+
10+
// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -j 1 -- -std=c++11 2>&1 | FileCheck %s --check-prefix=CHECK-J1
11+
// CHECK-J1: Running clang-tidy in 1 threads...
912
struct A {
1013
virtual void f() {}
1114
virtual void g() {}
1215
};
16+
// CHECK-JMAX: Running clang-tidy in {{[1-9][0-9]*}} threads...
1317
// CHECK-NOT: warning:
1418
// CHECK-QUIET-NOT: warning:
1519
struct B : public A {

clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
// RUN: echo " modernize-use-auto.MinTypeNameLength: '0'" >> %t/.clang-tidy
99
// RUN: cp "%s" "%t/test.cpp"
1010
// RUN: cd "%t"
11-
// RUN: not %run_clang_tidy "test.cpp"
11+
// RUN: not %run_clang_tidy "test.cpp" 2>&1 | FileCheck %s --check-prefix=CHECK-JMAX
12+
// CHECK-JMAX: Running clang-tidy in {{[1-9][0-9]*}} threads for
13+
14+
// RUN: not %run_clang_tidy -j 1 "test.cpp" 2>&1 | FileCheck %s --check-prefix=CHECK-J1
15+
// CHECK-J1: Running clang-tidy in 1 threads for
1216

1317
int main()
1418
{

0 commit comments

Comments
 (0)