Skip to content

Commit 77c277e

Browse files
authored
Merge branch 'users/kparzysz/r11-ods-assumes' into users/kparzysz/r12-ods-requires
2 parents 0434e25 + cfef35d commit 77c277e

File tree

1,202 files changed

+74336
-31123
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,202 files changed

+74336
-31123
lines changed

.github/workflows/pr-code-lint.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ jobs:
4747
echo "Changed files:"
4848
echo "$CHANGED_FILES"
4949
50+
# The clang tidy version should always be upgraded to the first version
51+
# of a release cycle (x.1.0) or the last version of a release cycle, or
52+
# if there have been relevant clang-format backports.
5053
- name: Install clang-tidy
5154
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
5255
with:
53-
clang-tidy: 20.1.8
56+
clang-tidy: 21.1.0
5457

5558
- name: Setup Python env
5659
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0

bolt/include/bolt/Core/FunctionLayout.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,31 @@ class FunctionLayout {
232232
return Blocks[Index];
233233
}
234234

235+
/// Return the basic block after the given basic block iterator in the layout
236+
/// or nullptr if the last basic block iterator is given.
237+
const BinaryBasicBlock *getBasicBlockAfter(block_const_iterator BlockIt,
238+
bool IgnoreSplits = true) const;
239+
240+
/// Returns the basic block after the given basic block in the layout or
241+
/// nullptr if the last basic block is given.
242+
///
243+
/// Note: prefer the version that takes the iterator as this function uses
244+
/// linear basic block lookup.
245+
const BinaryBasicBlock *getBasicBlockAfter(const BinaryBasicBlock *BB,
246+
bool IgnoreSplits = true) const;
247+
235248
/// Returns the basic block after the given basic block in the layout or
236249
/// nullptr if the last basic block is given.
250+
///
251+
/// Note: prefer the version that takes the iterator as this function uses
252+
/// linear basic block lookup.
237253
BinaryBasicBlock *getBasicBlockAfter(const BinaryBasicBlock *const BB,
238254
const bool IgnoreSplits = true) {
239255
return const_cast<BinaryBasicBlock *>(
240256
static_cast<const FunctionLayout &>(*this).getBasicBlockAfter(
241257
BB, IgnoreSplits));
242258
}
243259

