Skip to content

Commit 0c8b9cb

Browse files
committed
[clang] [WIP] MicrosoftCXXABI: save and load the RecordToCopyCtor table (#53486)
- Replaces the previous attempt at restoring the table - The implementation is currently broken
1 parent eef3907 commit 0c8b9cb

20 files changed

+102
-35
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,6 +3289,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
32893289
const FunctionDecl *FD,
32903290
llvm::function_ref<void(FunctionDecl *)> Pred) const;
32913291

3292+
const llvm::SmallDenseMap<CXXRecordDecl *, CXXConstructorDecl *> *
3293+
getRecordToCopyCtor() const;
3294+
32923295
const CXXConstructorDecl *
32933296
getCopyConstructorForExceptionObject(CXXRecordDecl *RD);
32943297

clang/include/clang/AST/CXXRecordDeclDefinitionBits.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,6 @@ FIELD(HasDeclaredCopyAssignmentWithConstParam, 1, MERGE_OR)
249249
/// base classes or fields have a no-return destructor
250250
FIELD(IsAnyDestructorNoReturn, 1, NO_MERGE)
251251

252-
/// Microsoft CXX ABI specific:
253-
/// Whether the copy constructor is used by a `throw` expression.
254-
/// Used by ASTReader to restore the sidecar RecordToCopyCtor LUT.
255-
FIELD(HasCopyConstructorForExceptionObject, 1, MERGE_OR)
256-
257252
/// Whether the record type is intangible (if any base classes or fields have
258253
/// type that is intangible). HLSL only.
259254
FIELD(IsHLSLIntangible, 1, NO_MERGE)

clang/include/clang/AST/DeclCXX.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,14 +1558,6 @@ class CXXRecordDecl : public RecordDecl {
15581558
/// a field or in base class.
15591559
bool isHLSLIntangible() const { return data().IsHLSLIntangible; }
15601560

1561-
bool hasCopyConstructorForExceptionObject() const {
1562-
return data().HasCopyConstructorForExceptionObject;
1563-
}
1564-
1565-
void setHasCopyConstructorForExceptionObject() {
1566-
data().HasCopyConstructorForExceptionObject = true;
1567-
}
1568-
15691561
/// If the class is a local class [class.local], returns
15701562
/// the enclosing function declaration.
15711563
const FunctionDecl *isLocalClass() const {

clang/include/clang/Sema/ExternalSemaSource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ class ExternalSemaSource : public ExternalASTSource {
200200
virtual void
201201
ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector<Decl *, 4> &Decls) {}
202202

203+
virtual void ReadRecordExceptionCopyingConstructors(
204+
llvm::MapVector<CXXRecordDecl *, CXXConstructorDecl *> &RecordToCtor) {}
205+
203206
/// \copydoc Sema::CorrectTypo
204207
/// \note LookupKind must correspond to a valid Sema::LookupNameKind
205208
///

clang/include/clang/Sema/MultiplexExternalSemaSource.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
345345
void ReadDeclsToCheckForDeferredDiags(
346346
llvm::SmallSetVector<Decl *, 4> &Decls) override;
347347

348+
void ReadRecordExceptionCopyingConstructors(
349+
llvm::MapVector<CXXRecordDecl *,
350+
CXXConstructorDecl *> &RecordToCtor) override;
351+
348352
/// \copydoc ExternalSemaSource::CorrectTypo
349353
/// \note Returns the first nonempty correction.
350354
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5427,6 +5427,8 @@ class Sema final : public SemaBase {
54275427
/// \returns true if any work was done, false otherwise.
54285428
bool DefineUsedVTables();
54295429

5430+
void LoadExternalRecordToExceptionCopyingCtor();
5431+
54305432
/// AddImplicitlyDeclaredMembersToClass - Adds any implicitly-declared
54315433
/// special functions, such as the default constructor, copy
54325434
/// constructor, or destructor, to the given C++ class (C++

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ enum ASTRecordTypes {
742742
UPDATE_MODULE_LOCAL_VISIBLE = 76,
743743

744744
UPDATE_TU_LOCAL_VISIBLE = 77,
745+
746+
MSCXXABI_EXCEPTION_COPYING_CONSTRUCTORS = 78,
745747
};
746748

747749
/// Record types used within a source manager block.

clang/include/clang/Serialization/ASTReader.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,12 @@ class ASTReader
10441044
/// The IDs of all decls with function effects to be checked.
10451045
SmallVector<GlobalDeclID> DeclsWithEffectsToVerify;
10461046

1047+
struct RecordAndCopyingCtor {
1048+
GlobalDeclID RecordID;
1049+
GlobalDeclID CtorID;
1050+
};
1051+
SmallVector<RecordAndCopyingCtor> RecordToCopyingCtor;
1052+
10471053
private:
10481054
struct ImportedSubmodule {
10491055
serialization::SubmoduleID ID;
@@ -2289,6 +2295,10 @@ class ASTReader
22892295
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
22902296
&LPTMap) override;
22912297

2298+
void ReadRecordExceptionCopyingConstructors(
2299+
llvm::MapVector<CXXRecordDecl *,
2300+
CXXConstructorDecl *> &RecordToCtor) override;
2301+
22922302
void AssignedLambdaNumbering(CXXRecordDecl *Lambda) override;
22932303

22942304
/// Load a selector from disk, registering its ID if it exists.

clang/lib/AST/ASTContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13103,6 +13103,11 @@ ASTContext::createMangleNumberingContext() const {
1310313103
return ABI->createMangleNumberingContext();
1310413104
}
1310513105

13106+
const llvm::SmallDenseMap<CXXRecordDecl *, CXXConstructorDecl *> *
13107+
ASTContext::getRecordToCopyCtor() const {
13108+
return ABI->getRecordToCopyCtor();
13109+
}
13110+
1310613111
const CXXConstructorDecl *
1310713112
ASTContext::getCopyConstructorForExceptionObject(CXXRecordDecl *RD) {
1310813113
return ABI->getCopyConstructorForExceptionObject(

clang/lib/AST/CXXABI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class CXXABI {
5656
virtual void addCopyConstructorForExceptionObject(CXXRecordDecl *,
5757
CXXConstructorDecl *) = 0;
5858

59+
virtual const llvm::SmallDenseMap<CXXRecordDecl *, CXXConstructorDecl *> *
60+
getRecordToCopyCtor() const = 0;
61+
5962
/// Retrieves the mapping from class to copy constructor for this C++ ABI.
6063
virtual const CXXConstructorDecl *
6164
getCopyConstructorForExceptionObject(CXXRecordDecl *) = 0;

0 commit comments

Comments
 (0)