Skip to content

Commit b120fe8

Browse files
committed
[clang][NFC] Refactor ArgPassingKind
This patch moves `RecordDecl::ArgPassingKind` to DeclBase.h to namespace scope, so that it's complete at the time bit-field is declared.
1 parent 760658c commit b120fe8

File tree

11 files changed

+44
-43
lines changed

11 files changed

+44
-43
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4069,28 +4069,6 @@ class RecordDecl : public TagDecl {
40694069
public:
40704070
friend class DeclContext;
40714071
friend class ASTDeclReader;
4072-
/// Enum that represents the different ways arguments are passed to and
4073-
/// returned from function calls. This takes into account the target-specific
4074-
/// and version-specific rules along with the rules determined by the
4075-
/// language.
4076-
enum ArgPassingKind : unsigned {
4077-
/// The argument of this type can be passed directly in registers.
4078-
APK_CanPassInRegs,
4079-
4080-
/// The argument of this type cannot be passed directly in registers.
4081-
/// Records containing this type as a subobject are not forced to be passed
4082-
/// indirectly. This value is used only in C++. This value is required by
4083-
/// C++ because, in uncommon situations, it is possible for a class to have
4084-
/// only trivial copy/move constructors even when one of its subobjects has
4085-
/// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
4086-
/// constructor in the derived class is deleted).
4087-
APK_CannotPassInRegs,
4088-
4089-
/// The argument of this type cannot be passed directly in registers.
4090-
/// Records containing this type as a subobject are forced to be passed
4091-
/// indirectly.
4092-
APK_CanNeverPassInRegs
4093-
};
40944072

40954073
protected:
40964074
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
@@ -4215,15 +4193,15 @@ class RecordDecl : public TagDecl {
42154193
/// it must have at least one trivial, non-deleted copy or move constructor.
42164194
/// FIXME: This should be set as part of completeDefinition.
42174195
bool canPassInRegisters() const {
4218-
return getArgPassingRestrictions() == APK_CanPassInRegs;
4196+
return getArgPassingRestrictions() == ArgPassingKind::CanPassInRegs;
42194197
}
42204198

42214199
ArgPassingKind getArgPassingRestrictions() const {
42224200
return static_cast<ArgPassingKind>(RecordDeclBits.ArgPassingRestrictions);
42234201
}
42244202

42254203
void setArgPassingRestrictions(ArgPassingKind Kind) {
4226-
RecordDeclBits.ArgPassingRestrictions = Kind;
4204+
RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
42274205
}
42284206

42294207
bool isParamDestroyedInCallee() const {

clang/include/clang/AST/DeclBase.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,29 @@ enum class DeductionCandidate : unsigned char {
13991399
Aggregate,
14001400
};
14011401

1402+
/// Enum that represents the different ways arguments are passed to and
1403+
/// returned from function calls. This takes into account the target-specific
1404+
/// and version-specific rules along with the rules determined by the
1405+
/// language.
1406+
enum class ArgPassingKind {
1407+
/// The argument of this type can be passed directly in registers.
1408+
CanPassInRegs,
1409+
1410+
/// The argument of this type cannot be passed directly in registers.
1411+
/// Records containing this type as a subobject are not forced to be passed
1412+
/// indirectly. This value is used only in C++. This value is required by
1413+
/// C++ because, in uncommon situations, it is possible for a class to have
1414+
/// only trivial copy/move constructors even when one of its subobjects has
1415+
/// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
1416+
/// constructor in the derived class is deleted).
1417+
CannotPassInRegs,
1418+
1419+
/// The argument of this type cannot be passed directly in registers.
1420+
/// Records containing this type as a subobject are forced to be passed
1421+
/// indirectly.
1422+
CanNeverPassInRegs
1423+
};
1424+
14021425
/// DeclContext - This is used only as base class of specific decl types that
14031426
/// can act as declaration contexts. These decls are (only the top classes
14041427
/// that directly derive from DeclContext are mentioned, not their subclasses):

clang/lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4932,7 +4932,7 @@ RecordDecl::RecordDecl(Kind DK, TagKind TK, const ASTContext &C,
49324932
setHasNonTrivialToPrimitiveDestructCUnion(false);
49334933
setHasNonTrivialToPrimitiveCopyCUnion(false);
49344934
setParamDestroyedInCallee(false);
4935-
setArgPassingRestrictions(APK_CanPassInRegs);
4935+
setArgPassingRestrictions(ArgPassingKind::CanPassInRegs);
49364936
setIsRandomized(false);
49374937
setODRHash(0);
49384938
}

clang/lib/AST/DeclCXX.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
446446
setHasVolatileMember(true);
447447

448448
if (BaseClassDecl->getArgPassingRestrictions() ==
449-
RecordDecl::APK_CanNeverPassInRegs)
450-
setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
449+
ArgPassingKind::CanNeverPassInRegs)
450+
setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
451451

452452
// Keep track of the presence of mutable fields.
453453
if (BaseClassDecl->hasMutableFields())
@@ -1032,7 +1032,7 @@ void CXXRecordDecl::addedMember(Decl *D) {
10321032

10331033
// Structs with __weak fields should never be passed directly.
10341034
if (LT == Qualifiers::OCL_Weak)
1035-
setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
1035+
setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
10361036

10371037
Data.HasIrrelevantDestructor = false;
10381038

@@ -1226,8 +1226,8 @@ void CXXRecordDecl::addedMember(Decl *D) {
12261226
if (FieldRec->hasVolatileMember())
12271227
setHasVolatileMember(true);
12281228
if (FieldRec->getArgPassingRestrictions() ==
1229-
RecordDecl::APK_CanNeverPassInRegs)
1230-
setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
1229+
ArgPassingKind::CanNeverPassInRegs)
1230+
setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
12311231

12321232
// C++0x [class]p7:
12331233
// A standard-layout class is a class that:

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
27192719

27202720
auto *Decl = ParamType->getAsRecordDecl();
27212721
if (CodeGenOpts.PassByValueIsNoAlias && Decl &&
2722-
Decl->getArgPassingRestrictions() == RecordDecl::APK_CanPassInRegs)
2722+
Decl->getArgPassingRestrictions() == ArgPassingKind::CanPassInRegs)
27232723
// When calling the function, the pointer passed in will be the only
27242724
// reference to the underlying object. Mark it accordingly.
27252725
Attrs.addAttribute(llvm::Attribute::NoAlias);

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19197,10 +19197,10 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1919719197

1919819198
if (const auto *RT = FT->getAs<RecordType>()) {
1919919199
if (RT->getDecl()->getArgPassingRestrictions() ==
19200-
RecordDecl::APK_CanNeverPassInRegs)
19201-
Record->setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
19200+
ArgPassingKind::CanNeverPassInRegs)
19201+
Record->setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
1920219202
} else if (FT.getQualifiers().getObjCLifetime() == Qualifiers::OCL_Weak)
19203-
Record->setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
19203+
Record->setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
1920419204
}
1920519205

