Skip to content

Commit b7133ba

Browse files
committed
merge main into amd-staging
2 parents 03ae304 + 7ff6973 commit b7133ba

File tree

100 files changed

+10393
-14217
lines changed

Some content is hidden

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

100 files changed

+10393
-14217
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/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ def err_omp_more_one_clause : Error<
433433
"directive '#pragma omp %0' cannot contain more than one '%1' clause%select{| with '%3' name modifier| with 'source' dependence}2">;
434434
def err_omp_required_clause : Error<
435435
"directive '#pragma omp %0' requires the '%1' clause">;
436+
def warn_omp_gpu_unsupported_clause: Warning<
437+
"clause '%0' is currently not supported on a GPU; clause ignored">,
438+
InGroup<OpenMPClauses>;
439+
def warn_omp_gpu_unsupported_modifier_for_clause: Warning<
440+
"modifier '%0' is currently not supported on a GPU for the '%1' clause; modifier ignored">,
441+
InGroup<OpenMPClauses>;
436442

437443
// Static Analyzer Core
438444
def err_unknown_analyzer_checker_or_package : Error<

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "clang/AST/DeclObjC.h"
2727
#include "clang/AST/DeclTemplate.h"
2828
#include "clang/AST/Expr.h"
29-
#include "clang/AST/LambdaCapture.h"
3029
#include "clang/AST/RecordLayout.h"
3130
#include "clang/AST/RecursiveASTVisitor.h"
3231
#include "clang/AST/VTableBuilder.h"
@@ -1962,59 +1961,46 @@ CGDebugInfo::createInlinedSubprogram(StringRef FuncName,
19621961
return SP;
19631962
}
19641963

1965-
llvm::StringRef
1966-
CGDebugInfo::GetLambdaCaptureName(const LambdaCapture &Capture) {
1967-
if (Capture.capturesThis())
1968-
return CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
1969-
1970-
assert(Capture.capturesVariable());
1971-
1972-
const ValueDecl *CaptureDecl = Capture.getCapturedVar();
1973-
assert(CaptureDecl && "Expected valid decl for captured variable.");
1974-
1975-
return CaptureDecl->getName();
1976-
}
1977-
19781964
void CGDebugInfo::CollectRecordLambdaFields(
19791965
const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
19801966
llvm::DIType *RecordTy) {
19811967
// For C++11 Lambdas a Field will be the same as a Capture, but the Capture
19821968
// has the name and the location of the variable so we should iterate over
19831969
// both concurrently.
1970+
const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(CXXDecl);
19841971
RecordDecl::field_iterator Field = CXXDecl->field_begin();
19851972
unsigned fieldno = 0;
19861973
for (CXXRecordDecl::capture_const_iterator I = CXXDecl->captures_begin(),
19871974
E = CXXDecl->captures_end();
19881975
I != E; ++I, ++Field, ++fieldno) {
1989-
const LambdaCapture &Capture = *I;
1990-
const uint64_t FieldOffset =
1991-
CGM.getContext().getASTRecordLayout(CXXDecl).getFieldOffset(fieldno);
1992-
1993-
assert(!Field->isBitField() && "lambdas don't have bitfield members!");
1994-
1995-
SourceLocation Loc;
1996-
uint32_t Align = 0;
1997-
1998-
if (Capture.capturesThis()) {
1976+
const LambdaCapture &C = *I;
1977+
if (C.capturesVariable()) {
1978+
SourceLocation Loc = C.getLocation();
1979+
assert(!Field->isBitField() && "lambdas don't have bitfield members!");
1980+
ValueDecl *V = C.getCapturedVar();
1981+
StringRef VName = V->getName();
1982+
llvm::DIFile *VUnit = getOrCreateFile(Loc);
1983+
auto Align = getDeclAlignIfRequired(V, CGM.getContext());
1984+
llvm::DIType *FieldType = createFieldType(
1985+
VName, Field->getType(), Loc, Field->getAccess(),
1986+
layout.getFieldOffset(fieldno), Align, VUnit, RecordTy, CXXDecl);
1987+
elements.push_back(FieldType);
1988+
} else if (C.capturesThis()) {
19991989
// TODO: Need to handle 'this' in some way by probably renaming the
20001990
// this of the lambda class and having a field member of 'this' or
20011991
// by using AT_object_pointer for the function and having that be
20021992
// used as 'this' for semantic references.
2003-
Loc = Field->getLocation();
2004-
} else {
2005-
Loc = Capture.getLocation();
2006-
2007-
const ValueDecl *CaptureDecl = Capture.getCapturedVar();
2008-
assert(CaptureDecl && "Expected valid decl for captured variable.");
2009-
2010-
Align = getDeclAlignIfRequired(CaptureDecl, CGM.getContext());
1993+
FieldDecl *f = *Field;
1994+
llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
1995+
QualType type = f->getType();
1996+
StringRef ThisName =
1997+
CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
1998+
llvm::DIType *fieldType = createFieldType(
1999+
ThisName, type, f->getLocation(), f->getAccess(),
2000+
layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
2001+
2002+
elements.push_back(fieldType);
20112003
}
2012-
2013-
llvm::DIFile *VUnit = getOrCreateFile(Loc);
2014-
2015-
elements.push_back(createFieldType(
2016-
GetLambdaCaptureName(Capture), Field->getType(), Loc,
2017-
Field->getAccess(), FieldOffset, Align, VUnit, RecordTy, CXXDecl));
20182004
}
20192005
}
20202006

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ class CGDebugInfo {
397397
void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
398398
SmallVectorImpl<llvm::Metadata *> &E,
399399
llvm::DICompositeType *RecordTy);
400-
llvm::StringRef GetLambdaCaptureName(const LambdaCapture &Capture);
401400

402401
/// If the C++ class has vtable info then insert appropriate debug
403402
/// info entry in EltTys vector.

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,15 +1566,14 @@ static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc(
15661566
SourceManager &SM = CGM.getContext().getSourceManager();
15671567
PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc);
15681568

1569-
llvm::sys::fs::UniqueID ID;
1570-
if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
1569+
if (CGM.getFileSystem()->exists(PLoc.getFilename()))
15711570
PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false);
1572-
}
15731571

