Skip to content

Commit 811fe02

Browse files
committed
Merge from 'main' to 'sycl-web' (10 commits)
2 parents f76c270 + 9a783b6 commit 811fe02

File tree

138 files changed

+2458
-1371
lines changed

Some content is hidden

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

138 files changed

+2458
-1371
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,20 +1371,13 @@ class MCPlusBuilder {
13711371
/// Return true if \p Inst has RestoreState annotation.
13721372
bool hasRestoreState(const MCInst &Inst) const;
13731373

1374-
/// Stores RA Signed annotation on \p Inst.
1375-
void setRASigned(MCInst &Inst) const;
1374+
/// Sets kRASigned or kRAUnsigned annotation on \p Inst.
1375+
/// Fails if \p Inst has either annotation already set.
1376+
void setRAState(MCInst &Inst, bool State) const;
13761377

1377-
/// Return true if \p Inst has Signed RA annotation.
1378-
bool isRASigned(const MCInst &Inst) const;
1379-
1380-
/// Stores RA Unsigned annotation on \p Inst.
1381-
void setRAUnsigned(MCInst &Inst) const;
1382-
1383-
/// Return true if \p Inst has Unsigned RA annotation.
1384-
bool isRAUnsigned(const MCInst &Inst) const;
1385-
1386-
/// Return true if \p Inst doesn't have any annotation related to RA state.
1387-
bool isRAStateUnknown(const MCInst &Inst) const;
1378+
/// Return true if \p Inst has kRASigned annotation, false if it has
1379+
/// kRAUnsigned annotation, and std::nullopt if neither annotation is set.
1380+
std::optional<bool> getRAState(const MCInst &Inst) const;
13881381

13891382
/// Return true if the instruction is a call with an exception handling info.
13901383
virtual bool isInvoke(const MCInst &Inst) const {

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,26 +186,21 @@ bool MCPlusBuilder::hasRestoreState(const MCInst &Inst) const {
186186
return hasAnnotation(Inst, MCAnnotation::kRestoreState);
187187
}
188188

189-
void MCPlusBuilder::setRASigned(MCInst &Inst) const {
189+
void MCPlusBuilder::setRAState(MCInst &Inst, bool State) const {
190190
assert(!hasAnnotation(Inst, MCAnnotation::kRASigned));
191-
setAnnotationOpValue(Inst, MCAnnotation::kRASigned, true);
192-
}
193-
194-
bool MCPlusBuilder::isRASigned(const MCInst &Inst) const {
195-
return hasAnnotation(Inst, MCAnnotation::kRASigned);
196-
}
197-
198-
void MCPlusBuilder::setRAUnsigned(MCInst &Inst) const {
199191
assert(!hasAnnotation(Inst, MCAnnotation::kRAUnsigned));
200-
setAnnotationOpValue(Inst, MCAnnotation::kRAUnsigned, true);
192+
if (State)
193+
setAnnotationOpValue(Inst, MCAnnotation::kRASigned, true);
194+
else
195+
setAnnotationOpValue(Inst, MCAnnotation::kRAUnsigned, true);
201196
}
202197

203-
bool MCPlusBuilder::isRAUnsigned(const MCInst &Inst) const {
204-
return hasAnnotation(Inst, MCAnnotation::kRAUnsigned);
205-
}
206-
207-
bool MCPlusBuilder::isRAStateUnknown(const MCInst &Inst) const {
208-
return !(isRAUnsigned(Inst) || isRASigned(Inst));
198+
std::optional<bool> MCPlusBuilder::getRAState(const MCInst &Inst) const {
199+
if (hasAnnotation(Inst, MCAnnotation::kRASigned))
200+
return true;
201+
if (hasAnnotation(Inst, MCAnnotation::kRAUnsigned))
202+
return false;
203+
return std::nullopt;
209204
}
210205

211206
std::optional<MCLandingPad> MCPlusBuilder::getEHInfo(const MCInst &Inst) const {

bolt/lib/Passes/InsertNegateRAStatePass.cpp

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ using namespace llvm;
2121
namespace llvm {
2222
namespace bolt {
2323

24+
static bool PassFailed = false;
25+
2426
void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
27+
if (PassFailed)
28+
return;
29+
2530
BinaryContext &BC = BF.getBinaryContext();
2631

2732
if (BF.getState() == BinaryFunction::State::Empty)
@@ -39,26 +44,31 @@ void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
3944
for (FunctionFragment &FF : BF.getLayout().fragments()) {
4045
coverFunctionFragmentStart(BF, FF);
4146
bool FirstIter = true;
42-
MCInst PrevInst;
47+
bool PrevRAState = false;
4348
// As this pass runs after function splitting, we should only check
4449
// consecutive instructions inside FunctionFragments.
4550
for (BinaryBasicBlock *BB : FF) {
4651
for (auto It = BB->begin(); It != BB->end(); ++It) {
4752
MCInst &Inst = *It;
4853
if (BC.MIB->isCFI(Inst))
4954
continue;
55+
auto RAState = BC.MIB->getRAState(Inst);
56+
if (!RAState) {
57+
BC.errs() << "BOLT-ERROR: unknown RAState after inferUnknownStates "
58+
<< " in function " << BF.getPrintName() << "\n";
59+
PassFailed = true;
60+
return;
61+
}
5062
if (!FirstIter) {
5163
// Consecutive instructions with different RAState means we need to
5264
// add a OpNegateRAState.
53-
if ((BC.MIB->isRASigned(PrevInst) && BC.MIB->isRAUnsigned(Inst)) ||
54-
(BC.MIB->isRAUnsigned(PrevInst) && BC.MIB->isRASigned(Inst))) {
65+
if (*RAState != PrevRAState)
5566
It = BF.addCFIInstruction(
5667
BB, It, MCCFIInstruction::createNegateRAState(nullptr));
57-
}
5868
} else {
5969
FirstIter = false;
6070
}
61-
PrevInst = *It;
71+
PrevRAState = *RAState;
6272
}
6373
}
6474
}
@@ -81,10 +91,17 @@ void InsertNegateRAState::coverFunctionFragmentStart(BinaryFunction &BF,
8191
});
8292
// If a function is already split in the input, the first FF can also start
8393
// with Signed state. This covers that scenario as well.
84-
if (BC.MIB->isRASigned(*((*FirstNonEmpty)->begin()))) {
85-
BF.addCFIInstruction(*FirstNonEmpty, (*FirstNonEmpty)->begin(),
86-
MCCFIInstruction::createNegateRAState(nullptr));
94+
auto II = (*FirstNonEmpty)->getFirstNonPseudo();
95+
auto RAState = BC.MIB->getRAState(*II);
96+
if (!RAState) {
97+
BC.errs() << "BOLT-ERROR: unknown RAState after inferUnknownStates "
98+
<< " in function " << BF.getPrintName() << "\n";
99+
PassFailed = true;
100+
return;
87101
}
102+
if (*RAState)
103+
BF.addCFIInstruction(*FirstNonEmpty, II,
104+
MCCFIInstruction::createNegateRAState(nullptr));
88105
}
89106

90107
void InsertNegateRAState::inferUnknownStates(BinaryFunction &BF) {
@@ -96,15 +113,21 @@ void InsertNegateRAState::inferUnknownStates(BinaryFunction &BF) {
96113
if (BC.MIB->isCFI(Inst))
97114
continue;
98115

99-
if (!FirstIter && BC.MIB->isRAStateUnknown(Inst)) {
100-
if (BC.MIB->isRASigned(PrevInst) || BC.MIB->isPSignOnLR(PrevInst)) {
101-
BC.MIB->setRASigned(Inst);
102-
} else if (BC.MIB->isRAUnsigned(PrevInst) ||
103-
BC.MIB->isPAuthOnLR(PrevInst)) {
104-
BC.MIB->setRAUnsigned(Inst);
116+
auto RAState = BC.MIB->getRAState(Inst);
117+
if (!FirstIter && !RAState) {
118+
if (BC.MIB->isPSignOnLR(PrevInst))
119+
RAState = true;
120+
else if (BC.MIB->isPAuthOnLR(PrevInst))
121+
RAState = false;
122+
else {
123+
auto PrevRAState = BC.MIB->getRAState(PrevInst);
124+
RAState = PrevRAState ? *PrevRAState : false;
105125
}
126+
BC.MIB->setRAState(Inst, *RAState);
106127
} else {
107128
FirstIter = false;
129+
if (!RAState)
130+
BC.MIB->setRAState(Inst, BF.getInitialRAState());
108131
}
109132
PrevInst = Inst;
110133
}
@@ -135,6 +158,8 @@ Error InsertNegateRAState::runOnFunctions(BinaryContext &BC) {
135158
<< " functions "
136159
<< format("(%.2lf%%).\n", (100.0 * FunctionsModified) /
137160
BC.getBinaryFunctions().size());
161+
if (PassFailed)
162+
return createFatalBOLTError("");
138163
return Error::success();
139164
}
140165

bolt/lib/Passes/MarkRAStates.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
7272
BF.setIgnored();
7373
return false;
7474
}
75-
// The signing instruction itself is unsigned, the next will be
76-
// signed.
77-
BC.MIB->setRAUnsigned(Inst);
7875
} else if (BC.MIB->isPAuthOnLR(Inst)) {
7976
if (!RAState) {
8077
// RA authenticating instructions should only follow signed RA state.
@@ -86,15 +83,10 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
8683
BF.setIgnored();
8784
return false;
8885
}
89-
// The authenticating instruction itself is signed, but the next will be
90-
// unsigned.
91-
BC.MIB->setRASigned(Inst);
92-
} else if (RAState) {
93-
BC.MIB->setRASigned(Inst);
94-
} else {
95-
BC.MIB->setRAUnsigned(Inst);
9686
}
9787

88+
BC.MIB->setRAState(Inst, RAState);
89+
9890
// Updating RAState. All updates are valid from the next instruction.
9991
// Because the same instruction can have remember and restore, the order
10092
// here is relevant. This is the reason to loop over Annotations instead

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ clang_target_link_libraries(clangDaemon
165165
clangBasic
166166
clangDependencyScanning
167167
clangDriver
168+
clangOptions
168169
clangFormat
169170
clangFrontend
170171
clangIndex

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "support/Logger.h"
1212
#include "support/Trace.h"
1313
#include "clang/Driver/Driver.h"
14-
#include "clang/Driver/Options.h"
1514
#include "clang/Frontend/CompilerInvocation.h"
15+
#include "clang/Options/Options.h"
1616
#include "clang/Tooling/CompilationDatabase.h"
1717
#include "clang/Tooling/Tooling.h"
1818
#include "llvm/ADT/ArrayRef.h"
@@ -206,7 +206,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
206206
if (Cmd.empty())
207207
return;
208208

209-
auto &OptTable = clang::driver::getDriverOptTable();
209+
auto &OptTable = getDriverOptTable();
210210
// OriginalArgs needs to outlive ArgList.
211211
llvm::SmallVector<const char *, 16> OriginalArgs;
212212
OriginalArgs.reserve(Cmd.size());
@@ -222,8 +222,8 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
222222
llvm::opt::InputArgList ArgList;
223223
ArgList = OptTable.ParseArgs(
224224
llvm::ArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
225-
llvm::opt::Visibility(IsCLMode ? driver::options::CLOption
226-
: driver::options::ClangOption));
225+
llvm::opt::Visibility(IsCLMode ? options::CLOption
226+
: options::ClangOption));
227227

228228
llvm::SmallVector<unsigned, 1> IndicesToDrop;
229229
// Having multiple architecture options (e.g. when building fat binaries)
@@ -232,7 +232,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
232232
// As there are no signals to figure out which one user actually wants. They
233233
// can explicitly specify one through `CompileFlags.Add` if need be.
234234
unsigned ArchOptCount = 0;
235-
for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) {
235+
for (auto *Input : ArgList.filtered(options::OPT_arch)) {
236236
++ArchOptCount;
237237
for (auto I = 0U; I <= Input->getNumValues(); ++I)
238238
IndicesToDrop.push_back(Input->getIndex() + I);
@@ -262,13 +262,12 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
262262
// explicitly at the end of the flags. This ensures modifications done in the
263263
// following steps apply in more cases (like setting -x, which only affects
264264
// inputs that come after it).
265-
for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT)) {
265+
for (auto *Input : ArgList.filtered(options::OPT_INPUT)) {
266266
SawInput(Input->getValue(0));
267267
IndicesToDrop.push_back(Input->getIndex());
268268
}
269269
// Anything after `--` is also treated as input, drop them as well.
270-
if (auto *DashDash =
271-
ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
270+
if (auto *DashDash = ArgList.getLastArgNoClaim(options::OPT__DASH_DASH)) {
272271
auto DashDashIndex = DashDash->getIndex() + 1; // +1 accounts for Cmd[0]
273272
// Another +1 so we don't treat the `--` itself as an input.
274273
for (unsigned I = DashDashIndex + 1; I < Cmd.size(); ++I)
@@ -424,11 +423,11 @@ DriverMode getDriverMode(const std::vector<std::string> &Args) {
424423
// Returns the set of DriverModes where an option may be used.
425424
unsigned char getModes(const llvm::opt::Option &Opt) {
426425
unsigned char Result = DM_None;
427-
if (Opt.hasVisibilityFlag(driver::options::ClangOption))
426+
if (Opt.hasVisibilityFlag(options::ClangOption))
428427
Result |= DM_GCC;
429-
if (Opt.hasVisibilityFlag(driver::options::CC1Option))
428+
if (Opt.hasVisibilityFlag(options::CC1Option))
430429
Result |= DM_CC1;
431-
if (Opt.hasVisibilityFlag(driver::options::CLOption))
430+
if (Opt.hasVisibilityFlag(options::CLOption))
432431
Result |= DM_CL;
433432
return Result;
434433
}
@@ -442,8 +441,8 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
442441
using TableTy =
443442
llvm::StringMap<llvm::SmallVector<Rule, 4>, llvm::BumpPtrAllocator>;
444443
static TableTy *Table = [] {
445-
auto &DriverTable = driver::getDriverOptTable();
446-
using DriverID = clang::driver::options::ID;
444+
auto &DriverTable = getDriverOptTable();
445+
using DriverID = clang::options::ID;
447446

448447
// Collect sets of aliases, so we can treat -foo and -foo= as synonyms.
449448
// Conceptually a double-linked list: PrevAlias[I] -> I -> NextAlias[I].
@@ -468,7 +467,7 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
468467
FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
469468
METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \
470469
{DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS},
471-
#include "clang/Driver/Options.inc"
470+
#include "clang/Options/Options.inc"
472471
#undef OPTION
473472
};
474473
for (auto &E : AliasTable)

clang-tools-extra/modularize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ clang_target_link_libraries(modularize
2020
clangAST
2121
clangBasic
2222
clangDriver
23+
clangOptions
2324
clangFrontend
2425
clangLex
2526
clangSerialization

clang-tools-extra/modularize/CoverageChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@
5050
//
5151
//===----------------------------------------------------------------------===//
5252

53+
#include "CoverageChecker.h"
5354
#include "ModularizeUtilities.h"
5455
#include "clang/AST/ASTConsumer.h"
55-
#include "CoverageChecker.h"
5656
#include "clang/AST/ASTContext.h"
5757
#include "clang/AST/RecursiveASTVisitor.h"
5858
#include "clang/Basic/SourceManager.h"
59-
#include "clang/Driver/Options.h"
6059
#include "clang/Frontend/CompilerInstance.h"
6160
#include "clang/Frontend/FrontendAction.h"
6261
#include "clang/Frontend/FrontendActions.h"
6362
#include "clang/Lex/PPCallbacks.h"
6463
#include "clang/Lex/Preprocessor.h"
64+
#include "clang/Options/Options.h"
6565
#include "clang/Tooling/CompilationDatabase.h"
6666
#include "clang/Tooling/Tooling.h"
6767
#include "llvm/Option/Option.h"
@@ -73,7 +73,7 @@
7373
using namespace Modularize;
7474
using namespace clang;
7575
using namespace clang::driver;
76-
using namespace clang::driver::options;
76+
using namespace clang::options;
7777
using namespace clang::tooling;
7878
namespace cl = llvm::cl;
7979
namespace sys = llvm::sys;

clang-tools-extra/modularize/Modularize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@
231231
#include "clang/AST/ASTContext.h"
232232
#include "clang/AST/RecursiveASTVisitor.h"
233233
#include "clang/Basic/SourceManager.h"
234-
#include "clang/Driver/Options.h"
235234
#include "clang/Frontend/CompilerInstance.h"
236235
#include "clang/Frontend/FrontendAction.h"
237236
#include "clang/Frontend/FrontendActions.h"
238237
#include "clang/Lex/Preprocessor.h"
238+
#include "clang/Options/Options.h"
239239
#include "clang/Tooling/CompilationDatabase.h"
240240
#include "clang/Tooling/Tooling.h"
241241
#include "llvm/Option/Arg.h"
@@ -254,7 +254,7 @@
254254

255255
using namespace clang;
256256
using namespace clang::driver;
257-
using namespace clang::driver::options;
257+
using namespace clang::options;
258258
using namespace clang::tooling;
259259
using namespace llvm;
260260
using namespace llvm::opt;

clang-tools-extra/modularize/ModularizeUtilities.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "ModularizeUtilities.h"
16+
#include "CoverageChecker.h"
1517
#include "clang/Basic/SourceManager.h"
16-
#include "clang/Driver/Options.h"
1718
#include "clang/Frontend/CompilerInstance.h"
1819
#include "clang/Frontend/FrontendActions.h"
19-
#include "CoverageChecker.h"
20+
#include "clang/Options/Options.h"
2021
#include "llvm/ADT/SmallString.h"
2122
#include "llvm/Support/FileUtilities.h"
2223
#include "llvm/Support/MemoryBuffer.h"
2324
#include "llvm/Support/Path.h"
2425
#include "llvm/Support/raw_ostream.h"
25-
#include "ModularizeUtilities.h"
2626

2727
using namespace clang;
2828
using namespace llvm;

0 commit comments

Comments
 (0)