Skip to content

Commit ebf12ac

Browse files
Merge branch 'llvm:main' into gh-101657
2 parents 16edbe1 + 21ff45d commit ebf12ac

File tree

743 files changed

+36129
-25120
lines changed

Some content is hidden

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

743 files changed

+36129
-25120
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN cmake -B ./build -G Ninja ./llvm \
3232
-DLLVM_ENABLE_RUNTIMES="compiler-rt" \
3333
-DCMAKE_INSTALL_PREFIX="$LLVM_SYSROOT" \
3434
-DLLVM_ENABLE_PROJECTS="bolt;clang;lld;clang-tools-extra" \
35-
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format;scan-build" \
35+
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format;scan-build;llvm-symbolizer" \
3636
-DCLANG_DEFAULT_LINKER="lld"
3737

3838
RUN ninja -C ./build stage2-clang-bolt stage2-install-distribution && ninja -C ./build install-distribution

.mailmap

Lines changed: 2 additions & 1 deletion

bolt/lib/Core/BinaryContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ bool BinaryContext::analyzeJumpTable(const uint64_t Address,
663663
const BinaryFunction *TargetBF = getBinaryFunctionContainingAddress(Value);
664664
if (!TargetBF || !areRelatedFragments(TargetBF, &BF)) {
665665
LLVM_DEBUG(printEntryDiagnostics(dbgs(), TargetBF));
666+
(void)printEntryDiagnostics;
666667
break;
667668
}
668669

@@ -843,6 +844,7 @@ BinaryContext::getOrCreateJumpTable(BinaryFunction &Function, uint64_t Address,
843844
&Function, std::placeholders::_1);
844845
assert(llvm::all_of(JT->Parents, isSibling) &&
845846
"cannot re-use jump table of a different function");
847+
(void)isSibling;
846848
if (opts::Verbosity > 2) {
847849
this->outs() << "BOLT-INFO: multiple fragments access the same jump table"
848850
<< ": " << *JT->Parents[0] << "; " << Function << '\n';

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,18 +871,27 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
871871

872872
BinaryContext &BC = BF.getBinaryContext();
873873

874-
if (!BF.isSimple())
875-
return std::nullopt;
876-
877-
assert(BF.hasCFG() && "can only record traces in CFG state");
878-
879874
// Offsets of the trace within this function.
880875
const uint64_t From = FirstLBR.To - BF.getAddress();
881876
const uint64_t To = SecondLBR.From - BF.getAddress();
882877

883878
if (From > To)
884879
return std::nullopt;
885880

881+
// Accept fall-throughs inside pseudo functions (PLT/thunks).
882+
// This check has to be above BF.empty as pseudo functions would pass it:
883+
// pseudo => ignored => CFG not built => empty.
884+
// If we return nullopt, trace would be reported as mismatching disassembled
885+
// function contents which it is not. To avoid this, return an empty
886+
// fall-through list instead.
887+
if (BF.isPseudo())
888+
return Branches;
889+
890+
if (!BF.isSimple())
891+
return std::nullopt;
892+
893+
assert(BF.hasCFG() && "can only record traces in CFG state");
894+
886895
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(From);
887896
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset(To);
888897

bolt/test/X86/callcont-fallthru.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# RUN: link_fdata %s %t %t.pa3 PREAGG3
1010
# RUN: link_fdata %s %t %t.pat PREAGGT1
1111
# RUN: link_fdata %s %t %t.pat2 PREAGGT2
12+
# RUN: link_fdata %s %t %t.patplt PREAGGPLT
1213

1314
## Check normal case: fallthrough is not LP or secondary entry.
1415
# RUN: llvm-strip --strip-unneeded %t -o %t.strip
@@ -42,6 +43,12 @@
4243
# RUN: llvm-bolt %t.strip --pa -p %t.pat2 -o %t.out \
4344
# RUN: --print-cfg --print-only=main | FileCheck %s --check-prefix=CHECK3
4445

46+
## Check pre-aggregated traces don't report zero-sized PLT fall-through as
47+
## invalid trace
48+
# RUN: llvm-bolt %t.strip --pa -p %t.patplt -o %t.out | FileCheck %s \
49+
# RUN: --check-prefix=CHECK-PLT
50+
# CHECK-PLT: traces mismatching disassembled function contents: 0
51+
4552
.globl foo
4653
.type foo, %function
4754
foo:
@@ -65,7 +72,10 @@ main:
6572
movl $0x0, -0x4(%rbp)
6673
movl %edi, -0x8(%rbp)
6774
movq %rsi, -0x10(%rbp)
75+
Ltmp0_br:
6876
callq puts@PLT
77+
## Check PLT traces are accepted
78+
# PREAGGPLT: T #Ltmp0_br# #puts@plt# #puts@plt# 3
6979
## Target is an external-origin call continuation
7080
# PREAGG1: B X:0 #Ltmp1# 2 0
7181
# PREAGGT1: T X:0 #Ltmp1# #Ltmp4_br# 2

bolt/test/link_fdata.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import argparse
11+
import os
1112
import subprocess
1213
import sys
1314
import re
@@ -84,8 +85,16 @@
8485
exit("ERROR: unexpected input:\n%s" % line)
8586

8687
# Read nm output: <symbol value> <symbol type> <symbol name>
88+
is_llvm_nm = os.path.basename(args.nmtool) == "llvm-nm"
8789
nm_output = subprocess.run(
88-
[args.nmtool, "--defined-only", args.objfile], text=True, capture_output=True
90+
[
91+
args.nmtool,
92+
"--defined-only",
93+
"--special-syms" if is_llvm_nm else "--synthetic",
94+
args.objfile,
95+
],
96+
text=True,
97+
capture_output=True,
8998
).stdout
9099
# Populate symbol map
91100
symbols = {}

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

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

99
#include "UnintendedCharOstreamOutputCheck.h"
10+
#include "../utils/Matchers.h"
11+
#include "../utils/OptionsUtils.h"
1012
#include "clang/AST/Type.h"
1113
#include "clang/ASTMatchers/ASTMatchFinder.h"
1214
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -35,10 +37,14 @@ AST_MATCHER(Type, isChar) {
3537

3638
UnintendedCharOstreamOutputCheck::UnintendedCharOstreamOutputCheck(
3739
StringRef Name, ClangTidyContext *Context)
38-
: ClangTidyCheck(Name, Context), CastTypeName(Options.get("CastTypeName")) {
39-
}
40+
: ClangTidyCheck(Name, Context),
41+
AllowedTypes(utils::options::parseStringList(
42+
Options.get("AllowedTypes", "unsigned char;signed char"))),
43+
CastTypeName(Options.get("CastTypeName")) {}
4044
void UnintendedCharOstreamOutputCheck::storeOptions(
4145
ClangTidyOptions::OptionMap &Opts) {
46+
Options.store(Opts, "AllowedTypes",
47+
utils::options::serializeStringList(AllowedTypes));
4248
if (CastTypeName.has_value())
4349
Options.store(Opts, "CastTypeName", CastTypeName.value());
4450
}
@@ -50,13 +56,20 @@ void UnintendedCharOstreamOutputCheck::registerMatchers(MatchFinder *Finder) {
5056
// with char / unsigned char / signed char
5157
classTemplateSpecializationDecl(
5258
hasTemplateArgument(0, refersToType(isChar()))));
59+
auto IsDeclRefExprFromAllowedTypes = declRefExpr(to(varDecl(
60+
hasType(matchers::matchesAnyListedTypeName(AllowedTypes, false)))));
61+
auto IsExplicitCastExprFromAllowedTypes = explicitCastExpr(hasDestinationType(
62+
matchers::matchesAnyListedTypeName(AllowedTypes, false)));
5363
Finder->addMatcher(
5464
cxxOperatorCallExpr(
5565
hasOverloadedOperatorName("<<"),
5666
hasLHS(hasType(hasUnqualifiedDesugaredType(
5767
recordType(hasDeclaration(cxxRecordDecl(
5868
anyOf(BasicOstream, isDerivedFrom(BasicOstream)))))))),
59-
hasRHS(hasType(hasUnqualifiedDesugaredType(isNumericChar()))))
69+
hasRHS(expr(hasType(hasUnqualifiedDesugaredType(isNumericChar())),
70+
unless(ignoringParenImpCasts(
71+
anyOf(IsDeclRefExprFromAllowedTypes,
72+
IsExplicitCastExprFromAllowedTypes))))))
6073
.bind("x"),
6174
this);
6275
}

clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class UnintendedCharOstreamOutputCheck : public ClangTidyCheck {
3030
}
3131

3232
private:
33+
const std::vector<StringRef> AllowedTypes;
3334
const std::optional<StringRef> CastTypeName;
3435
};
3536

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ bool NotIdenticalStatementsPredicate::operator()(
1818
}
1919

