Skip to content

Commit 925c895

Browse files
authored
Merge branch 'llvm:main' into main
2 parents 2f18d5e + 195d8ac commit 925c895

File tree

1,025 files changed

+27156
-38782
lines changed

Some content is hidden

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

1,025 files changed

+27156
-38782
lines changed

.github/workflows/release-doxygen.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ jobs:
5656
pip3 install --user -r ./llvm/docs/requirements.txt
5757
5858
- name: Build Doxygen
59-
env:
60-
GITHUB_TOKEN: ${{ github.token }}
6159
run: |
6260
./llvm/utils/release/build-docs.sh -release "${{ inputs.release-version }}" -no-sphinx
6361
6462
- name: Upload Doxygen
6563
if: env.upload
64+
env:
65+
GITHUB_TOKEN: ${{ github.token }}
6666
run: |
6767
./llvm/utils/release/github-upload-release.py --token "$GITHUB_TOKEN" --release "${{ inputs.release-version }}" --user "${{ github.actor }}" upload --files ./*doxygen*.tar.xz

.github/workflows/release-tasks.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Release Task
22

33
permissions:
4-
contents: write
4+
contents: read
55

66
on:
77
push:
@@ -27,6 +27,8 @@ jobs:
2727
release-create:
2828
name: Create a New Release
2929
runs-on: ubuntu-latest
30+
permissions:
31+
contents: write # For creating the release.
3032
needs: validate-tag
3133

3234
steps:
@@ -55,6 +57,8 @@ jobs:
5557

5658
release-doxygen:
5759
name: Build and Upload Release Doxygen
60+
permissions:
61+
contents: write
5862
needs:
5963
- validate-tag
6064
- release-create
@@ -72,6 +76,8 @@ jobs:
7276

7377
release-binaries:
7478
name: Build Release Binaries
79+
permissions:
80+
contents: write
7581
needs:
7682
- validate-tag
7783
- release-create

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,8 @@ class BinaryFunction {
930930
return const_cast<BinaryFunction *>(this)->getInstructionAtOffset(Offset);
931931
}
932932

933+
std::optional<MCInst> disassembleInstructionAtOffset(uint64_t Offset) const;
934+
933935
/// Return offset for the first instruction. If there is data at the
934936
/// beginning of a function then offset of the first instruction could
935937
/// be different from 0

bolt/include/bolt/Passes/IndirectCallPromotion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class IndirectCallPromotion : public BinaryFunctionPass {
104104
struct Location {
105105
MCSymbol *Sym{nullptr};
106106
uint64_t Addr{0};
107-
bool isValid() const { return Sym || (!Sym && Addr != 0); }
107+
bool isValid() const { return Sym || Addr != 0; }
108108
Location() {}
109109
explicit Location(MCSymbol *Sym) : Sym(Sym) {}
110110
explicit Location(uint64_t Addr) : Addr(Addr) {}

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,21 @@ void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction,
11671167
}
11681168
}
11691169

1170+
std::optional<MCInst>
1171+
BinaryFunction::disassembleInstructionAtOffset(uint64_t Offset) const {
1172+
assert(CurrentState == State::Empty && "Function should not be disassembled");
1173+
assert(Offset < MaxSize && "Invalid offset");
1174+
ErrorOr<ArrayRef<unsigned char>> FunctionData = getData();
1175+
assert(FunctionData && "Cannot get function as data");
1176+
MCInst Instr;
1177+
uint64_t InstrSize = 0;
1178+
const uint64_t InstrAddress = getAddress() + Offset;
1179+
if (BC.DisAsm->getInstruction(Instr, InstrSize, FunctionData->slice(Offset),
1180+
InstrAddress, nulls()))
1181+
return Instr;
1182+
return std::nullopt;
1183+
}
1184+
11701185
Error BinaryFunction::disassemble() {
11711186
NamedRegionTimer T("disassemble", "Disassemble function", "buildfuncs",
11721187
"Build Binary Functions", opts::TimeBuild);

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,19 @@ bool DataAggregator::doInterBranch(BinaryFunction *FromFunc,
773773

774774
bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
775775
uint64_t Mispreds) {
776+
bool IsReturn = false;
776777
auto handleAddress = [&](uint64_t &Addr, bool IsFrom) -> BinaryFunction * {
777778
if (BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr)) {
778779
Addr -= Func->getAddress();
780+
if (IsFrom) {
781+
auto checkReturn = [&](auto MaybeInst) {
782+
IsReturn = MaybeInst && BC->MIB->isReturn(*MaybeInst);
783+
};
784+
if (Func->hasInstructions())
785+
checkReturn(Func->getInstructionAtOffset(Addr));
786+
else
787+
checkReturn(Func->disassembleInstructionAtOffset(Addr));
788+
}
779789

780790
if (BAT)
781791
Addr = BAT->translate(Func->getAddress(), Addr, IsFrom);
@@ -792,6 +802,9 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
792802
};
793803

794804
BinaryFunction *FromFunc = handleAddress(From, /*IsFrom=*/true);
805+
// Ignore returns.
806+
if (IsReturn)
807+
return true;
795808
BinaryFunction *ToFunc = handleAddress(To, /*IsFrom=*/false);
796809
if (!FromFunc && !ToFunc)
797810
return false;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.globl main
2+
.type main, %function
3+
main:
4+
.cfi_startproc
5+
cmpq $0x3, %rdi
6+
jae .L4
7+
cmpq $0x1, %rdi
8+
jne .L4
9+
mov .Ljt_pic+8(%rip), %rax
10+
lea .Ljt_pic(%rip), %rdx
11+
add %rdx, %rax
12+
jmpq *%rax
13+
.L1:
14+
movq $0x1, %rax
15+
jmp .L5
16+
.L2:
17+
movq $0x0, %rax
18+
jmp .L5
19+
.L3:
20+
movq $0x2, %rax
21+
jmp .L5
22+
.L4:
23+
mov $0x3, %rax
24+
.L5:
25+
retq
26+
.cfi_endproc
27+
28+
.section .rodata
29+
.align 16
30+
.Ljt_pic:
31+
.long .L1 - .Ljt_pic
32+
.long .L2 - .Ljt_pic
33+
.long .L3 - .Ljt_pic
34+
.long .L4 - .Ljt_pic
35+

