Skip to content

Commit 05bb629

Browse files
authored
merge main into amd-staging (#550)
2 parents a96efa8 + 26b4ac0 commit 05bb629

File tree

133 files changed

+3676
-1949
lines changed

Some content is hidden

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

133 files changed

+3676
-1949
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/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
10691069
}
10701070

10711071
def AsmLabel : InheritableAttr {
1072-
let Spellings = [CustomKeyword<"asm">, CustomKeyword<"__asm__">];
1072+
let Spellings = [CustomKeyword<"asm">, CustomKeyword<"__asm">, CustomKeyword<"__asm__">];
10731073
let Args = [
10741074
// Label specifies the mangled name for the decl.
10751075
StringArgument<"Label">, ];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,17 +4295,17 @@ used by other languages. (This prefix is also added to the standard Itanium
42954295
C++ ABI prefix on "mangled" symbol names, so that e.g. on such targets the true
42964296
symbol name for a C++ variable declared as ``int cppvar;`` would be
42974297
``__Z6cppvar``; note the two underscores.) This prefix is *not* added to the
4298-
symbol names specified by the ``asm`` attribute; programmers wishing to match a
4299-
C symbol name must compensate for this.
4298+
symbol names specified by the ``__asm`` attribute; programmers wishing to match
4299+
a C symbol name must compensate for this.
43004300

43014301
For example, consider the following C code:
43024302

43034303
.. code-block:: c
43044304

4305-
int var1 asm("altvar") = 1; // "altvar" in symbol table.
4305+
int var1 __asm("altvar") = 1; // "altvar" in symbol table.
43064306
int var2 = 1; // "_var2" in symbol table.
43074307

4308-
void func1(void) asm("altfunc");
4308+
void func1(void) __asm("altfunc");
43094309
void func1(void) {} // "altfunc" in symbol table.
43104310
void func2(void) {} // "_func2" in symbol table.
43114311

clang/lib/AST/ASTImporter.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,10 @@ namespace clang {
696696
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E);
697697
ExpectedStmt VisitRequiresExpr(RequiresExpr* E);
698698
ExpectedStmt VisitConceptSpecializationExpr(ConceptSpecializationExpr* E);
699+
ExpectedStmt
700+
VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E);
701+
ExpectedStmt VisitPseudoObjectExpr(PseudoObjectExpr *E);
702+
ExpectedStmt VisitCXXParenListInitExpr(CXXParenListInitExpr *E);
699703

700704
// Helper for chaining together multiple imports. If an error is detected,
701705
// subsequent imports will return default constructed nodes, so that failure
@@ -9273,6 +9277,50 @@ ASTNodeImporter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) {
92739277
const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
92749278
}
92759279