2020
MatchesAnyListedTypeNameMatcher::MatchesAnyListedTypeNameMatcher(
21-
llvm::ArrayRef<StringRef> NameList)
22-
: NameMatchers(NameList.begin(), NameList.end()) {}
21+
llvm::ArrayRef<StringRef> NameList, bool CanonicalTypes)
22+
: NameMatchers(NameList.begin(), NameList.end()),
23+
CanonicalTypes(CanonicalTypes) {}
2324

2425
MatchesAnyListedTypeNameMatcher::~MatchesAnyListedTypeNameMatcher() = default;
2526

@@ -32,7 +33,7 @@ bool MatchesAnyListedTypeNameMatcher::matches(
3233

3334
PrintingPolicy PrintingPolicyWithSuppressedTag(
3435
Finder->getASTContext().getLangOpts());
35-
PrintingPolicyWithSuppressedTag.PrintCanonicalTypes = true;
36+
PrintingPolicyWithSuppressedTag.PrintCanonicalTypes = CanonicalTypes;
3637
PrintingPolicyWithSuppressedTag.SuppressElaboration = true;
3738
PrintingPolicyWithSuppressedTag.SuppressScope = false;
3839
PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;

clang-tools-extra/clang-tidy/utils/Matchers.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,28 @@ AST_MATCHER_P(Stmt, isStatementIdenticalToBoundNode, std::string, ID) {
172172
class MatchesAnyListedTypeNameMatcher
173173
: public ast_matchers::internal::MatcherInterface<QualType> {
174174
public:
175-
explicit MatchesAnyListedTypeNameMatcher(llvm::ArrayRef<StringRef> NameList);
175+
explicit MatchesAnyListedTypeNameMatcher(llvm::ArrayRef<StringRef> NameList,
176+
bool CanonicalTypes);
176177
~MatchesAnyListedTypeNameMatcher() override;
177178
bool matches(
178179
const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder,
179180
ast_matchers::internal::BoundNodesTreeBuilder *Builder) const override;
180181

181182
private:
182183
std::vector<llvm::Regex> NameMatchers;
184+
bool CanonicalTypes;
183185
};
184186

185187
// Returns a matcher that matches QualType against a list of provided regular.
186188
inline ::clang::ast_matchers::internal::Matcher<QualType>
187-
matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList) {
189+
matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList,
190+
bool CanonicalTypes) {
188191
return ::clang::ast_matchers::internal::makeMatcher(
189-
new MatchesAnyListedTypeNameMatcher(NameList));
192+
new MatchesAnyListedTypeNameMatcher(NameList, CanonicalTypes));
193+
}
194+
inline ::clang::ast_matchers::internal::Matcher<QualType>
195+
matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList) {
196+
return matchesAnyListedTypeName(NameList, true);
190197
}
191198

192199
} // namespace clang::tidy::matchers

0 commit comments

Comments
 (0)