1920619206
if (Record && FD->getType().isVolatileQualified())

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7280,11 +7280,11 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
72807280
bool CanPass = canPassInRegisters(*this, Record, CCK);
72817281

72827282
// Do not change ArgPassingRestrictions if it has already been set to
7283-
// APK_CanNeverPassInRegs.
7284-
if (Record->getArgPassingRestrictions() != RecordDecl::APK_CanNeverPassInRegs)
7283+
// ArgPassingKind::CanNeverPassInRegs.
7284+
if (Record->getArgPassingRestrictions() != ArgPassingKind::CanNeverPassInRegs)
72857285
Record->setArgPassingRestrictions(CanPass
7286-
? RecordDecl::APK_CanPassInRegs
7287-
: RecordDecl::APK_CannotPassInRegs);
7286+
? ArgPassingKind::CanPassInRegs
7287+
: ArgPassingKind::CannotPassInRegs);
72887288

72897289
// If canPassInRegisters returns true despite the record having a non-trivial
72907290
// destructor, the record is destructed in the callee. This happens only when

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) {
845845
RD->setHasNonTrivialToPrimitiveDestructCUnion(Record.readInt());
846846
RD->setHasNonTrivialToPrimitiveCopyCUnion(Record.readInt());
847847
RD->setParamDestroyedInCallee(Record.readInt());
848-
RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)Record.readInt());
848+
RD->setArgPassingRestrictions((ArgPassingKind)Record.readInt());
849849
return Redecl;
850850
}
851851

@@ -4513,7 +4513,7 @@ void ASTDeclReader::UpdateDecl(Decl *D,
45134513
!Reader.PendingFakeDefinitionData.count(OldDD));
45144514
RD->setParamDestroyedInCallee(Record.readInt());
45154515
RD->setArgPassingRestrictions(
4516-
(RecordDecl::ArgPassingKind)Record.readInt());
4516+
static_cast<ArgPassingKind>(Record.readInt()));
45174517
ReadCXXRecordDefinition(RD, /*Update*/true);
45184518

45194519
// Visible update is handled separately.

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5302,7 +5302,7 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
53025302
auto *RD = cast<CXXRecordDecl>(D);
53035303
UpdatedDeclContexts.insert(RD->getPrimaryContext());
53045304
Record.push_back(RD->isParamDestroyedInCallee());
5305-
Record.push_back(RD->getArgPassingRestrictions());
5305+
Record.push_back(llvm::to_underlying(RD->getArgPassingRestrictions()));
53065306
Record.AddCXXDefinitionData(RD);
53075307
Record.AddOffset(WriteDeclContextLexicalBlock(
53085308
*Context, const_cast<CXXRecordDecl *>(RD)));

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
522522
Record.push_back(D->hasNonTrivialToPrimitiveDestructCUnion());
523523
Record.push_back(D->hasNonTrivialToPrimitiveCopyCUnion());
524524
Record.push_back(D->isParamDestroyedInCallee());
525-
Record.push_back(D->getArgPassingRestrictions());
525+
Record.push_back(llvm::to_underlying(D->getArgPassingRestrictions()));
526526
// Only compute this for C/Objective-C, in C++ this is computed as part
527527
// of CXXRecordDecl.
528528
if (!isa<CXXRecordDecl>(D))

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
19291929
m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
19301930
if (record_decl)
19311931
record_decl->setArgPassingRestrictions(
1932-
clang::RecordDecl::APK_CannotPassInRegs);
1932+
clang::ArgPassingKind::CannotPassInRegs);
19331933
}
19341934
return type_sp;
19351935
}

0 commit comments

Comments
 (0)