Skip to content

Commit 8a1f4b9

Browse files
author
Tyler Nowicki
authored
Merge branch 'main' into amd/dev/tnowicki/coro-docs-parameter-attribs
2 parents 5bf352a + 1b413c8 commit 8a1f4b9

File tree

1,140 files changed

+97324
-72919
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,140 files changed

+97324
-72919
lines changed

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,6 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, FunctionFragment &FF,
416416
BF.duplicateConstantIslands();
417417
}
418418

419-
if (!FF.empty() && FF.front()->isLandingPad()) {
420-
assert(!FF.front()->isEntryPoint() &&
421-
"Landing pad cannot be entry point of function");
422-
// If the first block of the fragment is a landing pad, it's offset from the
423-
// start of the area that the corresponding LSDA describes is zero. In this
424-
// case, the call site entries in that LSDA have 0 as offset to the landing
425-
// pad, which the runtime interprets as "no handler". To prevent this,
426-
// insert some padding.
427-
Streamer.emitBytes(BC.MIB->getTrapFillValue());
428-
}
429-
430419
// Track the first emitted instruction with debug info.
431420
bool FirstInstr = true;
432421
for (BinaryBasicBlock *const BB : FF) {
@@ -926,39 +915,54 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
926915
// Emit the LSDA header.
927916

928917
// If LPStart is omitted, then the start of the FDE is used as a base for
929-
// landing pad displacements. Then if a cold fragment starts with
930-
// a landing pad, this means that the first landing pad offset will be 0.
931-
// As a result, the exception handling runtime will ignore this landing pad
932-
// because zero offset denotes the absence of a landing pad.
933-
// For this reason, when the binary has fixed starting address we emit LPStart
934-
// as 0 and output the absolute value of the landing pad in the table.
918+
// landing pad displacements. Then, if a cold fragment starts with a landing
919+
// pad, this means that the first landing pad offset will be 0. However, C++
920+
// runtime treats 0 as if there is no landing pad present, thus we *must* emit
921+
// non-zero offsets for all valid LPs.
935922
//
936-
// If the base address can change, we cannot use absolute addresses for
937-
// landing pads (at least not without runtime relocations). Hence, we fall
938-
// back to emitting landing pads relative to the FDE start.
939-
// As we are emitting label differences, we have to guarantee both labels are
940-
// defined in the same section and hence cannot place the landing pad into a
941-
// cold fragment when the corresponding call site is in the hot fragment.
942-
// Because of this issue and the previously described issue of possible
943-
// zero-offset landing pad we have to place landing pads in the same section
944-
// as the corresponding invokes for shared objects.
923+
// As a solution, for fixed-address binaries we set LPStart to 0, and for
924+
// position-independent binaries we set LP start to FDE start minus one byte
925+
// for FDEs that start with a landing pad.
926+
const bool NeedsLPAdjustment = !FF.empty() && FF.front()->isLandingPad();
945927
std::function<void(const MCSymbol *)> emitLandingPad;
946928
if (BC.HasFixedLoadAddress) {
947929
Streamer.emitIntValue(dwarf::DW_EH_PE_udata4, 1); // LPStart format
948930
Streamer.emitIntValue(0, 4); // LPStart
949931
emitLandingPad = [&](const MCSymbol *LPSymbol) {
950-
if (!LPSymbol)
951-
Streamer.emitIntValue(0, 4);
952-
else
932+
if (LPSymbol)
953933
Streamer.emitSymbolValue(LPSymbol, 4);
934+
else
935+
Streamer.emitIntValue(0, 4);
954936
};
955937
} else {
956-
Streamer.emitIntValue(dwarf::DW_EH_PE_omit, 1); // LPStart format
938+
if (NeedsLPAdjustment) {
939+
// Use relative LPStart format and emit LPStart as [SymbolStart - 1].
940+
Streamer.emitIntValue(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4, 1);
941+
MCSymbol *DotSymbol = BC.Ctx->createTempSymbol("LPBase");
942+
Streamer.emitLabel(DotSymbol);
943+
944+
const MCExpr *LPStartExpr = MCBinaryExpr::createSub(
945+
MCSymbolRefExpr::create(StartSymbol, *BC.Ctx),
946+
MCSymbolRefExpr::create(DotSymbol, *BC.Ctx), *BC.Ctx);
947+
LPStartExpr = MCBinaryExpr::createSub(
948+
LPStartExpr, MCConstantExpr::create(1, *BC.Ctx), *BC.Ctx);
949+
Streamer.emitValue(LPStartExpr, 4);
950+
} else {
951+
// DW_EH_PE_omit means FDE start (StartSymbol) will be used as LPStart.
952+
Streamer.emitIntValue(dwarf::DW_EH_PE_omit, 1);
953+
}
957954
emitLandingPad = [&](const MCSymbol *LPSymbol) {
958-
if (!LPSymbol)
959-
Streamer.emitIntValue(0, 4);
960-
else
961-
Streamer.emitAbsoluteSymbolDiff(LPSymbol, StartSymbol, 4);
955+
if (LPSymbol) {
956+
const MCExpr *LPOffsetExpr = MCBinaryExpr::createSub(
957+
MCSymbolRefExpr::create(LPSymbol, *BC.Ctx),
958+
MCSymbolRefExpr::create(StartSymbol, *BC.Ctx), *BC.Ctx);
959+
if (NeedsLPAdjustment)
960+
LPOffsetExpr = MCBinaryExpr::createAdd(
961+
LPOffsetExpr, MCConstantExpr::create(1, *BC.Ctx), *BC.Ctx);
962+
Streamer.emitULEB128Value(LPOffsetExpr);
963+
} else {
964+
Streamer.emitULEB128IntValue(0);
965+
}
962966
};
963967
}
964968

@@ -972,10 +976,12 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
972976
Streamer.emitLabel(TTBaseRefLabel);
973977
}
974978

