Skip to content

Commit d178750

Browse files
committed
Do a final pass to address cosmetics.
1 parent 05b3c05 commit d178750

18 files changed

+197
-213
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
12811281
/// Return the "other" discriminator used for the pointer auth schema used for
12821282
/// vtable pointers in instances of the requested type.
12831283
uint16_t
1284-
getPointerAuthVTablePointerDiscriminator(const CXXRecordDecl *record);
1284+
getPointerAuthVTablePointerDiscriminator(const CXXRecordDecl *RD);
12851285

12861286
/// Apply Objective-C protocol qualifiers to the given type.
12871287
/// \param allowOnPointerType specifies if we can apply protocol
@@ -3446,9 +3446,10 @@ OPT_LIST(V)
34463446

34473447
/// Resolve the root record to be used to derive the vtable pointer
34483448
/// authentication policy for the specified record.
3449-
const CXXRecordDecl *baseForVTableAuthentication(const CXXRecordDecl *);
3450-
bool useAbbreviatedThunkName(GlobalDecl virtualMethodDecl,
3451-
StringRef mangledName);
3449+
const CXXRecordDecl *
3450+
baseForVTableAuthentication(const CXXRecordDecl *ThisClass);
3451+
bool useAbbreviatedThunkName(GlobalDecl VirtualMethodDecl,
3452+
StringRef MangledName);
34523453

34533454
StringRef getCUIDHash() const;
34543455

@@ -3457,7 +3458,7 @@ OPT_LIST(V)
34573458
/// `pragma omp [begin] declare variant` directive.
34583459
SmallVector<std::unique_ptr<OMPTraitInfo>, 4> OMPTraitInfoVector;
34593460

3460-
llvm::DenseMap<GlobalDecl, llvm::StringSet<>> thunksToBeAbbreviated;
3461+
llvm::DenseMap<GlobalDecl, llvm::StringSet<>> ThunksToBeAbbreviated;
34613462
};
34623463

34633464
/// Insertion operator for diagnostics.

clang/include/clang/AST/Mangle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ class MangleContext {
131131
void mangleName(GlobalDecl GD, raw_ostream &);
132132
virtual void mangleCXXName(GlobalDecl GD, raw_ostream &) = 0;
133133
virtual void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk,
134-
bool elideOverrideInfo, raw_ostream &) = 0;
134+
bool ElideOverrideInfo, raw_ostream &) = 0;
135135
virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
136136
const ThunkInfo &Thunk,
137-
bool elideOverrideInfo, raw_ostream &) = 0;
137+
bool ElideOverrideInfo, raw_ostream &) = 0;
138138
virtual void mangleReferenceTemporary(const VarDecl *D,
139139
unsigned ManglingNumber,
140140
raw_ostream &) = 0;

clang/include/clang/Basic/Thunk.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ struct ThunkInfo {
169169
/// CAUTION: In the unlikely event you need to sort ThunkInfos, consider using
170170
/// an ABI-specific comparator.
171171
const CXXMethodDecl *Method;
172-
const Type *ThisType{nullptr};
172+
const Type *ThisType;
173173

174-
ThunkInfo() : Method(nullptr) {}
174+
ThunkInfo() : Method(nullptr), ThisType(nullptr) {}
175175

176176
ThunkInfo(const ThisAdjustment &This, const ReturnAdjustment &Return,
177-
const Type *thisType, const CXXMethodDecl *Method = nullptr)
178-
: This(This), Return(Return), Method(Method), ThisType(thisType) {}
177+
const Type *ThisT, const CXXMethodDecl *Method = nullptr)
178+
: This(This), Return(Return), Method(Method), ThisType(ThisT) {}
179179

