Skip to content

Commit f5c348e

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into mlir-rewriter-ip
2 parents beab53d + 80beefa commit f5c348e

File tree

304 files changed

+55829
-47474
lines changed

Some content is hidden

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

304 files changed

+55829
-47474
lines changed

bolt/lib/Core/GDBIndex.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,19 @@ void GDBIndex::updateGdbIndexSection(
100100
Data += SymbolTableOffset - CUTypesOffset;
101101

102102
// Calculate the size of the new address table.
103+
const auto IsValidAddressRange = [](const DebugAddressRange &Range) {
104+
return Range.HighPC > Range.LowPC;
105+
};
106+
103107
uint32_t NewAddressTableSize = 0;
104108
for (const auto &CURangesPair : ARangesSectionWriter.getCUAddressRanges()) {
105109
const SmallVector<DebugAddressRange, 2> &Ranges = CURangesPair.second;
106-
NewAddressTableSize += Ranges.size() * 20;
110+
NewAddressTableSize +=
111+
llvm::count_if(Ranges,
112+
[&IsValidAddressRange](const DebugAddressRange &Range) {
113+
return IsValidAddressRange(Range);
114+
}) *
115+
20;
107116
}
108117

109118
// Difference between old and new table (and section) sizes.
@@ -201,10 +210,15 @@ void GDBIndex::updateGdbIndexSection(
201210
const uint32_t UpdatedCUIndex = RemapCUIndex(OriginalCUIndex);
202211
const DebugAddressRangesVector &Ranges = CURangesPair.second;
203212
for (const DebugAddressRange &Range : Ranges) {
204-
write64le(Buffer, Range.LowPC);
205-
write64le(Buffer + 8, Range.HighPC);
206-
write32le(Buffer + 16, UpdatedCUIndex);
207-
Buffer += 20;
213+
// Don't emit ranges that break gdb,
214+
// https://sourceware.org/bugzilla/show_bug.cgi?id=33247.
215+
// We've seen [0, 0) ranges here, for instance.
216+
if (IsValidAddressRange(Range)) {
217+
write64le(Buffer, Range.LowPC);
218+
write64le(Buffer + 8, Range.HighPC);
219+
write32le(Buffer + 16, UpdatedCUIndex);
220+
Buffer += 20;
221+
}
208222
}
209223
}
210224

bolt/lib/Target/AArch64/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ add_llvm_library(LLVMBOLTTargetAArch64
2828
AArch64CommonTableGen
2929
)
3030

31-
target_link_libraries(LLVMBOLTTargetAArch64 PRIVATE LLVMBOLTCore)
31+
target_link_libraries(LLVMBOLTTargetAArch64 PRIVATE LLVMBOLTCore LLVMBOLTUtils)
3232

3333
include_directories(
3434
${LLVM_MAIN_SRC_DIR}/lib/Target/AArch64

clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import json
2727
import multiprocessing
2828
import os
29-
import Queue
29+
from queue import Queue
3030
import shutil
3131
import subprocess
3232
import sys
@@ -105,7 +105,7 @@ def main():
105105

106106
try:
107107
# Spin up a bunch of tidy-launching threads.
108-
queue = Queue.Queue(max_task)
108+
queue = Queue(max_task)
109109
for _ in range(max_task):
110110
t = threading.Thread(
111111
target=run_find_all_symbols, args=(args, tmpdir, build_path, queue)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
2020
hasType(cxxRecordDecl(anyOf(
2121
matchesName("[Ee]xception|EXCEPTION"),
2222
hasAnyBase(hasType(hasCanonicalType(recordType(hasDeclaration(
23-
cxxRecordDecl(matchesName("[Ee]xception|EXCEPTION")))))))))),
23+
cxxRecordDecl(matchesName("[Ee]xception|EXCEPTION"))
24+
.bind("base"))))))))),
2425
unless(anyOf(
2526
hasAncestor(
2627
stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
@@ -39,6 +40,11 @@ void ThrowKeywordMissingCheck::check(const MatchFinder::MatchResult &Result) {
3940
diag(TemporaryExpr->getBeginLoc(), "suspicious exception object created but "
4041
"not thrown; did you mean 'throw %0'?")
4142
<< TemporaryExpr->getType().getBaseTypeIdentifier()->getName();
43+
44+
if (const auto *BaseDecl = Result.Nodes.getNodeAs<Decl>("base"))
45+
diag(BaseDecl->getLocation(),
46+
"object type inherits from base class declared here",
47+
DiagnosticIDs::Note);
4248
}
4349

4450
} // namespace clang::tidy::bugprone

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,11 @@ ExceptionAnalyzer::throwsException(const Stmt *St,
595595
Results.merge(DestructorExcs);
596596
}
597597
}
598+
} else if (const auto *Lambda = dyn_cast<LambdaExpr>(St)) {
599+
for (const Stmt *Init : Lambda->capture_inits()) {
600+
ExceptionInfo Excs = throwsException(Init, Caught, CallStack);
601+
Results.merge(Excs);
602+
}
598603
} else {
599604
for (const Stmt *Child : St->children()) {
600605
ExceptionInfo Excs = throwsException(Child, Caught, CallStack);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ Changes in existing checks
244244
correcting a spelling mistake on its option
245245
``NamePrefixSuffixSilenceDissimilarityTreshold``.
246246

247+
- Improved :doc:`bugprone-exception-escape
248+
<clang-tidy/checks/bugprone/exception-escape>` check's handling of lambdas:
249+
exceptions from captures are now diagnosed, exceptions in the bodies of
250+
lambdas that aren't actually invoked are not.
251+
247252
- Improved :doc:`bugprone-infinite-loop
248253
<clang-tidy/checks/bugprone/infinite-loop>` check by adding detection for
249254
variables introduced by structured bindings.
@@ -272,7 +277,8 @@ Changes in existing checks
272277

273278
- Improved :doc:`bugprone-throw-keyword-missing
274279
<clang-tidy/checks/bugprone/throw-keyword-missing>` check by only considering
275-
the canonical types of base classes as written.
280+
the canonical types of base classes as written and adding a note on the base
281+
class that triggered the warning.
276282

277283
- Improved :doc:`bugprone-unchecked-optional-access
278284
<clang-tidy/checks/bugprone/unchecked-optional-access>` check by supporting

clang-tools-extra/docs/clang-tidy/Contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ in the release notes, as the first sentence in the doxygen comments in the heade
436436
for your check class and as the first sentence of the check documentation. Avoid the
437437
phrase "this check" in your check summary and check documentation.
438438

439-
If your check relates to a published coding guideline (C++ Core Guidelines, MISRA, etc.)
439+
If your check relates to a published coding guideline (C++ Core Guidelines, SEI CERT, etc.)
440440
or style guide, provide links to the relevant guideline or style guide sections in your
441441
check documentation.
442442

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,3 +894,65 @@ void pointer_exception_can_not_escape_with_void_handler() noexcept {
894894
} catch (void *) {
895895
}
896896
}
897+
898+
void throw_in_uninvoked_lambda() noexcept {
899+
[] { throw 42; };
900+
}
901+
902+
void throw_in_lambda() noexcept {
903+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_in_lambda' which should not throw exceptions
904+
[] { throw 42; }();
905+
// CHECK-MESSAGES: :[[@LINE-1]]:8: note: frame #0: unhandled exception of type 'int' may be thrown in function 'operator()' here
906+
// CHECK-MESSAGES: :[[@LINE-2]]:19: note: frame #1: function 'throw_in_lambda' calls function 'operator()' here
907+
}
908+
909+
struct copy_constructor_throws {
910+
copy_constructor_throws(const copy_constructor_throws&) { throw 42; }
911+
};
912+
913+
void throw_in_lambda_default_by_value_capture(const copy_constructor_throws& a) noexcept {
914+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_in_lambda_default_by_value_capture' which should not throw exceptions
915+
[=] { a; };
916+
// CHECK-MESSAGES: :[[@LINE-6]]:61: note: frame #0: unhandled exception of type 'int' may be thrown in function 'copy_constructor_throws' here
917+
// CHECK-MESSAGES: :[[@LINE-2]]:4: note: frame #1: function 'throw_in_lambda_default_by_value_capture' calls function 'copy_constructor_throws' here
918+
}
919+
920+
void throw_in_lambda_explicit_by_value_capture(const copy_constructor_throws& a) noexcept {
921+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_in_lambda_explicit_by_value_capture' which should not throw exceptions
922+
[a] {};
923+
// CHECK-MESSAGES: :[[@LINE-13]]:61: note: frame #0: unhandled exception of type 'int' may be thrown in function 'copy_constructor_throws' here
924+
// CHECK-MESSAGES: :[[@LINE-2]]:4: note: frame #1: function 'throw_in_lambda_explicit_by_value_capture' calls function 'copy_constructor_throws' here
925+
}
926+
927+
void no_throw_in_lambda_by_reference_capture(const copy_constructor_throws& a) noexcept {
928+
[&] { a; };
929+
[&a] {};
930+
}
931+
932+
void throw_in_lambda_init_capture() noexcept {
933+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_in_lambda_init_capture' which should not throw exceptions
934+
[a = [] { throw 42; return 0; }()] {};
935+
// CHECK-MESSAGES: :[[@LINE-1]]:13: note: frame #0: unhandled exception of type 'int' may be thrown in function 'operator()' here
936+
// CHECK-MESSAGES: :[[@LINE-2]]:34: note: frame #1: function 'throw_in_lambda_init_capture' calls function 'operator()' here
937+
}
938+
939+
void throw_from_nested_lambda() noexcept {
940+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_from_nested_lambda' which should not throw exceptions
941+
[] { [] { throw 42; }(); }();
942+
// CHECK-MESSAGES: :[[@LINE-1]]:13: note: frame #0: unhandled exception of type 'int' may be thrown in function 'operator()' here
943+
// CHECK-MESSAGES: :[[@LINE-2]]:24: note: frame #1: function 'operator()' calls function 'operator()' here
944+
// CHECK-MESSAGES: :[[@LINE-3]]:29: note: frame #2: function 'throw_from_nested_lambda' calls function 'operator()' here
945+
}
946+
947+
const auto throw_in_noexcept_lambda = [] () noexcept { throw 42; };
948+
// CHECK-MESSAGES: :[[@LINE-1]]:39: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
949+
// CHECK-MESSAGES: :[[@LINE-2]]:56: note: frame #0: unhandled exception of type 'int' may be thrown in function 'operator()' here
950+
951+
void thrower() {
952+
throw 42;
953+
}
954+
955+
const auto indirect_throw_in_noexcept_lambda = [] () noexcept { thrower(); };
956+
// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
957+
// CHECK-MESSAGES: :[[@LINE-5]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'thrower' here
958+
// CHECK-MESSAGES: :[[@LINE-3]]:65: note: frame #1: function 'operator()' calls function 'thrower' here

clang-tools-extra/test/clang-tidy/checkers/bugprone/throw-keyword-missing.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef basic_string<char> string;
2020
typedef basic_string<wchar_t> wstring;
2121

2222
// std::exception and std::runtime_error declaration.
23+
// CHECK-MESSAGES-DAG: [[#EXCEPTION_LINE:@LINE + 1]]:8
2324
struct exception {
2425
exception();
2526
exception(const exception &other);
@@ -50,12 +51,13 @@ struct RegularException {
5051

5152
void stdExceptionNotTrownTest(int i) {
5253
if (i < 0)
53-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious exception object created but not thrown; did you mean 'throw {{.*}}'? [bugprone-throw-keyword-missing]
54+
// CHECK-MESSAGES-DAG: :[[@LINE+1]]:5: warning: suspicious exception object created but not thrown; did you mean 'throw {{.*}}'? [bugprone-throw-keyword-missing]
5455
std::exception();
5556

5657
if (i > 0)
57-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious exception
58+
// CHECK-MESSAGES-DAG: :[[@LINE+1]]:5: warning: suspicious exception
5859
std::runtime_error("Unexpected argument");
60+
// CHECK-MESSAGES: note: object type inherits from base class declared here
5961
}
6062

6163
void stdExceptionThrownTest(int i) {
@@ -181,6 +183,7 @@ class RegularError : public ERROR_BASE {};
181183
void typedefTest() {
182184
// CHECK-MESSAGES: :[[@LINE+1]]:3: warning: suspicious exception
183185
RegularError();
186+
// CHECK-MESSAGES: :[[#EXCEPTION_LINE]]:8: note: object type inherits from base class declared here
184187
}
185188

186189
struct ExceptionRAII {

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ Crash and bug fixes
566566
- Fixed a crash in the static analyzer that when the expression in an
567567
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
568568
- Fixed a crash when parsing ``#embed`` parameters with unmatched closing brackets. (#GH152829)
569+
- Fixed a crash when compiling ``__real__`` or ``__imag__`` unary operator on scalar value with type promotion. (#GH160583)
569570

570571
Improvements
571572
^^^^^^^^^^^^

0 commit comments

Comments
 (0)