975-
// Emit the landing pad call site table. We use signed data4 since we can emit
976-
// a landing pad in a different part of the split function that could appear
977-
// earlier in the address space than LPStart.
978-
Streamer.emitIntValue(dwarf::DW_EH_PE_sdata4, 1);
979+
// Emit encoding of entries in the call site table. The format is used for the
980+
// call site start, length, and corresponding landing pad.
981+
if (BC.HasFixedLoadAddress)
982+
Streamer.emitIntValue(dwarf::DW_EH_PE_sdata4, 1);
983+
else
984+
Streamer.emitIntValue(dwarf::DW_EH_PE_uleb128, 1);
979985

980986
MCSymbol *CSTStartLabel = BC.Ctx->createTempSymbol("CSTStart");
981987
MCSymbol *CSTEndLabel = BC.Ctx->createTempSymbol("CSTEnd");
@@ -992,8 +998,13 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
992998

993999
// Start of the range is emitted relative to the start of current
9941000
// function split part.
995-
Streamer.emitAbsoluteSymbolDiff(BeginLabel, StartSymbol, 4);
996-
Streamer.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
1001+
if (BC.HasFixedLoadAddress) {
1002+
Streamer.emitAbsoluteSymbolDiff(BeginLabel, StartSymbol, 4);
1003+
Streamer.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
1004+
} else {
1005+
Streamer.emitAbsoluteSymbolDiffAsULEB128(BeginLabel, StartSymbol);
1006+
Streamer.emitAbsoluteSymbolDiffAsULEB128(EndLabel, BeginLabel);
1007+
}
9971008
emitLandingPad(CallSite.LP);
9981009
Streamer.emitULEB128IntValue(CallSite.Action);
9991010
}

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ bool IncludeFixerActionFactory::runInvocation(
9595

9696
// Create the compiler's actual diagnostics engine. We want to drop all
9797
// diagnostics here.
98-
Compiler.createDiagnostics(new clang::IgnoringDiagConsumer,
98+
Compiler.createDiagnostics(Files->getVirtualFileSystem(),
99+
new clang::IgnoringDiagConsumer,
99100
/*ShouldOwnClient=*/true);
100101
Compiler.createSourceManager(*Files);
101102

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
2323
} // namespace
2424

2525
UseStdPrintCheck::UseStdPrintCheck(StringRef Name, ClangTidyContext *Context)
26-
: ClangTidyCheck(Name, Context),
26+
: ClangTidyCheck(Name, Context), PP(nullptr),
2727
StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
2828
PrintfLikeFunctions(utils::options::parseStringList(
2929
Options.get("PrintfLikeFunctions", ""))),
@@ -131,6 +131,7 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult &Result) {
131131
utils::FormatStringConverter::Configuration ConverterConfig;
132132
ConverterConfig.StrictMode = StrictMode;
133133
ConverterConfig.AllowTrailingNewlineRemoval = true;
134+
assert(PP && "Preprocessor should be set by registerPPCallbacks");
134135
utils::FormatStringConverter Converter(
135136
Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts(),
136137
*Result.SourceManager, *PP);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ bool isQualificationConvertiblePointer(QualType From, QualType To,
320320
} // namespace
321321

322322
static bool canThrow(const FunctionDecl *Func) {
323+
// consteval specifies that every call to the function must produce a
324+
// compile-time constant, which cannot evaluate a throw expression without
325+
// producing a compilation error.
326+
if (Func->isConsteval())
327+
return false;
328+
323329
const auto *FunProto = Func->getType()->getAs<FunctionProtoType>();
324330
if (!FunProto)
325331
return true;

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
110110
CIOpts.VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
111111
CIOpts.CC1Args = CC1Args;
112112
CIOpts.RecoverOnError = true;
113-
CIOpts.Diags =
114-
CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false);
113+
CIOpts.Diags = CompilerInstance::createDiagnostics(
114+
*CIOpts.VFS, new DiagnosticOptions, &D, false);
115115
CIOpts.ProbePrecompiled = false;
116116
std::unique_ptr<CompilerInvocation> CI = createInvocation(ArgStrs, CIOpts);
117117
if (!CI)
@@ -148,7 +148,7 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
148148
auto Clang = std::make_unique<CompilerInstance>(
149149
std::make_shared<PCHContainerOperations>());
150150
Clang->setInvocation(std::move(CI));
151-
Clang->createDiagnostics(&DiagsClient, false);
151+
Clang->createDiagnostics(*VFS, &DiagsClient, false);
152152

153153
if (auto VFSWithRemapping = createVFSFromCompilerInvocation(
154154
Clang->getInvocation(), Clang->getDiagnostics(), VFS))

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
188188

189189
clang::clangd::IgnoreDiagnostics IgnoreDiags;
190190
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
191-
CompilerInstance::createDiagnostics(new DiagnosticOptions, &IgnoreDiags,
191+
CompilerInstance::createDiagnostics(*VFS, new DiagnosticOptions,
192+
&IgnoreDiags,
192193
/*ShouldOwnClient=*/false);
193194

194195
LangOptions LangOpts;

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,9 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
613613
for (const auto &L : ASTListeners)
614614
L->sawDiagnostic(D, Diag);
615615
});
616+
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
616617
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> PreambleDiagsEngine =
617-
CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
618+
CompilerInstance::createDiagnostics(*VFS, &CI.getDiagnosticOpts(),
618619
&PreambleDiagnostics,
619620
/*ShouldOwnClient=*/false);
620621
const Config &Cfg = Config::current();
@@ -651,7 +652,6 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
651652
for (const auto &L : ASTListeners)
652653
L->beforeExecute(CI);
653654
});
654-
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
655655
llvm::SmallString<32> AbsFileName(FileName);
656656
VFS->makeAbsolute(AbsFileName);
657657
auto StatCache = std::make_shared<PreambleFileStatusCache>(AbsFileName);

clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ getFunctionSourceCode(const FunctionDecl *FD, const DeclContext *TargetContext,
239239
return;
240240

241241
for (const NamedDecl *ND : Ref.Targets) {
242+
if (ND->getKind() == Decl::TemplateTypeParm)
243+
return;
242244
if (ND->getDeclContext() != Ref.Targets.front()->getDeclContext()) {
243245
elog("Targets from multiple contexts: {0}, {1}",
244246
printQualifiedName(*Ref.Targets.front()),

clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,29 +411,29 @@ inline typename O1<T, U...>::template O2<V, A>::E O1<T, U...>::template O2<V, A>
411411
R"cpp(
412412
struct Foo {
413413
template <typename T, bool B = true>
414-
void ^bar() {}
414+
T ^bar() { return {}; }
415415
};)cpp",
416416
R"cpp(
417417
struct Foo {
418418
template <typename T, bool B = true>
419-
void bar() ;
419+
T bar() ;
420420
};template <typename T, bool B>
421-
inline void Foo::bar() {}
421+
inline T Foo::bar() { return {}; }
422422
)cpp",
423423
""},
424424

425425
// Class template with member template
426426
{
427427
R"cpp(
428428
template <typename T> struct Foo {
429-
template <typename U> void ^bar(const T& t, const U& u) {}
429+
template <typename U> T ^bar(const T& t, const U& u) { return {}; }
430430
};)cpp",
431431
R"cpp(
432432
template <typename T> struct Foo {
433-
template <typename U> void bar(const T& t, const U& u) ;
433+
template <typename U> T bar(const T& t, const U& u) ;
434434
};template <typename T>
435435
template <typename U>
436-
inline void Foo<T>::bar(const T& t, const U& u) {}
436+
inline T Foo<T>::bar(const T& t, const U& u) { return {}; }
437437
)cpp",
438438
""},
439439
};

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ Changes in existing checks
162162
<clang-tidy/checks/bugprone/dangling-handle>` check to treat `std::span` as a
163163
handle class.
164164

165+
- Improved :doc:`bugprone-exception-escape
166+
<clang-tidy/checks/bugprone/exception-escape>` by fixing false positives
167+
when a consteval function with throw statements.
168+
165169
- Improved :doc:`bugprone-forwarding-reference-overload
166170
<clang-tidy/checks/bugprone/forwarding-reference-overload>` check by fixing
167171
a crash when determining if an ``enable_if[_t]`` was found.

0 commit comments

Comments
 (0)