Skip to content

Commit 885984d

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-narrow-interleave
2 parents 61279d1 + b9f09a4 commit 885984d

File tree

403 files changed

+11687
-6482
lines changed

Some content is hidden

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

403 files changed

+11687
-6482
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ bool shouldPrint(const BinaryFunction &Function) {
165165
}
166166
}
167167

168+
std::optional<StringRef> Origin = Function.getOriginSectionName();
169+
if (Origin && llvm::any_of(opts::PrintOnly, [&](const std::string &Name) {
170+
return Name == *Origin;
171+
}))
172+
return true;
173+
168174
return false;
169175
}
170176

bolt/test/AArch64/constant_island_pie_update.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
# RUN: %clang %cflags -fPIC -pie %t.o -o %t.rela.exe -nostdlib \
99
# RUN: -Wl,-q -Wl,-z,notext
1010
# RUN: llvm-bolt %t.rela.exe -o %t.rela.bolt --use-old-text=0 --lite=0
11-
# RUN: llvm-objdump -j .text -d --show-all-symbols %t.rela.bolt | FileCheck %s
11+
# RUN: llvm-objdump -j .text -d -z --show-all-symbols %t.rela.bolt | FileCheck %s
1212
# RUN: llvm-readelf -rsW %t.rela.bolt | FileCheck --check-prefix=ELFCHECK %s
1313
// .relr.dyn
1414
# RUN: %clang %cflags -fPIC -pie %t.o -o %t.relr.exe -nostdlib \
1515
# RUN: -Wl,-q -Wl,-z,notext -Wl,--pack-dyn-relocs=relr
1616
# RUN: llvm-objcopy --remove-section .rela.mytext %t.relr.exe
1717
# RUN: llvm-bolt %t.relr.exe -o %t.relr.bolt --use-old-text=0 --lite=0
18-
# RUN: llvm-objdump -j .text -d --show-all-symbols %t.relr.bolt | FileCheck %s
19-
# RUN: llvm-objdump -j .text -d %t.relr.bolt | \
18+
# RUN: llvm-objdump -j .text -d -z --show-all-symbols %t.relr.bolt | FileCheck %s
19+
# RUN: llvm-objdump -j .text -d -z %t.relr.bolt | \
2020
# RUN: FileCheck %s --check-prefix=ADDENDCHECK
2121
# RUN: llvm-readelf -rsW %t.relr.bolt | FileCheck --check-prefix=RELRELFCHECK %s
2222
# RUN: llvm-readelf -SW %t.relr.bolt | FileCheck --check-prefix=RELRSZCHECK %s

bolt/test/AArch64/update-weak-reference-symbol.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: %clang %cflags -Wl,-z,notext -shared -Wl,-q %s -o %t.so
44
// RUN: llvm-bolt %t.so -o %t.so.bolt
55
// RUN: llvm-nm -n %t.so.bolt > %t.out.txt
6-
// RUN: llvm-objdump -dj .rodata %t.so.bolt >> %t.out.txt
6+
// RUN: llvm-objdump -z -dj .rodata %t.so.bolt >> %t.out.txt
77
// RUN: FileCheck %s --input-file=%t.out.txt
88

99
# CHECK: w func_1