244-
/// Returns the basic block after the given basic block in the layout or
245-
/// nullptr if the last basic block is given.
246-
const BinaryBasicBlock *getBasicBlockAfter(const BinaryBasicBlock *BB,
247-
bool IgnoreSplits = true) const;
248-
249260
/// True if the layout contains at least two non-empty fragments.
250261
bool isSplit() const;
251262

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,7 +3598,9 @@ void BinaryFunction::fixBranches() {
35983598
auto &MIB = BC.MIB;
35993599
MCContext *Ctx = BC.Ctx.get();
36003600

3601-
for (BinaryBasicBlock *BB : BasicBlocks) {
3601+
for (auto BBI = Layout.block_begin(), BBE = Layout.block_end(); BBI != BBE;
3602+
++BBI) {
3603+
BinaryBasicBlock *BB = *BBI;
36023604
const MCSymbol *TBB = nullptr;
36033605
const MCSymbol *FBB = nullptr;
36043606
MCInst *CondBranch = nullptr;
@@ -3612,7 +3614,7 @@ void BinaryFunction::fixBranches() {
36123614

36133615
// Basic block that follows the current one in the final layout.
36143616
const BinaryBasicBlock *const NextBB =
3615-
Layout.getBasicBlockAfter(BB, /*IgnoreSplits=*/false);
3617+
Layout.getBasicBlockAfter(BBI, /*IgnoreSplits*/ false);
36163618

36173619
if (BB->succ_size() == 1) {
36183620
// __builtin_unreachable() could create a conditional branch that

bolt/lib/Core/FunctionLayout.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,29 @@ void FunctionLayout::clear() {
224224
}
225225

226226
const BinaryBasicBlock *
227-
FunctionLayout::getBasicBlockAfter(const BinaryBasicBlock *BB,
227+
FunctionLayout::getBasicBlockAfter(block_const_iterator BBIter,
228228
bool IgnoreSplits) const {
229-
const block_const_iterator BBPos = find(blocks(), BB);
230-
if (BBPos == block_end())
231-
return nullptr;
232-
233-
const block_const_iterator BlockAfter = std::next(BBPos);
229+
const block_const_iterator BlockAfter = std::next(BBIter);
234230
if (BlockAfter == block_end())
235231
return nullptr;
236232

237233
if (!IgnoreSplits)
238-
if (BlockAfter == getFragment(BB->getFragmentNum()).end())
234+
if (BlockAfter == getFragment((*BBIter)->getFragmentNum()).end())
239235
return nullptr;
240236

241237
return *BlockAfter;
242238
}
243239

240+
const BinaryBasicBlock *
241+
FunctionLayout::getBasicBlockAfter(const BinaryBasicBlock *BB,
242+
bool IgnoreSplits) const {
243+
const block_const_iterator BBPos = find(blocks(), BB);
244+
if (BBPos == block_end())
245+
return nullptr;
246+
247+
return getBasicBlockAfter(BBPos, IgnoreSplits);
248+
}
249+
244250
bool FunctionLayout::isSplit() const {
245251
const unsigned NonEmptyFragCount = llvm::count_if(
246252
fragments(), [](const FunctionFragment &FF) { return !FF.empty(); });

bolt/test/AArch64/unmarked-data.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// RUN: yaml2obj %S/Inputs/unmarked-data.yaml -o %t.exe
44
// RUN: llvm-bolt %t.exe -o %t.bolt --lite=0 --use-old-text=0 2>&1 | FileCheck %s
5-
// CHECK-NOT: BOLT-WARNING
5+
// CHECK-NOT: BOLT-WARNING: unable to disassemble instruction at offset
66
// RUN: llvm-objdump -j .text -d --disassemble-symbols=first,second %t.bolt | FileCheck %s -check-prefix=CHECK-SYMBOL
77
// CHECK-SYMBOL: <first>:
88
// CHECK-SYMBOL: <second>:

bolt/test/X86/dwarf5-dwoid-no-dwoname.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Check that DWARF CU with a valid DWOId but missing a dwo_name is correctly detected.
22
# RUN: rm -rf %t && mkdir -p %t && cd %t
33
# RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %s -split-dwarf-file=main.dwo -o main.o
4-
# RUN: %clang -O3 -g -gdwarf-5 -gsplit-dwarf -Wl,-q %t/main.o -o main.exe
4+
# RUN: %clang %cflags -O3 -g -gdwarf-5 -gsplit-dwarf -Wl,-q %t/main.o -o main.exe
55
# RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -update-debug-sections 2>&1 | FileCheck %s --check-prefix=PRECHECK
66
# PRECHECK: BOLT-ERROR: broken DWARF found in CU at offset 0x3e (DWOId=0x0, missing DW_AT_dwo_name / DW_AT_GNU_dwo_name)
77

clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,12 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
274274
}
275275

276276
Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) {
277+
std::string ResourcePath(CDCtx.OutDirectory + "/html");
277278
for (const auto &FilePath : CDCtx.UserStylesheets)
278-
if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
279+
if (Error Err = copyFile(FilePath, ResourcePath))
279280
return Err;
280281
for (const auto &FilePath : CDCtx.JsScripts)
281-
if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
282+
if (Error Err = copyFile(FilePath, ResourcePath))
282283
return Err;
283284
return Error::success();
284285
}

clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,57 @@
88

99
#include "UseDefaultMemberInitCheck.h"
1010
#include "clang/AST/ASTContext.h"
11+
#include "clang/AST/Expr.h"
1112
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1214
#include "clang/Lex/Lexer.h"
15+
#include "llvm/ADT/TypeSwitch.h"
1316

1417
using namespace clang::ast_matchers;
1518

1619
namespace clang::tidy::modernize {
1720

21+
static bool isExprAllowedInMemberInit(const Expr *E) {
22+
if (!E)
23+
return false;
24+
return llvm::TypeSwitch<const Expr *, bool>(E)
25+
.Case<IntegerLiteral, FloatingLiteral, CXXBoolLiteralExpr,
26+
CXXNullPtrLiteralExpr, CharacterLiteral, StringLiteral>(
27+
[](const auto *) { return true; })
28+
.Case<ImplicitValueInitExpr>([](const auto *) { return true; })
29+
.Case<ParenExpr>([](const ParenExpr *PE) {
30+
return isExprAllowedInMemberInit(PE->getSubExpr());
31+
})
32+
.Case<UnaryOperator>([](const UnaryOperator *UO) {
33+
return isExprAllowedInMemberInit(UO->getSubExpr());
34+
})
35+
.Case<BinaryOperator>([](const BinaryOperator *BO) {
36+
return isExprAllowedInMemberInit(BO->getLHS()) &&
37+
isExprAllowedInMemberInit(BO->getRHS());
38+
})
39+
.Case<CastExpr>([](const CastExpr *CE) {
40+
return isExprAllowedInMemberInit(CE->getSubExpr());
41+
})
42+
.Case<DeclRefExpr>([](const DeclRefExpr *DRE) {
43+
if (const ValueDecl *D = DRE->getDecl()) {
44+
if (isa<EnumConstantDecl>(D))
45+
return true;
46+
if (const auto *VD = dyn_cast<VarDecl>(D))
47+
return VD->isConstexpr() || VD->getStorageClass() == SC_Static;
48+
}
49+
return false;
50+
})
51+
.Default(false);
52+
}
53+
1854
namespace {
55+
1956
AST_MATCHER_P(InitListExpr, initCountIs, unsigned, N) {
2057
return Node.getNumInits() == N;
2158
}
59+
60+
AST_MATCHER(Expr, allowedInitExpr) { return isExprAllowedInMemberInit(&Node); }
61+
2262
} // namespace
2363

2464
static StringRef getValueOfValueInit(const QualType InitType) {
@@ -206,30 +246,10 @@ void UseDefaultMemberInitCheck::storeOptions(
206246
}
207247

208248
void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
209-
auto NumericLiteral = anyOf(integerLiteral(), floatLiteral());
210-
auto UnaryNumericLiteral = unaryOperator(hasAnyOperatorName("+", "-"),
211-
hasUnaryOperand(NumericLiteral));
212-
213-
auto ConstExprRef = varDecl(anyOf(isConstexpr(), isStaticStorageClass()));
214-
auto ImmutableRef =
215-
declRefExpr(to(decl(anyOf(enumConstantDecl(), ConstExprRef))));
216-
217-
auto BinaryNumericExpr = binaryOperator(
218-
hasOperands(anyOf(NumericLiteral, ImmutableRef, binaryOperator()),
219-
anyOf(NumericLiteral, ImmutableRef, binaryOperator())));
220-
221-
auto InitBase =
222-
anyOf(stringLiteral(), characterLiteral(), NumericLiteral,
223-
UnaryNumericLiteral, cxxBoolLiteral(), cxxNullPtrLiteralExpr(),
224-
implicitValueInitExpr(), ImmutableRef, BinaryNumericExpr);
225-
226-
auto ExplicitCastExpr = castExpr(hasSourceExpression(InitBase));
227-
auto InitMatcher = anyOf(InitBase, ExplicitCastExpr);
228-
229-
auto Init =
230-
anyOf(initListExpr(anyOf(allOf(initCountIs(1), hasInit(0, InitMatcher)),
231-
initCountIs(0), hasType(arrayType()))),
232-
InitBase, ExplicitCastExpr);
249+
auto Init = anyOf(
250+
initListExpr(anyOf(allOf(initCountIs(1), hasInit(0, allowedInitExpr())),
251+
initCountIs(0), hasType(arrayType()))),
252+
allowedInitExpr());
233253

234254
Finder->addMatcher(
235255
cxxConstructorDecl(forEachConstructorInitializer(

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ Changes in existing checks
301301
uses of non-standard ``enable_if`` with a signature different from
302302
``std::enable_if`` (such as ``boost::enable_if``).
303303

304+
- Improved :doc:`modernize-use-default-member-init
305+
<clang-tidy/checks/modernize/use-default-member-init>` check to
306+
enhance the robustness of the member initializer detection.
307+
304308
- Improved :doc:`modernize-use-designated-initializers
305309
<clang-tidy/checks/modernize/use-designated-initializers>` check to
306310
suggest using designated initializers for aliased aggregate types.

clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@ namespace std {
1414
static constexpr bool value = true;
1515
};
1616

17+
template <typename T, typename U>
18+
static constexpr bool is_same_v = is_same<T, U>::value; // NOLINT
19+
1720
template<bool, typename T = void>
1821
struct enable_if {
1922
using type = T;
2023
};
2124

25+
template <bool B, typename T = void>
26+
using enable_if_t = typename enable_if<B, T>::type; // NOLINT
27+
28+
template <typename T>
29+
struct remove_reference {
30+
using type = T;
31+
};
32+
33+
template <typename T>
34+
using remove_reference_t = typename remove_reference<T>::type; // NOLINT
35+
2236
template <typename...>
2337
struct common_type {
2438
using type = int;
@@ -126,3 +140,13 @@ namespace my_std = std;
126140
using Alias = my_std::add_const<bool>::type;
127141
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use c++14 style type templates
128142
// CHECK-FIXES: using Alias = my_std::add_const_t<bool>;
143+
144+
template <typename T>
145+
struct ImplicitlyInstantiatedConstructor {
146+
template <typename U, typename = std::enable_if_t<std::is_same_v<U, T>>>
147+
ImplicitlyInstantiatedConstructor(U) {}
148+
};
149+
150+
const ImplicitlyInstantiatedConstructor<int> ImplicitInstantiation(std::remove_reference<int>::type(123));
151+
// CHECK-MESSAGES: :[[@LINE-1]]:68: warning: use c++14 style type templates
152+
// CHECK-FIXES: const ImplicitlyInstantiatedConstructor<int> ImplicitInstantiation(std::remove_reference_t<int>(123));

0 commit comments

Comments
 (0)