180180
friend bool operator==(const ThunkInfo &LHS, const ThunkInfo &RHS) {
181181
return LHS.This == RHS.This && LHS.Return == RHS.Return &&

clang/lib/AST/ASTContext.cpp

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,14 +3129,14 @@ QualType ASTContext::removeAddrSpaceQualType(QualType T) const {
31293129
return QualType(TypeNode, Quals.getFastQualifiers());
31303130
}
31313131

3132-
uint16_t ASTContext::getPointerAuthVTablePointerDiscriminator(
3133-
const CXXRecordDecl *record) {
3134-
assert(record->isPolymorphic() &&
3132+
uint16_t
3133+
ASTContext::getPointerAuthVTablePointerDiscriminator(const CXXRecordDecl *RD) {
3134+
assert(RD->isPolymorphic() &&
31353135
"Attempted to get vtable pointer discriminator on a monomorphic type");
31363136
std::unique_ptr<MangleContext> MC(createMangleContext());
31373137
SmallString<256> Str;
31383138
llvm::raw_svector_ostream Out(Str);
3139-
MC->mangleCXXVTable(record, Out);
3139+
MC->mangleCXXVTable(RD, Out);
31403140
return llvm::getPointerAuthStableSipHash(Str);
31413141
}
31423142

@@ -13908,75 +13908,72 @@ StringRef ASTContext::getCUIDHash() const {
1390813908
}
1390913909

1391013910
const CXXRecordDecl *
13911-
ASTContext::baseForVTableAuthentication(const CXXRecordDecl *thisClass) {
13912-
assert(thisClass);
13913-
assert(thisClass->isPolymorphic());
13914-
const CXXRecordDecl *primaryBase = thisClass;
13911+
ASTContext::baseForVTableAuthentication(const CXXRecordDecl *ThisClass) {
13912+
assert(ThisClass);
13913+
assert(ThisClass->isPolymorphic());
13914+
const CXXRecordDecl *PrimaryBase = ThisClass;
1391513915
while (1) {
13916-
assert(primaryBase);
13917-
assert(primaryBase->isPolymorphic());
13918-
auto &layout = getASTRecordLayout(primaryBase);
13919-
auto base = layout.getPrimaryBase();
13920-
if (!base || base == primaryBase || !base->isPolymorphic())
13916+
assert(PrimaryBase);
13917+
assert(PrimaryBase->isPolymorphic());
13918+
auto &Layout = getASTRecordLayout(PrimaryBase);
13919+
auto Base = Layout.getPrimaryBase();
13920+
if (!Base || Base == PrimaryBase || !Base->isPolymorphic())
1392113921
break;
13922-
primaryBase = base;
13922+
PrimaryBase = Base;
1392313923
}
13924-
return primaryBase;
13924+
return PrimaryBase;
1392513925
}
1392613926

13927-
bool ASTContext::useAbbreviatedThunkName(GlobalDecl virtualMethodDecl,
13928-
StringRef mangledName) {
13929-
auto method = cast<CXXMethodDecl>(virtualMethodDecl.getDecl());
13930-
assert(method->isVirtual());
13931-
bool defaultIncludesPointerAuth =
13927+
bool ASTContext::useAbbreviatedThunkName(GlobalDecl VirtualMethodDecl,
13928+
StringRef MangledName) {
13929+
auto *Method = cast<CXXMethodDecl>(VirtualMethodDecl.getDecl());
13930+
assert(Method->isVirtual());
13931+
bool DefaultIncludesPointerAuth =
1393213932
LangOpts.PointerAuthCalls || LangOpts.PointerAuthIntrinsics;
1393313933

13934-
if (!defaultIncludesPointerAuth)
13934+
if (!DefaultIncludesPointerAuth)
1393513935
return true;
1393613936

13937-
auto existing = thunksToBeAbbreviated.find(virtualMethodDecl);
13938-
if (existing != thunksToBeAbbreviated.end())
13939-
return existing->second.contains(mangledName.str());
13940-
13941-
std::unique_ptr<MangleContext> mangler(createMangleContext());
13942-
llvm::StringMap<llvm::SmallVector<std::string, 2>> thunks;
13943-
auto vtableContext = getVTableContext();
13944-
if (const auto *thunkInfos = vtableContext->getThunkInfo(virtualMethodDecl)) {
13945-
auto destructor = dyn_cast<CXXDestructorDecl>(method);
13946-
for (const auto &thunk : *thunkInfos) {
13947-
SmallString<256> elidedName;
13948-
llvm::raw_svector_ostream elidedNameStream(elidedName);
13949-
if (destructor) {
13950-
mangler->mangleCXXDtorThunk(destructor, virtualMethodDecl.getDtorType(),
13951-
thunk, /* elideOverrideInfo */ true,
13952-
elidedNameStream);
13953-
} else {
13954-
mangler->mangleThunk(method, thunk, /* elideOverrideInfo */ true,
13955-
elidedNameStream);
13956-
}
13957-
SmallString<256> mangledName;
13958-
llvm::raw_svector_ostream mangledNameStream(mangledName);
13959-
if (destructor) {
13960-
mangler->mangleCXXDtorThunk(destructor, virtualMethodDecl.getDtorType(),
13961-
thunk, /* elideOverrideInfo */ false,
13937+
auto Existing = ThunksToBeAbbreviated.find(VirtualMethodDecl);
13938+
if (Existing != ThunksToBeAbbreviated.end())
13939+
return Existing->second.contains(MangledName.str());
13940+
13941+
std::unique_ptr<MangleContext> Mangler(createMangleContext());
13942+
llvm::StringMap<llvm::SmallVector<std::string, 2>> Thunks;
13943+
auto VtableContext = getVTableContext();
13944+
if (const auto *ThunkInfos = VtableContext->getThunkInfo(VirtualMethodDecl)) {
13945+
auto *Destructor = dyn_cast<CXXDestructorDecl>(Method);
13946+
for (const auto &Thunk : *ThunkInfos) {
13947+
SmallString<256> ElidedName;
13948+
llvm::raw_svector_ostream ElidedNameStream(ElidedName);
13949+
if (Destructor)
13950+
Mangler->mangleCXXDtorThunk(Destructor, VirtualMethodDecl.getDtorType(),
13951+
Thunk, /* elideOverrideInfo */ true,
13952+
ElidedNameStream);
13953+
else
13954+
Mangler->mangleThunk(Method, Thunk, /* elideOverrideInfo */ true,
13955+
ElidedNameStream);
13956+
SmallString<256> MangledName;
13957+
llvm::raw_svector_ostream mangledNameStream(MangledName);
13958+
if (Destructor)
13959+
Mangler->mangleCXXDtorThunk(Destructor, VirtualMethodDecl.getDtorType(),
13960+
Thunk, /* elideOverrideInfo */ false,
1396213961
mangledNameStream);
13963-
} else {
13964-
mangler->mangleThunk(method, thunk, /* elideOverrideInfo */ false,
13962+
else
13963+
Mangler->mangleThunk(Method, Thunk, /* elideOverrideInfo */ false,
1396513964
mangledNameStream);
13966-
}
1396713965

13968-
if (thunks.find(elidedName) == thunks.end()) {
13969-
thunks[elidedName] = {};
13970-
}
13971-
thunks[elidedName].push_back(std::string(mangledName));
13966+
if (Thunks.find(ElidedName) == Thunks.end())
13967+
Thunks[ElidedName] = {};
13968+
Thunks[ElidedName].push_back(std::string(MangledName));
1397213969
}
1397313970
}
13974-
llvm::StringSet<> simplifiedThunkNames;
13975-
for (auto &thunkList : thunks) {
13976-
llvm::sort(thunkList.second);
13977-
simplifiedThunkNames.insert(thunkList.second[0]);
13971+
llvm::StringSet<> SimplifiedThunkNames;
13972+
for (auto &ThunkList : Thunks) {
13973+
llvm::sort(ThunkList.second);
13974+
SimplifiedThunkNames.insert(ThunkList.second[0]);
1397813975
}
13979-
bool result = simplifiedThunkNames.contains(mangledName);
13980-
thunksToBeAbbreviated[virtualMethodDecl] = std::move(simplifiedThunkNames);
13981-
return result;
13976+
bool Result = SimplifiedThunkNames.contains(MangledName);
13977+
ThunksToBeAbbreviated[VirtualMethodDecl] = std::move(SimplifiedThunkNames);
13978+
return Result;
1398213979
}

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class CXXNameMangler {
467467
void mangleNameOrStandardSubstitution(const NamedDecl *ND);
468468
void mangleLambdaSig(const CXXRecordDecl *Lambda);
469469
void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false);
470-
void mangleVendorQualifier(StringRef qualifier);
470+
void mangleVendorQualifier(StringRef Name);
471471

472472
private:
473473

@@ -7058,64 +7058,63 @@ void ItaniumMangleContextImpl::mangleCXXDtorComdat(const CXXDestructorDecl *D,
70587058
/// override schema, e.g. if the override has specified type based
70597059
/// discrimination the encoded value will be the discriminator derived from the
70607060
/// type name.
7061-
static void mangleOverrideDiscrimination(CXXNameMangler &mangler,
7062-
ASTContext &context,
7063-
const ThunkInfo &thunk) {
7064-
auto &langOpts = context.getLangOpts();
7065-
auto thisType = thunk.ThisType;
7066-
auto thisRecord = thisType->getPointeeCXXRecordDecl();
7067-
auto ptrauthClassRecord = context.baseForVTableAuthentication(thisRecord);
7068-
unsigned typedDiscriminator =
7069-
context.getPointerAuthVTablePointerDiscriminator(thisRecord);
7070-
mangler.mangleVendorQualifier("__vtptrauth");
7071-
auto &manglerStream = mangler.getStream();
7072-
manglerStream << "I";
7073-
if (auto explicitAuth =
7074-
ptrauthClassRecord->getAttr<VTablePointerAuthenticationAttr>()) {
7075-
manglerStream << "Lj" << explicitAuth->getKey();
7076-
7077-
if (explicitAuth->getAddressDiscrimination() ==
7078-
VTablePointerAuthenticationAttr::DefaultAddressDiscrimination) {
7079-
manglerStream << "Lb" << langOpts.PointerAuthVTPtrAddressDiscrimination;
7080-
} else {
7081-
manglerStream << "Lb"
7082-
<< (explicitAuth->getAddressDiscrimination() ==
7061+
static void mangleOverrideDiscrimination(CXXNameMangler &Mangler,
7062+
ASTContext &Context,
7063+
const ThunkInfo &Thunk) {
7064+
auto &LangOpts = Context.getLangOpts();
7065+
const CXXRecordDecl *ThisRD = Thunk.ThisType->getPointeeCXXRecordDecl();
7066+
const CXXRecordDecl *PtrauthClassRD =
7067+
Context.baseForVTableAuthentication(ThisRD);
7068+
unsigned TypedDiscriminator =
7069+
Context.getPointerAuthVTablePointerDiscriminator(ThisRD);
7070+
Mangler.mangleVendorQualifier("__vtptrauth");
7071+
auto &ManglerStream = Mangler.getStream();
7072+
ManglerStream << "I";
7073+
if (const auto *ExplicitAuth =
7074+
PtrauthClassRD->getAttr<VTablePointerAuthenticationAttr>()) {
7075+
ManglerStream << "Lj" << ExplicitAuth->getKey();
7076+
7077+
if (ExplicitAuth->getAddressDiscrimination() ==
7078+
VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7079+
ManglerStream << "Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7080+
else
7081+
ManglerStream << "Lb"
7082+
<< (ExplicitAuth->getAddressDiscrimination() ==
70837083
VTablePointerAuthenticationAttr::AddressDiscrimination);
7084-
}
70857084

7086-
switch (explicitAuth->getExtraDiscrimination()) {
7085+
switch (ExplicitAuth->getExtraDiscrimination()) {
70877086
case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7088-
if (langOpts.PointerAuthVTPtrTypeDiscrimination)
7089-
manglerStream << "Lj" << typedDiscriminator;
7087+
if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7088+
ManglerStream << "Lj" << TypedDiscriminator;
70907089
else
7091-
manglerStream << "Lj" << 0;
7090+
ManglerStream << "Lj" << 0;
70927091
break;
70937092
}
70947093
case VTablePointerAuthenticationAttr::TypeDiscrimination:
7095-
manglerStream << "Lj" << typedDiscriminator;
7094+
ManglerStream << "Lj" << TypedDiscriminator;
70967095
break;
70977096
case VTablePointerAuthenticationAttr::CustomDiscrimination:
7098-
manglerStream << "Lj" << explicitAuth->getCustomDiscriminationValue();
7097+
ManglerStream << "Lj" << ExplicitAuth->getCustomDiscriminationValue();
70997098
break;
71007099
case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7101-
manglerStream << "Lj" << 0;
7100+
ManglerStream << "Lj" << 0;
71027101
break;
71037102
}
71047103
} else {
7105-
manglerStream << "Lj"
7104+
ManglerStream << "Lj"
71067105
<< (unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7107-
manglerStream << "Lb" << langOpts.PointerAuthVTPtrAddressDiscrimination;
7108-
if (langOpts.PointerAuthVTPtrTypeDiscrimination)
7109-
manglerStream << "Lj" << typedDiscriminator;
7106+
ManglerStream << "Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7107+
if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7108+
ManglerStream << "Lj" << TypedDiscriminator;
71107109
else
7111-
manglerStream << "Lj" << 0;
7110+
ManglerStream << "Lj" << 0;
71127111
}
7113-
manglerStream << "E";
7112+
ManglerStream << "E";
71147113
}
71157114

71167115
void ItaniumMangleContextImpl::mangleThunk(const CXXMethodDecl *MD,
71177116
const ThunkInfo &Thunk,
7118-
bool elideOverrideInfo,
7117+
bool ElideOverrideInfo,
71197118
raw_ostream &Out) {
71207119
// <special-name> ::= T <call-offset> <base encoding>
71217120
// # base is the nominal target function of thunk
@@ -7141,15 +7140,14 @@ void ItaniumMangleContextImpl::mangleThunk(const CXXMethodDecl *MD,
71417140
Thunk.Return.Virtual.Itanium.VBaseOffsetOffset);
71427141

71437142
Mangler.mangleFunctionEncoding(MD);
7144-
if (!elideOverrideInfo) {
7143+
if (!ElideOverrideInfo)
71457144
mangleOverrideDiscrimination(Mangler, getASTContext(), Thunk);
7146-
}
71477145
}
71487146

71497147
void ItaniumMangleContextImpl::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
71507148
CXXDtorType Type,
71517149
const ThunkInfo &Thunk,
7152-
bool elideOverrideInfo,
7150+
bool ElideOverrideInfo,
71537151
raw_ostream &Out) {
71547152
// <special-name> ::= T <call-offset> <base encoding>
71557153
// # base is the nominal target function of thunk
@@ -7162,7 +7160,7 @@ void ItaniumMangleContextImpl::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
71627160
ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
71637161

71647162
Mangler.mangleFunctionEncoding(GlobalDecl(DD, Type));
7165-
if (!elideOverrideInfo)
7163+
if (!ElideOverrideInfo)
71667164
mangleOverrideDiscrimination(Mangler, getASTContext(), Thunk);
71677165
}
71687166

clang/lib/AST/Mangle.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,14 @@ class ASTNameGenerator::Implementation {
516516
if (MD->isVirtual()) {
517517
if (const auto *TIV = Ctx.getVTableContext()->getThunkInfo(MD)) {
518518
for (const auto &T : *TIV) {
519-
std::string thunkName;
520-
std::string contextualizedName =
521-
getMangledThunk(MD, T, /* elideOverrideInfo */ false);
522-
if (Ctx.useAbbreviatedThunkName(MD, contextualizedName))
523-
thunkName = getMangledThunk(MD, T, /* elideOverrideInfo */ true);
519+
std::string ThunkName;
520+
std::string ContextualizedName =
521+
getMangledThunk(MD, T, /* ElideOverrideInfo */ false);
522+
if (Ctx.useAbbreviatedThunkName(MD, ContextualizedName))
523+
ThunkName = getMangledThunk(MD, T, /* ElideOverrideInfo */ true);
524524
else
525-
thunkName = contextualizedName;
526-
Manglings.emplace_back(thunkName);
525+
ThunkName = ContextualizedName;
526+
Manglings.emplace_back(ThunkName);
527527
}
528528
}
529529
}
@@ -580,11 +580,11 @@ class ASTNameGenerator::Implementation {
580580
}
581581

582582
std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo &T,
583-
bool elideOverrideInfo) {
583+
bool ElideOverrideInfo) {
584584
std::string FrontendBuf;
585585
llvm::raw_string_ostream FOS(FrontendBuf);
586586

587-
MC->mangleThunk(MD, T, elideOverrideInfo, FOS);
587+
MC->mangleThunk(MD, T, ElideOverrideInfo, FOS);
588588

589589
std::string BackendBuf;
590590
llvm::raw_string_ostream BOS(BackendBuf);

0 commit comments

Comments
 (0)