bolt/test/X86/print-only-section.s

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Check that --print-only flag works with sections.
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
6+
# RUN: ld.lld %t.o -o %t.exe
7+
# RUN: llvm-bolt %t.exe -o %t.out --print-cfg --print-only=unused_code 2>&1 \
8+
# RUN: | FileCheck %s
9+
10+
# CHECK: Binary Function "foo"
11+
# CHECK-NOT: Binary Function "_start"
12+
13+
.text
14+
.globl _start
15+
.type _start, %function
16+
_start:
17+
.cfi_startproc
18+
ret
19+
.cfi_endproc
20+
.size _start, .-_start
21+
22+
.section unused_code,"ax",@progbits
23+
.globl foo
24+
.type foo, %function
25+
foo:
26+
.cfi_startproc
27+
ret
28+
.cfi_endproc
29+
.size foo, .-foo
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Test that merge-fdata correctly handles YAML header with an uninitialized
2+
## fields. a.yaml does not have hash-func set and it used to crash merge-fdata.
3+
4+
# REQUIRES: system-linux
5+
6+
# RUN: split-file %s %t
7+
# RUN: not merge-fdata %t/a.yaml %t/b.yaml 2>&1 | FileCheck %s
8+
9+
# CHECK: cannot merge profiles with different hash functions
10+
11+
#--- a.yaml
12+
---
13+
header:
14+
profile-version: 1
15+
binary-name: 'a.out'
16+
binary-build-id: '<unknown>'
17+
profile-flags: [ lbr ]
18+
profile-origin: branch profile reader
19+
profile-events: ''
20+
dfs-order: false
21+
functions:
22+
- name: 'main'
23+
fid: 1
24+
hash: 0x50BBA3441D436491
25+
exec: 1
26+
nblocks: 0
27+
...
28+
#--- b.yaml
29+
---
30+
header:
31+
profile-version: 1
32+
binary-name: 'a.out'
33+
binary-build-id: '<unknown>'
34+
profile-flags: [ lbr ]
35+
profile-origin: branch profile reader
36+
profile-events: ''
37+
dfs-order: false
38+
hash-func: xxh3
39+
functions:
40+
- name: 'main'
41+
fid: 1
42+
hash: 0x50BBA3441D436491
43+
exec: 1
44+
nblocks: 0
45+
...

bolt/tools/merge-fdata/merge-fdata.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ void mergeProfileHeaders(BinaryProfileHeader &MergedHeader,
145145
errs() << "WARNING: merging profiles with different sampling events\n";
146146
MergedHeader.EventNames += "," + Header.EventNames;
147147
}
148+
149+
if (MergedHeader.HashFunction != Header.HashFunction)
150+
report_error("merge conflict",
151+
"cannot merge profiles with different hash functions");
148152
}
149153

