[Lldb-commits] [lldb] b120fe8 - [clang][NFC] Refactor `ArgPassingKind`
Vlad Serebrennikov via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 1 01:50:08 PDT 2023
Author: Vlad Serebrennikov
Date: 2023-11-01T11:49:59+03:00
New Revision: b120fe8d3288c4dca1b5427ca34839ce8833f71c
URL: https://github.com/llvm/llvm-project/commit/b120fe8d3288c4dca1b5427ca34839ce8833f71c
DIFF: https://github.com/llvm/llvm-project/commit/b120fe8d3288c4dca1b5427ca34839ce8833f71c.diff
LOG: [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.
Added:
Modified:
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7f076cc77ea82cb..1c2158f51aa184d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4069,28 +4069,6 @@ class RecordDecl : public TagDecl {
public:
friend class DeclContext;
friend class ASTDeclReader;
- /// Enum that represents the
diff erent ways arguments are passed to and
- /// returned from function calls. This takes into account the target-specific
- /// and version-specific rules along with the rules determined by the
- /// language.
- enum ArgPassingKind : unsigned {
- /// The argument of this type can be passed directly in registers.
- APK_CanPassInRegs,
-
- /// The argument of this type cannot be passed directly in registers.
- /// Records containing this type as a subobject are not forced to be passed
- /// indirectly. This value is used only in C++. This value is required by
- /// C++ because, in uncommon situations, it is possible for a class to have
- /// only trivial copy/move constructors even when one of its subobjects has
- /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
- /// constructor in the derived class is deleted).
- APK_CannotPassInRegs,
-
- /// The argument of this type cannot be passed directly in registers.
- /// Records containing this type as a subobject are forced to be passed
- /// indirectly.
- APK_CanNeverPassInRegs
- };
protected:
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
@@ -4215,7 +4193,7 @@ class RecordDecl : public TagDecl {
/// it must have at least one trivial, non-deleted copy or move constructor.
/// FIXME: This should be set as part of completeDefinition.
bool canPassInRegisters() const {
- return getArgPassingRestrictions() == APK_CanPassInRegs;
+ return getArgPassingRestrictions() == ArgPassingKind::CanPassInRegs;
}
ArgPassingKind getArgPassingRestrictions() const {
@@ -4223,7 +4201,7 @@ class RecordDecl : public TagDecl {
}
void setArgPassingRestrictions(ArgPassingKind Kind) {
- RecordDeclBits.ArgPassingRestrictions = Kind;
+ RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
}
bool isParamDestroyedInCallee() const {
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 978e4255e877ec2..ba6dadd7d3563c3 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1399,6 +1399,29 @@ enum class DeductionCandidate : unsigned char {
Aggregate,
};
+/// Enum that represents the
diff erent ways arguments are passed to and
+/// returned from function calls. This takes into account the target-specific
+/// and version-specific rules along with the rules determined by the
+/// language.
+enum class ArgPassingKind {
+ /// The argument of this type can be passed directly in registers.
+ CanPassInRegs,
+
+ /// The argument of this type cannot be passed directly in registers.
+ /// Records containing this type as a subobject are not forced to be passed
+ /// indirectly. This value is used only in C++. This value is required by
+ /// C++ because, in uncommon situations, it is possible for a class to have
+ /// only trivial copy/move constructors even when one of its subobjects has
+ /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
+ /// constructor in the derived class is deleted).
+ CannotPassInRegs,
+
+ /// The argument of this type cannot be passed directly in registers.
+ /// Records containing this type as a subobject are forced to be passed
+ /// indirectly.
+ CanNeverPassInRegs
+};
+
/// DeclContext - This is used only as base class of specific decl types that
/// can act as declaration contexts. These decls are (only the top classes
/// that directly derive from DeclContext are mentioned, not their subclasses):
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 480639606d22525..28243a76712d63e 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4932,7 +4932,7 @@ RecordDecl::RecordDecl(Kind DK, TagKind TK, const ASTContext &C,
setHasNonTrivialToPrimitiveDestructCUnion(false);
setHasNonTrivialToPrimitiveCopyCUnion(false);
setParamDestroyedInCallee(false);
- setArgPassingRestrictions(APK_CanPassInRegs);
+ setArgPassingRestrictions(ArgPassingKind::CanPassInRegs);
setIsRandomized(false);
setODRHash(0);
}
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 9107525a44f22c2..7f42decda51216f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -446,8 +446,8 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
setHasVolatileMember(true);
if (BaseClassDecl->getArgPassingRestrictions() ==
- RecordDecl::APK_CanNeverPassInRegs)
- setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
+ ArgPassingKind::CanNeverPassInRegs)
+ setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
// Keep track of the presence of mutable fields.
if (BaseClassDecl->hasMutableFields())
@@ -1032,7 +1032,7 @@ void CXXRecordDecl::addedMember(Decl *D) {
// Structs with __weak fields should never be passed directly.
if (LT == Qualifiers::OCL_Weak)
- setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
+ setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
Data.HasIrrelevantDestructor = false;
@@ -1226,8 +1226,8 @@ void CXXRecordDecl::addedMember(Decl *D) {
if (FieldRec->hasVolatileMember())
setHasVolatileMember(true);
if (FieldRec->getArgPassingRestrictions() ==
- RecordDecl::APK_CanNeverPassInRegs)
- setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
+ ArgPassingKind::CanNeverPassInRegs)
+ setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
// C++0x [class]p7:
// A standard-layout class is a class that:
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d0ee70c8d712727..d8168e35decb0ca 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2719,7 +2719,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
auto *Decl = ParamType->getAsRecordDecl();
if (CodeGenOpts.PassByValueIsNoAlias && Decl &&
- Decl->getArgPassingRestrictions() == RecordDecl::APK_CanPassInRegs)
+ Decl->getArgPassingRestrictions() == ArgPassingKind::CanPassInRegs)
// When calling the function, the pointer passed in will be the only
// reference to the underlying object. Mark it accordingly.
Attrs.addAttribute(llvm::Attribute::NoAlias);
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 824267acbb1c04e..96128850f5be0c1 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19197,10 +19197,10 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
if (const auto *RT = FT->getAs<RecordType>()) {
if (RT->getDecl()->getArgPassingRestrictions() ==
- RecordDecl::APK_CanNeverPassInRegs)
- Record->setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
+ ArgPassingKind::CanNeverPassInRegs)
+ Record->setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
} else if (FT.getQualifiers().getObjCLifetime() == Qualifiers::OCL_Weak)
- Record->setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
+ Record->setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
}
if (Record && FD->getType().isVolatileQualified())
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 5b6d452ebf4ea1e..8d74ecd375f6737 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7280,11 +7280,11 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
bool CanPass = canPassInRegisters(*this, Record, CCK);
// Do not change ArgPassingRestrictions if it has already been set to
- // APK_CanNeverPassInRegs.
- if (Record->getArgPassingRestrictions() != RecordDecl::APK_CanNeverPassInRegs)
+ // ArgPassingKind::CanNeverPassInRegs.
+ if (Record->getArgPassingRestrictions() != ArgPassingKind::CanNeverPassInRegs)
Record->setArgPassingRestrictions(CanPass
- ? RecordDecl::APK_CanPassInRegs
- : RecordDecl::APK_CannotPassInRegs);
+ ? ArgPassingKind::CanPassInRegs
+ : ArgPassingKind::CannotPassInRegs);
// If canPassInRegisters returns true despite the record having a non-trivial
// destructor, the record is destructed in the callee. This happens only when
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 3a3477c39efae25..470a648098e2ed9 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -845,7 +845,7 @@ ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) {
RD->setHasNonTrivialToPrimitiveDestructCUnion(Record.readInt());
RD->setHasNonTrivialToPrimitiveCopyCUnion(Record.readInt());
RD->setParamDestroyedInCallee(Record.readInt());
- RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)Record.readInt());
+ RD->setArgPassingRestrictions((ArgPassingKind)Record.readInt());
return Redecl;
}
@@ -4513,7 +4513,7 @@ void ASTDeclReader::UpdateDecl(Decl *D,
!Reader.PendingFakeDefinitionData.count(OldDD));
RD->setParamDestroyedInCallee(Record.readInt());
RD->setArgPassingRestrictions(
- (RecordDecl::ArgPassingKind)Record.readInt());
+ static_cast<ArgPassingKind>(Record.readInt()));
ReadCXXRecordDefinition(RD, /*Update*/true);
// Visible update is handled separately.
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 739344b9a128dcf..ab70594607530f4 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5302,7 +5302,7 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
auto *RD = cast<CXXRecordDecl>(D);
UpdatedDeclContexts.insert(RD->getPrimaryContext());
Record.push_back(RD->isParamDestroyedInCallee());
- Record.push_back(RD->getArgPassingRestrictions());
+ Record.push_back(llvm::to_underlying(RD->getArgPassingRestrictions()));
Record.AddCXXDefinitionData(RD);
Record.AddOffset(WriteDeclContextLexicalBlock(
*Context, const_cast<CXXRecordDecl *>(RD)));
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index b3364113abf15ba..7f6a23cf6b8c10d 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -522,7 +522,7 @@ void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Record.push_back(D->hasNonTrivialToPrimitiveDestructCUnion());
Record.push_back(D->hasNonTrivialToPrimitiveCopyCUnion());
Record.push_back(D->isParamDestroyedInCallee());
- Record.push_back(D->getArgPassingRestrictions());
+ Record.push_back(llvm::to_underlying(D->getArgPassingRestrictions()));
// Only compute this for C/Objective-C, in C++ this is computed as part
// of CXXRecordDecl.
if (!isa<CXXRecordDecl>(D))
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 182cc6764651747..83bc67c0a12cac4 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1929,7 +1929,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
if (record_decl)
record_decl->setArgPassingRestrictions(
- clang::RecordDecl::APK_CannotPassInRegs);
+ clang::ArgPassingKind::CannotPassInRegs);
}
return type_sp;
}
More information about the lldb-commits
mailing list