15741572
return std::pair<std::string, uint64_t>(PLoc.getFilename(), PLoc.getLine());
15751573
};
15761574

1577-
return OMPBuilder.getTargetEntryUniqueInfo(FileInfoCallBack, ParentName);
1575+
return OMPBuilder.getTargetEntryUniqueInfo(FileInfoCallBack,
1576+
*CGM.getFileSystem(), ParentName);
15781577
}
15791578

15801579
ConstantAddress CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) {
@@ -2750,7 +2749,8 @@ llvm::Value *CGOpenMPRuntime::emitForNext(CodeGenFunction &CGF,
27502749
}
27512750

27522751
llvm::Value *CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF,
2753-
const Expr *Message) {
2752+
const Expr *Message,
2753+
SourceLocation Loc) {
27542754
if (!Message)
27552755
return llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
27562756
return CGF.EmitScalarExpr(Message);
@@ -2760,11 +2760,13 @@ llvm::Value *
27602760
CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF,
27612761
const OMPMessageClause *MessageClause) {
27622762
return emitMessageClause(
2763-
CGF, MessageClause ? MessageClause->getMessageString() : nullptr);
2763+
CGF, MessageClause ? MessageClause->getMessageString() : nullptr,
2764+
MessageClause->getBeginLoc());
27642765
}
27652766

