Skip to content

Commit 6aec300

Browse files
authored
Merge branch 'main' into wcstombs-functions
2 parents 8df5406 + 0a17483 commit 6aec300

File tree

218 files changed

+11619
-6903
lines changed

Some content is hidden

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

218 files changed

+11619
-6903
lines changed

.ci/metrics/metrics_test.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
"""Tests for metrics.py"""
5+
6+
from dataclasses import dataclass
7+
import requests
8+
import unittest
9+
import unittest.mock
10+
11+
import metrics
12+
13+
14+
class TestMetrics(unittest.TestCase):
15+
def test_upload_gauge_metric(self):
16+
"""Test that we can upload a gauge metric correctly.
17+
18+
Also verify that we pass around parameters like API keys and user IDs
19+
correctly to the HTTP POST request.
20+
"""
21+
test_metrics = [metrics.GaugeMetric("gauge_test", 5, 1000)]
22+
return_value = requests.Response()
23+
return_value.status_code = 204
24+
with unittest.mock.patch(
25+
"requests.post", return_value=return_value
26+
) as post_mock:
27+
metrics.upload_metrics(test_metrics, "test_userid", "test_api_key")
28+
self.assertSequenceEqual(post_mock.call_args.args, [metrics.GRAFANA_URL])
29+
self.assertEqual(
30+
post_mock.call_args.kwargs["data"], "gauge_test value=5 1000"
31+
)
32+
self.assertEqual(
33+
post_mock.call_args.kwargs["auth"], ("test_userid", "test_api_key")
34+
)
35+
36+
def test_upload_job_metric(self):
37+
"""Test that we can upload a job metric correctly."""
38+
test_metrics = [
39+
metrics.JobMetrics("test_job", 5, 10, 1, 1000, 7, "test_workflow")
40+
]
41+
return_value = requests.Response()
42+
return_value.status_code = 204
43+
with unittest.mock.patch(
44+
"requests.post", return_value=return_value
45+
) as post_mock:
46+
metrics.upload_metrics(test_metrics, "test_userid", "test_aoi_key")
47+
self.assertEqual(
48+
post_mock.call_args.kwargs["data"],
49+
"test_job queue_time=5,run_time=10,status=1 1000",
50+
)
51+
52+
def test_upload_unknown_metric(self):
53+
"""Test we report an error if we encounter an unknown metric type."""
54+
55+
@dataclass
56+
class FakeMetric:
57+
fake_data: str
58+
59+
test_metrics = [FakeMetric("test")]
60+
61+
with self.assertRaises(ValueError):
62+
metrics.upload_metrics(test_metrics, "test_userid", "test_api_key")
63+
64+
def test_bad_response_code(self):
65+
"""Test that we gracefully handle HTTP response errors."""
66+
test_metrics = [metrics.GaugeMetric("gauge_test", 5, 1000)]
67+
return_value = requests.Response()
68+
return_value.status_code = 403
69+
# Just assert that we continue running here and do not raise anything.
70+
with unittest.mock.patch("requests.post", return_value=return_value) as _:
71+
metrics.upload_metrics(test_metrics, "test_userid", "test_api_key")
72+
73+
74+
if __name__ == "__main__":
75+
unittest.main()

.github/workflows/check-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
- name: Install Python Dependencies
3232
run: |
3333
pip3 install -r .ci/all_requirements.txt
34+
pip3 install -r .ci/metrics/requirements.lock.txt
3435
pip3 install pytest==8.4.1
3536
- name: Run Tests
3637
working-directory: .ci

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4260,31 +4260,25 @@ void RewriteInstance::patchELFPHDRTable() {
42604260
const ELFFile<ELF64LE> &Obj = ELF64LEFile->getELFFile();
42614261
raw_fd_ostream &OS = Out->os();
42624262

4263-
// Write/re-write program headers.
42644263
Phnum = Obj.getHeader().e_phnum;
4265-
if (PHDRTableOffset) {
4266-
// Writing new pheader table and adding one new entry for R+X segment.
4267-
Phnum += 1;
4268-
if (NewWritableSegmentSize) {
4269-
// Adding one more entry for R+W segment.
4270-
Phnum += 1;
4271-
}
4272-
} else {
4264+
4265+
if (BC->NewSegments.empty()) {
4266+
BC->outs() << "BOLT-INFO: not adding new segments\n";
4267+
return;
4268+
}
4269+
4270+
if (opts::UseGnuStack) {
42734271
assert(!PHDRTableAddress && "unexpected address for program header table");
4274-
PHDRTableOffset = Obj.getHeader().e_phoff;
4275-
if (NewWritableSegmentSize) {
4272+
if (BC->NewSegments.size() > 1) {
42764273
BC->errs() << "BOLT-ERROR: unable to add writable segment\n";
42774274
exit(1);
42784275
}
4276+
} else {
4277+
Phnum += BC->NewSegments.size();
42794278
}
42804279

4281-
if (opts::Instrument)
4282-
Phnum += 2;
4283-
4284-
if (BC->NewSegments.empty()) {
4285-
BC->outs() << "BOLT-INFO: not adding new segments\n";
4286-
return;
4287-
}
4280+
if (!PHDRTableOffset)
4281+
PHDRTableOffset = Obj.getHeader().e_phoff;
42884282

42894283
const uint64_t SavedPos = OS.tell();
42904284
OS.seek(PHDRTableOffset);

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ Changes in existing checks
124124
- Improved :doc:`misc-header-include-cycle
125125
<clang-tidy/checks/misc/header-include-cycle>` check performance.
126126

127+
- Improved :doc:`modernize-use-std-format
128+
<clang-tidy/checks/modernize/use-std-format>` check to correctly match
129+
when the format string is converted to a different type by an implicit
130+
constructor call.
131+
132+
- Improved :doc:`modernize-use-std-print
133+
<clang-tidy/checks/modernize/use-std-print>` check to correctly match
134+
when the format string is converted to a different type by an implicit
135+
constructor call.
136+
127137
- Improved :doc:`portability-template-virtual-member-function
128138
<clang-tidy/checks/portability/template-virtual-member-function>` check to
129139
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/cmake/caches/Fuchsia.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ foreach(variable ${_FUCHSIA_BOOTSTRAP_PASSTHROUGH})
7676
get_property(value CACHE ${variable} PROPERTY VALUE)
7777
get_property(type CACHE ${variable} PROPERTY TYPE)
7878
set(BOOTSTRAP_${variable} "${value}" CACHE ${type} "")
79+
if(FUCHSIA_ENABLE_PGO)
80+
set(BOOTSTRAP_BOOTSTRAP_${variable} "${value}" CACHE ${type} "")
81+
endif()
7982
endif()
8083
endforeach()
8184

0 commit comments

Comments
 (0)