150154
void mergeBasicBlockProfile(BinaryBasicBlockProfile &MergedBB,
@@ -386,6 +390,7 @@ int main(int argc, char **argv) {
386390
// Merged information for all functions.
387391
StringMap<BinaryFunctionProfile> MergedBFs;
388392

393+
bool FirstHeader = true;
389394
for (std::string &InputDataFilename : Inputs) {
390395
ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
391396
MemoryBuffer::getFileOrSTDIN(InputDataFilename);
@@ -409,7 +414,12 @@ int main(int argc, char **argv) {
409414
}
410415

411416
// Merge the header.
412-
mergeProfileHeaders(MergedHeader, BP.Header);
417+
if (FirstHeader) {
418+
MergedHeader = BP.Header;
419+
FirstHeader = false;
420+
} else {
421+
mergeProfileHeaders(MergedHeader, BP.Header);
422+
}
413423

414424
// Do the function merge.
415425
for (BinaryFunctionProfile &BF : BP.Functions) {

clang-tools-extra/clang-move/tool/ClangMove.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ int main(int argc, const char **argv) {
199199
for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
200200
OS << " {\n";
201201
OS << " \"FilePath\": \"" << *I << "\",\n";
202-
const auto Entry = FileMgr.getFile(*I);
202+
const auto Entry = FileMgr.getOptionalFileRef(*I);
203203
auto ID = SM.translateFile(*Entry);
204204
std::string Content;
205205
llvm::raw_string_ostream ContentStream(Content);

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

Lines changed: 143 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "UnsafeFunctionsCheck.h"
10+
#include "../utils/OptionsUtils.h"
1011
#include "clang/AST/ASTContext.h"
1112
#include "clang/ASTMatchers/ASTMatchFinder.h"
1213
#include "clang/Lex/PPCallbacks.h"
@@ -18,6 +19,10 @@ using namespace llvm;
1819

1920
namespace clang::tidy::bugprone {
2021

22+
static constexpr llvm::StringLiteral OptionNameCustomFunctions =
23+
"CustomFunctions";
24+
static constexpr llvm::StringLiteral OptionNameReportDefaultFunctions =
25+
"ReportDefaultFunctions";
2126
static constexpr llvm::StringLiteral OptionNameReportMoreUnsafeFunctions =
2227
"ReportMoreUnsafeFunctions";
2328

@@ -26,6 +31,8 @@ static constexpr llvm::StringLiteral FunctionNamesWithAnnexKReplacementId =
2631
static constexpr llvm::StringLiteral FunctionNamesId = "FunctionsNames";
2732
static constexpr llvm::StringLiteral AdditionalFunctionNamesId =
2833
"AdditionalFunctionsNames";
34+
static constexpr llvm::StringLiteral CustomFunctionNamesId =
35+
"CustomFunctionNames";
2936
static constexpr llvm::StringLiteral DeclRefId = "DRE";
3037

3138
static std::optional<std::string>
@@ -127,57 +134,128 @@ static bool isAnnexKAvailable(std::optional<bool> &CacheVar, Preprocessor *PP,
127134
return CacheVar.value();
128135
}
129136

137+
static std::vector<UnsafeFunctionsCheck::CheckedFunction>
138+
parseCheckedFunctions(StringRef Option, ClangTidyContext *Context) {
139+
const std::vector<StringRef> Functions =
140+
utils::options::parseStringList(Option);
141+
std::vector<UnsafeFunctionsCheck::CheckedFunction> Result;
142+
Result.reserve(Functions.size());
143+
144+
for (StringRef Function : Functions) {
145+
if (Function.empty())
146+
continue;
147+
148+
const auto [Name, Rest] = Function.split(',');
149+
const auto [Replacement, Reason] = Rest.split(',');
150+
151+
if (Name.trim().empty()) {
152+
Context->configurationDiag("invalid configuration value for option '%0'; "
153+
"expected the name of an unsafe function")
154+
<< OptionNameCustomFunctions;
155+
continue;
156+
}
157+
158+
Result.push_back(
159+
{Name.trim().str(),
160+
matchers::MatchesAnyListedNameMatcher::NameMatcher(Name.trim()),
161+
Replacement.trim().str(), Reason.trim().str()});
162+
}
163+
164+
return Result;
165+
}
166+
167+
static std::string serializeCheckedFunctions(
168+
const std::vector<UnsafeFunctionsCheck::CheckedFunction> &Functions) {
169+
std::vector<std::string> Result;
170+
Result.reserve(Functions.size());
171+
172+
for (const auto &Entry : Functions) {
173+
if (Entry.Reason.empty())
174+
Result.push_back(Entry.Name + "," + Entry.Replacement);
175+
else
176+
Result.push_back(Entry.Name + "," + Entry.Replacement + "," +
177+
Entry.Reason);
178+
}
179+
180+
return llvm::join(Result, ";");
181+
}
182+
130183
UnsafeFunctionsCheck::UnsafeFunctionsCheck(StringRef Name,
131184
ClangTidyContext *Context)
132185
: ClangTidyCheck(Name, Context),
186+
CustomFunctions(parseCheckedFunctions(
187+
Options.get(OptionNameCustomFunctions, ""), Context)),
188+
ReportDefaultFunctions(
189+
Options.get(OptionNameReportDefaultFunctions, true)),
133190
ReportMoreUnsafeFunctions(
134191
Options.get(OptionNameReportMoreUnsafeFunctions, true)) {}
135192

136193
void UnsafeFunctionsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
194+
Options.store(Opts, OptionNameCustomFunctions,
195+
serializeCheckedFunctions(CustomFunctions));
196+
Options.store(Opts, OptionNameReportDefaultFunctions, ReportDefaultFunctions);
137197
Options.store(Opts, OptionNameReportMoreUnsafeFunctions,
138198
ReportMoreUnsafeFunctions);
139199
}
140200

141201
void UnsafeFunctionsCheck::registerMatchers(MatchFinder *Finder) {
142-
if (getLangOpts().C11) {
143-
// Matching functions with safe replacements only in Annex K.
144-
auto FunctionNamesWithAnnexKReplacementMatcher = hasAnyName(
145-
"::bsearch", "::ctime", "::fopen", "::fprintf", "::freopen", "::fscanf",
146-
"::fwprintf", "::fwscanf", "::getenv", "::gmtime", "::localtime",
147-
"::mbsrtowcs", "::mbstowcs", "::memcpy", "::memmove", "::memset",
148-
"::printf", "::qsort", "::scanf", "::snprintf", "::sprintf", "::sscanf",
149-
"::strcat", "::strcpy", "::strerror", "::strlen", "::strncat",
150-
"::strncpy", "::strtok", "::swprintf", "::swscanf", "::vfprintf",
151-
"::vfscanf", "::vfwprintf", "::vfwscanf", "::vprintf", "::vscanf",
152-
"::vsnprintf", "::vsprintf", "::vsscanf", "::vswprintf", "::vswscanf",
153-
"::vwprintf", "::vwscanf", "::wcrtomb", "::wcscat", "::wcscpy",
154-
"::wcslen", "::wcsncat", "::wcsncpy", "::wcsrtombs", "::wcstok",
155-
"::wcstombs", "::wctomb", "::wmemcpy", "::wmemmove", "::wprintf",
156-
"::wscanf");
202+
if (ReportDefaultFunctions) {
203+
if (getLangOpts().C11) {
204+
// Matching functions with safe replacements only in Annex K.
205+
auto FunctionNamesWithAnnexKReplacementMatcher = hasAnyName(
206+
"::bsearch", "::ctime", "::fopen", "::fprintf", "::freopen",
207+
"::fscanf", "::fwprintf", "::fwscanf", "::getenv", "::gmtime",
208+
"::localtime", "::mbsrtowcs", "::mbstowcs", "::memcpy", "::memmove",
209+
"::memset", "::printf", "::qsort", "::scanf", "::snprintf",
210+
"::sprintf", "::sscanf", "::strcat", "::strcpy", "::strerror",
211+
"::strlen", "::strncat", "::strncpy", "::strtok", "::swprintf",
212+
"::swscanf", "::vfprintf", "::vfscanf", "::vfwprintf", "::vfwscanf",
213+
"::vprintf", "::vscanf", "::vsnprintf", "::vsprintf", "::vsscanf",
214+
"::vswprintf", "::vswscanf", "::vwprintf", "::vwscanf", "::wcrtomb",
215+
"::wcscat", "::wcscpy", "::wcslen", "::wcsncat", "::wcsncpy",
216+
"::wcsrtombs", "::wcstok", "::wcstombs", "::wctomb", "::wmemcpy",
217+
"::wmemmove", "::wprintf", "::wscanf");
218+
Finder->addMatcher(
219+
declRefExpr(to(functionDecl(FunctionNamesWithAnnexKReplacementMatcher)
220+
.bind(FunctionNamesWithAnnexKReplacementId)))
221+
.bind(DeclRefId),
222+
this);
223+
}
224+
225+
// Matching functions with replacements without Annex K.
226+
auto FunctionNamesMatcher =
227+
hasAnyName("::asctime", "asctime_r", "::gets", "::rewind", "::setbuf");
157228
Finder->addMatcher(
158-
declRefExpr(to(functionDecl(FunctionNamesWithAnnexKReplacementMatcher)
159-
.bind(FunctionNamesWithAnnexKReplacementId)))
229+
declRefExpr(
230+
to(functionDecl(FunctionNamesMatcher).bind(FunctionNamesId)))
160231
.bind(DeclRefId),
161232
this);
233+
234+
if (ReportMoreUnsafeFunctions) {
235+
// Matching functions with replacements without Annex K, at user request.
236+
auto AdditionalFunctionNamesMatcher =
237+
hasAnyName("::bcmp", "::bcopy", "::bzero", "::getpw", "::vfork");
238+
Finder->addMatcher(
239+
declRefExpr(to(functionDecl(AdditionalFunctionNamesMatcher)
240+
.bind(AdditionalFunctionNamesId)))
241+
.bind(DeclRefId),
242+
this);
243+
}
162244
}
163245

164-
// Matching functions with replacements without Annex K.
165-
auto FunctionNamesMatcher =
166-
hasAnyName("::asctime", "asctime_r", "::gets", "::rewind", "::setbuf");
167-
Finder->addMatcher(
168-
declRefExpr(to(functionDecl(FunctionNamesMatcher).bind(FunctionNamesId)))
169-
.bind(DeclRefId),
170-
this);
171-
172-
if (ReportMoreUnsafeFunctions) {
173-
// Matching functions with replacements without Annex K, at user request.
174-
auto AdditionalFunctionNamesMatcher =
175-
hasAnyName("::bcmp", "::bcopy", "::bzero", "::getpw", "::vfork");
176-
Finder->addMatcher(
177-
declRefExpr(to(functionDecl(AdditionalFunctionNamesMatcher)
178-
.bind(AdditionalFunctionNamesId)))
179-
.bind(DeclRefId),
180-
this);
246+
if (!CustomFunctions.empty()) {
247+
std::vector<llvm::StringRef> FunctionNames;
248+
FunctionNames.reserve(CustomFunctions.size());
249+
250+
for (const auto &Entry : CustomFunctions)
251+
FunctionNames.push_back(Entry.Name);
252+
253+
auto CustomFunctionsMatcher = matchers::matchesAnyListedName(FunctionNames);
254+
255+
Finder->addMatcher(declRefExpr(to(functionDecl(CustomFunctionsMatcher)
256+
.bind(CustomFunctionNamesId)))
257+
.bind(DeclRefId),
258+
this);
181259
}
182260
}
183261

@@ -186,16 +264,46 @@ void UnsafeFunctionsCheck::check(const MatchFinder::MatchResult &Result) {
186264
const auto *FuncDecl = cast<FunctionDecl>(DeclRef->getDecl());
187265
assert(DeclRef && FuncDecl && "No valid matched node in check()");
188266

267+
// Only one of these are matched at a time.
189268
const auto *AnnexK = Result.Nodes.getNodeAs<FunctionDecl>(
190269
FunctionNamesWithAnnexKReplacementId);
191270
const auto *Normal = Result.Nodes.getNodeAs<FunctionDecl>(FunctionNamesId);
192271
const auto *Additional =
193272
Result.Nodes.getNodeAs<FunctionDecl>(AdditionalFunctionNamesId);
194-
assert((AnnexK || Normal || Additional) && "No valid match category.");
273+
const auto *Custom =
274+
Result.Nodes.getNodeAs<FunctionDecl>(CustomFunctionNamesId);
275+
assert((AnnexK || Normal || Additional || Custom) &&
276+
"No valid match category.");
195277

196278
bool AnnexKIsAvailable =
197279
isAnnexKAvailable(IsAnnexKAvailable, PP, getLangOpts());
198280
StringRef FunctionName = FuncDecl->getName();
281+
282+
if (Custom) {
283+
for (const auto &Entry : CustomFunctions) {
284+
if (Entry.Pattern.match(*FuncDecl)) {
285+
StringRef Reason =
286+
Entry.Reason.empty() ? "is marked as unsafe" : Entry.Reason.c_str();
287+
288+
if (Entry.Replacement.empty()) {
289+
diag(DeclRef->getExprLoc(), "function %0 %1; it should not be used")
290+
<< FuncDecl << Reason << Entry.Replacement
291+
<< DeclRef->getSourceRange();
292+
} else {
293+
diag(DeclRef->getExprLoc(),
294+
"function %0 %1; '%2' should be used instead")
295+
<< FuncDecl << Reason << Entry.Replacement
296+
<< DeclRef->getSourceRange();
297+
}
298+
299+
return;
300+
}
301+
}
302+
303+
llvm_unreachable("No custom function was matched.");
304+
return;
305+
}
306+
199307
const std::optional<std::string> ReplacementFunctionName =
200308
[&]() -> std::optional<std::string> {
201309
if (AnnexK) {

0 commit comments

Comments
 (0)