27662767
llvm::Value *
2767-
CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity) {
2768+
CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity,
2769+
SourceLocation Loc) {
27682770
// OpenMP 6.0, 10.4: "If no severity clause is specified then the effect is
27692771
// as if sev-level is fatal."
27702772
return llvm::ConstantInt::get(CGM.Int32Ty,
@@ -2774,13 +2776,15 @@ CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity) {
27742776
llvm::Value *
27752777
CGOpenMPRuntime::emitSeverityClause(const OMPSeverityClause *SeverityClause) {
27762778
return emitSeverityClause(SeverityClause ? SeverityClause->getSeverityKind()
2777-
: OMPC_SEVERITY_unknown);
2779+
: OMPC_SEVERITY_unknown,
2780+
SeverityClause->getBeginLoc());
27782781
}
27792782

27802783
void CGOpenMPRuntime::emitNumThreadsClause(
27812784
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
27822785
OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
2783-
const Expr *Message) {
2786+
SourceLocation SeverityLoc, const Expr *Message,
2787+
SourceLocation MessageLoc) {
27842788
if (!CGF.HaveInsertPoint())
27852789
return;
27862790
llvm::SmallVector<llvm::Value *, 4> Args(
@@ -2792,8 +2796,8 @@ void CGOpenMPRuntime::emitNumThreadsClause(
27922796
RuntimeFunction FnID = OMPRTL___kmpc_push_num_threads;
27932797
if (Modifier == OMPC_NUMTHREADS_strict) {
27942798
FnID = OMPRTL___kmpc_push_num_threads_strict;
2795-
Args.push_back(emitSeverityClause(Severity));
2796-
Args.push_back(emitMessageClause(CGF, Message));
2799+
Args.push_back(emitSeverityClause(Severity, SeverityLoc));
2800+
Args.push_back(emitMessageClause(CGF, Message, MessageLoc));
27972801
}
27982802
CGF.EmitRuntimeCall(
27992803
OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(), FnID), Args);
@@ -13093,7 +13097,8 @@ llvm::Value *CGOpenMPSIMDRuntime::emitForNext(CodeGenFunction &CGF,
1309313097
void CGOpenMPSIMDRuntime::emitNumThreadsClause(
1309413098
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
1309513099
OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
13096-
const Expr *Message) {
13100+
SourceLocation SeverityLoc, const Expr *Message,
13101+
SourceLocation MessageLoc) {
1309713102
llvm_unreachable("Not supported in SIMD-only mode");
1309813103
}
1309913104

clang/lib/CodeGen/CGOpenMPRuntime.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,13 @@ class CGOpenMPRuntime {
10621062
Address UB, Address ST);
10631063

10641064
virtual llvm::Value *emitMessageClause(CodeGenFunction &CGF,
1065-
const Expr *Message);
1065+
const Expr *Message,
1066+
SourceLocation Loc);
10661067
virtual llvm::Value *emitMessageClause(CodeGenFunction &CGF,
10671068
const OMPMessageClause *MessageClause);
10681069

1069-
virtual llvm::Value *emitSeverityClause(OpenMPSeverityClauseKind Severity);
1070+
virtual llvm::Value *emitSeverityClause(OpenMPSeverityClauseKind Severity,
1071+
SourceLocation Loc);
10701072
virtual llvm::Value *
10711073
emitSeverityClause(const OMPSeverityClause *SeverityClause);
10721074

@@ -1082,7 +1084,9 @@ class CGOpenMPRuntime {
10821084
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
10831085
OpenMPNumThreadsClauseModifier Modifier = OMPC_NUMTHREADS_unknown,
10841086
OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
1085-
const Expr *Message = nullptr);
1087+
SourceLocation SeverityLoc = SourceLocation(),
1088+
const Expr *Message = nullptr,
1089+
SourceLocation MessageLoc = SourceLocation());
10861090

10871091
/// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
10881092
/// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
@@ -1994,7 +1998,9 @@ class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime {
19941998
CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
19951999
OpenMPNumThreadsClauseModifier Modifier = OMPC_NUMTHREADS_unknown,
19962000
OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
1997-
const Expr *Message = nullptr) override;
2001+
SourceLocation SeverityLoc = SourceLocation(),
2002+
const Expr *Message = nullptr,
2003+
SourceLocation MessageLoc = SourceLocation()) override;
19982004

19992005
/// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
20002006
/// global_tid, int proc_bind) to generate code for 'proc_bind' clause.

0 commit comments

Comments
 (0)