9280+
ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmPackExpr(
9281+
SubstNonTypeTemplateParmPackExpr *E) {
9282+
Error Err = Error::success();
9283+
auto ToType = importChecked(Err, E->getType());
9284+
auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9285+
auto ToArgPack = importChecked(Err, E->getArgumentPack());
9286+
auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9287+
if (Err)
9288+
return std::move(Err);
9289+
9290+
return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9291+
ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9292+
E->getIndex(), E->getFinal());
9293+
}
9294+
9295+
ExpectedStmt ASTNodeImporter::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
9296+
SmallVector<Expr *, 4> ToSemantics(E->getNumSemanticExprs());
9297+
if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9298+
return std::move(Err);
9299+
auto ToSyntOrErr = import(E->getSyntacticForm());
9300+
if (!ToSyntOrErr)
9301+
return ToSyntOrErr.takeError();
9302+
return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9303+
ToSemantics, E->getResultExprIndex());
9304+
}
9305+
9306+
ExpectedStmt
9307+
ASTNodeImporter::VisitCXXParenListInitExpr(CXXParenListInitExpr *E) {
9308+
Error Err = Error::success();
9309+
auto ToType = importChecked(Err, E->getType());
9310+
auto ToInitLoc = importChecked(Err, E->getInitLoc());
9311+
auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9312+
auto ToEndLoc = importChecked(Err, E->getEndLoc());
9313+
if (Err)
9314+
return std::move(Err);
9315+
9316+
SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9317+
if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9318+
return std::move(Err);
9319+
return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9320+
E->getUserSpecifiedInitExprs().size(),
9321+
ToInitLoc, ToBeginLoc, ToEndLoc);
9322+
}
9323+
92769324
Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod,
92779325
CXXMethodDecl *FromMethod) {
92789326
Error ImportErrors = Error::success();

clang/lib/CodeGen/CGCall.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/IR/Attributes.h"
3939
#include "llvm/IR/CallingConv.h"
4040
#include "llvm/IR/DataLayout.h"
41+
#include "llvm/IR/DebugInfoMetadata.h"
4142
#include "llvm/IR/InlineAsm.h"
4243
#include "llvm/IR/IntrinsicInst.h"
4344
#include "llvm/IR/Intrinsics.h"
@@ -6289,6 +6290,24 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
62896290
pushDestroy(QualType::DK_nontrivial_c_struct, Ret.getAggregateAddress(),
62906291
RetTy);
62916292

6293+
// Generate function declaration DISuprogram in order to be used
6294+
// in debug info about call sites.
6295+
if (CGDebugInfo *DI = getDebugInfo()) {
6296+
// Ensure call site info would actually be emitted before collecting
6297+
// further callee info.
6298+
if (CalleeDecl && !CalleeDecl->hasAttr<NoDebugAttr>() &&
6299+
DI->getCallSiteRelatedAttrs() != llvm::DINode::FlagZero) {
6300+
CodeGenFunction CalleeCGF(CGM);
6301+
const GlobalDecl &CalleeGlobalDecl =
6302+
Callee.getAbstractInfo().getCalleeDecl();
6303+
CalleeCGF.CurGD = CalleeGlobalDecl;
6304+
FunctionArgList Args;
6305+
QualType ResTy = CalleeCGF.BuildFunctionArgList(CalleeGlobalDecl, Args);
6306+
DI->EmitFuncDeclForCallSite(
6307+
CI, DI->getFunctionType(CalleeDecl, ResTy, Args), CalleeGlobalDecl);
6308+
}
6309+
}
6310+
62926311
return Ret;
62936312
}
62946313

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5019,7 +5019,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
50195019

50205020
void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
50215021
QualType CalleeType,
5022-
const FunctionDecl *CalleeDecl) {
5022+
GlobalDecl CalleeGlobalDecl) {
50235023
if (!CallOrInvoke)
50245024
return;
50255025
auto *Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
@@ -5028,6 +5028,9 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
50285028
if (Func->getSubprogram())
50295029
return;
50305030

5031+
const FunctionDecl *CalleeDecl =
5032+
cast<FunctionDecl>(CalleeGlobalDecl.getDecl());
5033+
50315034
// Do not emit a declaration subprogram for a function with nodebug
50325035
// attribute, or if call site info isn't required.
50335036
if (CalleeDecl->hasAttr<NoDebugAttr>() ||
@@ -5038,7 +5041,8 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
50385041
// create the one describing the function in order to have complete
50395042
// call site debug info.
50405043
if (!CalleeDecl->isStatic() && !CalleeDecl->isInlined())
5041-
EmitFunctionDecl(CalleeDecl, CalleeDecl->getLocation(), CalleeType, Func);
5044+
EmitFunctionDecl(CalleeGlobalDecl, CalleeDecl->getLocation(), CalleeType,
5045+
Func);
50425046
}
50435047

50445048
void CGDebugInfo::EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD) {

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class CGDebugInfo {
511511
/// This is needed for call site debug info.
512512
void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
513513
QualType CalleeType,
514-
const FunctionDecl *CalleeDecl);
514+
GlobalDecl CalleeGlobalDecl);
515515

516516
/// Constructs the debug code for exiting a function.
517517
void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn);
@@ -686,6 +686,10 @@ class CGDebugInfo {
686686
/// Emit symbol for debugger that holds the pointer to the vtable.
687687
void emitVTableSymbol(llvm::GlobalVariable *VTable, const CXXRecordDecl *RD);
688688

689+
/// Return flags which enable debug info emission for call sites, provided
690+
/// that it is supported and enabled.
691+
llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
692+
689693
private:
690694
/// Amend \p I's DebugLoc with \p Group (its source atom group) and \p
691695
/// Rank (lower nonzero rank is higher precedence). Does nothing if \p I
@@ -864,10 +868,6 @@ class CGDebugInfo {
864868
StringRef LinkageName, llvm::dwarf::MemorySpace MS,
865869
llvm::GlobalVariable *Var, llvm::DIScope *DContext);
866870

867-
/// Return flags which enable debug info emission for call sites, provided
868-
/// that it is supported and enabled.
869-
llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
870-
871871
/// Get the printing policy for producing names for debug info.
872872
PrintingPolicy getPrintingPolicy() const;
873873

0 commit comments

Comments
 (0)