Skip to content

Commit

Permalink
Merge pull request #7745 from apple/merging-b120fe8d3288-manually
Browse files Browse the repository at this point in the history
Merge commit 'b120fe8d3288' from llvm.org/main into next
  • Loading branch information
fahadnayyar authored Nov 2, 2023
2 parents 0d62e52 + d49fe3f commit 625c9f5
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 67 deletions.
48 changes: 2 additions & 46 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4059,28 +4059,6 @@ class EnumDecl : public TagDecl {
static bool classofKind(Kind K) { return K == Enum; }
};

/// Enum that represents the different 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
};

/// Represents a struct/union/class. For example:
/// struct X; // Forward declaration, no "body".
Expand All @@ -4092,28 +4070,6 @@ class RecordDecl : public TagDecl {
public:
friend class DeclContext;
friend class ASTDeclReader;
/// Enum that represents the different 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,
Expand Down Expand Up @@ -4238,15 +4194,15 @@ 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 {
return static_cast<ArgPassingKind>(RecordDeclBits.ArgPassingRestrictions);
}

void setArgPassingRestrictions(ArgPassingKind Kind) {
RecordDeclBits.ArgPassingRestrictions = Kind;
RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
}

bool isParamDestroyedInCallee() const {
Expand Down
23 changes: 23 additions & 0 deletions clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,29 @@ enum class OMPDeclareReductionInitKind;
enum class ObjCImplementationControl;
enum class LinkageSpecLanguageIDs;

/// Enum that represents the different 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):
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4933,7 +4933,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);
}
Expand Down
12 changes: 6 additions & 6 deletions clang/lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1064,7 +1064,7 @@ void CXXRecordDecl::addedMember(Decl *D) {
Data.HasTrivialSpecialMembers &=
~(SMF_CopyConstructor | SMF_MoveConstructor |
SMF_CopyAssignment | SMF_MoveAssignment);
setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);

// Copy/move constructors/assignment operators of a union are deleted by
// default if it has an address-discriminated ptrauth field.
Expand Down Expand Up @@ -1253,8 +1253,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:
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,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);
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19222,13 +19222,13 @@ 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);
} else if (PointerAuthQualifier Q = FT.getPointerAuth()) {
if (Q.isAddressDiscriminated())
Record->setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
Record->setArgPassingRestrictions(ArgPassingKind::CanNeverPassInRegs);
}
}

Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -4517,7 +4517,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.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5293,7 +5293,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)));
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Serialization/ASTWriterDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 625c9f5

Please sign in to comment.