bolt/test/X86/bolt-address-translation-yaml.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o /dev/null
1313
RUN: FileCheck --input-file %t.yaml-fdata --check-prefix YAML-BAT-CHECK %s
1414

1515
# Test resulting YAML profile with the original binary (no-stale mode)
16-
RUN: llvm-bolt %t.exe -data %t.yaml -o %t.null -dyno-stats \
16+
RUN: llvm-bolt %t.exe -data %t.yaml -o %t.null -dyno-stats 2>&1 \
1717
RUN: | FileCheck --check-prefix CHECK-BOLT-YAML %s
1818

1919
WRITE-BAT-CHECK: BOLT-INFO: Wrote 5 BAT maps
@@ -63,7 +63,8 @@ YAML-BAT-CHECK-NEXT: blocks:
6363
YAML-BAT-CHECK: - bid: 1
6464
YAML-BAT-CHECK-NEXT: insns: [[#]]
6565
YAML-BAT-CHECK-NEXT: hash: 0xD70DC695320E0010
66-
YAML-BAT-CHECK-NEXT: succ: {{.*}} { bid: 2, cnt: [[#]] }
66+
YAML-BAT-CHECK-NEXT: succ: {{.*}} { bid: 2, cnt: [[#]]
6767

6868
CHECK-BOLT-YAML: pre-processing profile using YAML profile reader
6969
CHECK-BOLT-YAML-NEXT: 5 out of 16 functions in the binary (31.2%) have non-empty execution profile
70+
CHECK-BOLT-YAML-NOT: invalid (possibly stale) profile
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Verify that BOLT detects fixed destination of indirect jump for PIC
2+
# case.
3+
4+
XFAIL: *
5+
6+
RUN: %clang %cflags -no-pie %S/Inputs/jump-table-fixed-ref-pic.s -Wl,-q -o %t
7+
RUN: llvm-bolt %t --relocs -o %t.null 2>&1 | FileCheck %s
8+
9+
CHECK: BOLT-INFO: fixed indirect branch detected in main

clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "SignedBitwiseCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/ASTMatchers/ASTMatchers.h"
1213

1314
using namespace clang::ast_matchers;
1415
using namespace clang::ast_matchers::internal;
@@ -29,8 +30,8 @@ void SignedBitwiseCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2930
void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
3031
const auto SignedIntegerOperand =
3132
(IgnorePositiveIntegerLiterals
32-
? expr(ignoringImpCasts(hasType(isSignedInteger())),
33-
unless(integerLiteral()))
33+
? expr(ignoringImpCasts(
34+
allOf(hasType(isSignedInteger()), unless(integerLiteral()))))
3435
: expr(ignoringImpCasts(hasType(isSignedInteger()))))
3536
.bind("signed-operand");
3637

clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ void StaticAccessedThroughInstanceCheck::check(
5959

6060
const Expr *BaseExpr = MemberExpression->getBase();
6161

62-
// Do not warn for overloaded -> operators.
63-
if (isa<CXXOperatorCallExpr>(BaseExpr))
64-
return;
65-
6662
const QualType BaseType =
6763
BaseExpr->getType()->isPointerType()
6864
? BaseExpr->getType()->getPointeeType().getUnqualifiedType()
@@ -89,17 +85,30 @@ void StaticAccessedThroughInstanceCheck::check(
8985
return;
9086

9187
SourceLocation MemberExprStartLoc = MemberExpression->getBeginLoc();
92-
auto Diag =
93-
diag(MemberExprStartLoc, "static member accessed through instance");
94-
95-
if (BaseExpr->HasSideEffects(*AstContext) ||
96-
getNameSpecifierNestingLevel(BaseType) > NameSpecifierNestingThreshold)
97-
return;
88+
auto CreateFix = [&] {
89+
return FixItHint::CreateReplacement(
90+
CharSourceRange::getCharRange(MemberExprStartLoc,
91+
MemberExpression->getMemberLoc()),
92+
BaseTypeName + "::");
93+
};
94+
95+
{
96+
auto Diag =
97+
diag(MemberExprStartLoc, "static member accessed through instance");
98+
99+
if (getNameSpecifierNestingLevel(BaseType) > NameSpecifierNestingThreshold)
100+
return;
101+
102+
if (!BaseExpr->HasSideEffects(*AstContext,
103+
/* IncludePossibleEffects =*/true)) {
104+
Diag << CreateFix();
105+
return;
106+
}
107+
}
98108

99-
Diag << FixItHint::CreateReplacement(
100-
CharSourceRange::getCharRange(MemberExprStartLoc,
101-
MemberExpression->getMemberLoc()),
102-
BaseTypeName + "::");
109+
diag(MemberExprStartLoc, "member base expression may carry some side effects",
110+
DiagnosticIDs::Level::Note)
111+
<< BaseExpr->getSourceRange() << CreateFix();
103112
}
104113

105114
} // namespace clang::tidy::readability

clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,43 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "StringCompareCheck.h"
10-
#include "../utils/FixItHintUtils.h"
10+
#include "../utils/OptionsUtils.h"
1111
#include "clang/AST/ASTContext.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1314
#include "clang/Tooling/FixIt.h"
15+
#include "llvm/ADT/StringRef.h"
1416

1517
using namespace clang::ast_matchers;
18+
namespace optutils = clang::tidy::utils::options;
1619

1720
namespace clang::tidy::readability {
1821

1922
static const StringRef CompareMessage = "do not use 'compare' to test equality "
2023
"of strings; use the string equality "
2124
"operator instead";
2225

26+
static const StringRef DefaultStringLikeClasses = "::std::basic_string;"
27+
"::std::basic_string_view";
28+
29+
StringCompareCheck::StringCompareCheck(StringRef Name,
30+
ClangTidyContext *Context)
31+
: ClangTidyCheck(Name, Context),
32+
StringLikeClasses(optutils::parseStringList(
33+
Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
34+
35+
void StringCompareCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
36+
Options.store(Opts, "StringLikeClasses",
37+
optutils::serializeStringList(StringLikeClasses));
38+
}
39+
2340
void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
41+
if (StringLikeClasses.empty()) {
42+
return;
43+
}
2444
const auto StrCompare = cxxMemberCallExpr(
25-
callee(cxxMethodDecl(hasName("compare"),
26-
ofClass(classTemplateSpecializationDecl(
27-
hasName("::std::basic_string"))))),
45+
callee(cxxMethodDecl(hasName("compare"), ofClass(cxxRecordDecl(hasAnyName(
46+
StringLikeClasses))))),
2847
hasArgument(0, expr().bind("str2")), argumentCountIs(1),
2948
callee(memberExpr().bind("str1")));
3049

clang-tools-extra/clang-tidy/readability/StringCompareCheck.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STRINGCOMPARECHECK_H
1111

1212
#include "../ClangTidyCheck.h"
13+
#include <vector>
1314

1415
namespace clang::tidy::readability {
1516

@@ -20,13 +21,18 @@ namespace clang::tidy::readability {
2021
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/string-compare.html
2122
class StringCompareCheck : public ClangTidyCheck {
2223
public:
23-
StringCompareCheck(StringRef Name, ClangTidyContext *Context)
24-
: ClangTidyCheck(Name, Context) {}
24+
StringCompareCheck(StringRef Name, ClangTidyContext *Context);
25+
2526
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2627
return LangOpts.CPlusPlus;
2728
}
29+
2830
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2931
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33+
34+
private:
35+
const std::vector<StringRef> StringLikeClasses;
3036
};
3137

3238
} // namespace clang::tidy::readability

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ Changes in existing checks
259259
- Improved :doc:`google-runtime-int <clang-tidy/checks/google/runtime-int>`
260260
check performance through optimizations.
261261

262+
- Improved :doc:`hicpp-signed-bitwise <clang-tidy/checks/hicpp/signed-bitwise>`
263+
check by ignoring false positives involving positive integer literals behind
264+
implicit casts when `IgnorePositiveIntegerLiterals` is enabled.
265+
262266
- Improved :doc:`hicpp-ignored-remove-result <clang-tidy/checks/hicpp/ignored-remove-result>`
263267
check by ignoring other functions with same prefixes as the target specific
264268
functions.
@@ -348,11 +352,21 @@ Changes in existing checks
348352
<clang-tidy/checks/readability/redundant-inline-specifier>` check to properly
349353
emit warnings for static data member with an in-class initializer.
350354

355+
- Improved :doc:`readability-static-accessed-through-instance
356+
<clang-tidy/checks/readability/static-accessed-through-instance>` check to
357+
support calls to overloaded operators as base expression and provide fixes to
358+
expressions with side-effects.
359+
351360
- Improved :doc:`readability-static-definition-in-anonymous-namespace
352361
<clang-tidy/checks/readability/static-definition-in-anonymous-namespace>`
353362
check by resolving fix-it overlaps in template code by disregarding implicit
354363
instances.
355364

365+
- Improved :doc:`readability-string-compare
366+
<clang-tidy/checks/readability/string-compare>` check to also detect
367+
usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
368+
to detect usages of ``compare`` method in custom string-like classes.
369+
356370
Removed checks
357371
^^^^^^^^^^^^^^
358372

clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ is changed to:
3535
C::E1;
3636
C::E2;
3737
38+
The `--fix` commandline option provides default support for safe fixes, whereas
39+
`--fix-notes` enables fixes that may replace expressions with side effects,
40+
potentially altering the program's behavior.

0 commit comments

Comments
 (0)