Skip to content

Commit 9ede198

Browse files
authored
Merge branch 'main' into cstring-order-test-name
2 parents daff663 + f8d547f commit 9ede198

File tree

50 files changed

+1586
-869
lines changed

Some content is hidden

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

50 files changed

+1586
-869
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

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: 5 additions & 0 deletions
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.

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/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,10 +1542,8 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
15421542
SourceManager &SM = CGM.getContext().getSourceManager();
15431543
PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc);
15441544

1545-
llvm::sys::fs::UniqueID ID;
1546-
if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
1545+
if (CGM.getFileSystem()->exists(PLoc.getFilename()))
15471546
PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
1548-
}
15491547

15501548
return std::pair<std::string, uint64_t>(PLoc.getFilename(), PLoc.getLine());
15511549
};

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8172,12 +8172,17 @@ void CodeGenModule::printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
81728172

81738173
// Get the UniqueID for the file containing the decl.
81748174
llvm::sys::fs::UniqueID ID;
8175-
if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
8175+
auto Status = FS->status(PLoc.getFilename());
8176+
if (!Status) {
81768177
PLoc = SM.getPresumedLoc(D->getLocation(), /*UseLineDirectives=*/false);
81778178
assert(PLoc.isValid() && "Source location is expected to be valid.");
8178-
if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
8179-
SM.getDiagnostics().Report(diag::err_cannot_open_file)
8180-
<< PLoc.getFilename() << EC.message();
8179+
Status = FS->status(PLoc.getFilename());
8180+
}
8181+
if (!Status) {
8182+
SM.getDiagnostics().Report(diag::err_cannot_open_file)
8183+
<< PLoc.getFilename() << Status.getError().message();
8184+
} else {
8185+
ID = Status->getUniqueID();
81818186
}
81828187
OS << llvm::format("%x", ID.getFile()) << llvm::format("%x", ID.getDevice())
81838188
<< "_" << llvm::utohexstr(Result.low(), /*LowerCase=*/true, /*Width=*/8);

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,8 @@ OptionalFileEntryRef DirectoryLookup::DoFrameworkLookup(
672672
if (getDirCharacteristic() == SrcMgr::C_User) {
673673
SmallString<1024> SystemFrameworkMarker(FrameworkName);
674674
SystemFrameworkMarker += ".system_framework";
675-
if (llvm::sys::fs::exists(SystemFrameworkMarker)) {
675+
if (FileMgr.getOptionalFileRef(SystemFrameworkMarker))
676676
CacheEntry.IsUserSpecifiedSystemFramework = true;
677-
}
678677
}
679678
}
680679

clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void ModelInjector::onBodySynthesis(const NamedDecl *D) {
6565
else
6666
fileName = llvm::StringRef(D->getName().str() + ".model");
6767

68-
if (!llvm::sys::fs::exists(fileName.str())) {
68+
if (!CI.getVirtualFileSystem().exists(fileName)) {
6969
Bodies[D->getName()] = nullptr;
7070
return;
7171
}

compiler-rt/test/fuzzer/fork-sigusr.test

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Check that libFuzzer honors SIGUSR1/SIGUSR2
22
# Disabled on Windows which does not have SIGUSR1/SIGUSR2.
3+
REQUIRES: shell
34
UNSUPPORTED: darwin, target={{.*windows.*}}, target=aarch64{{.*}}
45
RUN: rm -rf %t
56
RUN: mkdir -p %t
67
RUN: %cpp_compiler %S/SleepOneSecondTest.cpp -o %t/ForkSIGUSR
78

8-
# The line below needs the " | env" at the end, in order to make the
9-
# script continue executing, rather than waiting (forever) for the
10-
# 'nohup run...' command to finish.
11-
RUN: bash -c "nohup %run %t/ForkSIGUSR -fork=3 -ignore_crashes=1 2>%t/log & echo -n $! > %t2" | env
9+
RUN: %run %t/ForkSIGUSR -fork=3 -ignore_crashes=1 2>%t/log & export PID=$!
1210
RUN: sleep 3
13-
RUN: kill -SIGUSR2 %{readfile:%t2}
11+
RUN: kill -SIGUSR2 $PID
1412
RUN: sleep 6
1513
RUN: cat %t/log | FileCheck %s --dump-input=fail
1614

0 commit comments

Comments
 (0)