Skip to content

Commit 76a5546

Browse files
authored
Merge pull request #542 from bcardosolopes/apple-stable-20200108-merge-tag-types
[Modules] Handle tag types and complain about bad merges in C/Objective-C mode
2 parents 4f93870 + e54af19 commit 76a5546

File tree

11 files changed

+791
-115
lines changed

11 files changed

+791
-115
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3716,6 +3716,7 @@ class RecordDecl : public TagDecl {
37163716
// to save some space. Use the provided accessors to access it.
37173717
public:
37183718
friend class DeclContext;
3719+
friend class ASTDeclReader;
37193720
/// Enum that represents the different ways arguments are passed to and
37203721
/// returned from function calls. This takes into account the target-specific
37213722
/// and version-specific rules along with the rules determined by the
@@ -3960,9 +3961,19 @@ class RecordDecl : public TagDecl {
39603961
/// nullptr is returned if no named data member exists.
39613962
const FieldDecl *findFirstNamedDataMember() const;
39623963

3964+
/// Get precomputed ODRHash or add a new one.
3965+
unsigned getODRHash();
3966+
39633967
private:
39643968
/// Deserialize just the fields.
39653969
void LoadFieldsFromExternalStorage() const;
3970+
3971+
/// True if a valid hash is stored in ODRHash.
3972+
bool hasODRHash() const { return RecordDeclBits.HasODRHash; }
3973+
void setHasODRHash(bool Hash = true) { RecordDeclBits.HasODRHash = Hash; }
3974+
3975+
/// Store the ODR hash for this decl.
3976+
unsigned ODRHash;
39663977
};
39673978

39683979
class FileScopeAsmDecl : public Decl {

clang/include/clang/AST/DeclBase.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,10 +1452,13 @@ class DeclContext {
14521452

14531453
/// Represents the way this type is passed to a function.
14541454
uint64_t ArgPassingRestrictions : 2;
1455+
1456+
/// True if a valid hash is stored in ODRHash.
1457+
uint64_t HasODRHash : 1;
14551458
};
14561459

14571460
/// Number of non-inherited bits in RecordDeclBitfields.
1458-
enum { NumRecordDeclBits = 14 };
1461+
enum { NumRecordDeclBits = 15 };
14591462

14601463
/// Stores the bits used by OMPDeclareReductionDecl.
14611464
/// If modified NumOMPDeclareReductionDeclBits and the accessor

clang/include/clang/AST/ODRHash.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class ODRHash {
5555
// more information than the AddDecl class.
5656
void AddCXXRecordDecl(const CXXRecordDecl *Record);
5757

58+
// Use this for ODR checking records in C/Objective-C between modules. This
59+
// method compares more information than the AddDecl class.
60+
void AddRecordDecl(const RecordDecl *Record);
61+
5862
// Use this for ODR checking functions between modules. This method compares
5963
// more information than the AddDecl class. SkipBody will process the
6064
// hash as if the function has no body.

clang/include/clang/Serialization/ASTReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,10 @@ class ASTReader
11001100
llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2>
11011101
PendingEnumOdrMergeFailures;
11021102

1103+
/// C/ObjC definitions in which the structural equivalence check fails
1104+
llvm::SmallDenseMap<RecordDecl *, llvm::SmallVector<RecordDecl *, 2>, 2>
1105+
PendingRecordOdrMergeFailures;
1106+
11031107
/// DeclContexts in which we have diagnosed an ODR violation.
11041108
llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
11051109

clang/lib/AST/Decl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4360,6 +4360,8 @@ RecordDecl::RecordDecl(Kind DK, TagKind TK, const ASTContext &C,
43604360
setHasNonTrivialToPrimitiveCopyCUnion(false);
43614361
setParamDestroyedInCallee(false);
43624362
setArgPassingRestrictions(APK_CanPassInRegs);
4363+
setHasODRHash(false);
4364+
ODRHash = 0;
43634365
}
43644366

43654367
RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC,
@@ -4507,6 +4509,19 @@ const FieldDecl *RecordDecl::findFirstNamedDataMember() const {
45074509
return nullptr;
45084510
}
45094511

4512+
unsigned RecordDecl::getODRHash() {
4513+
if (hasODRHash())
4514+
return ODRHash;
4515+
4516+
// Only calculate hash on first call of getODRHash per record.
4517+
class ODRHash Hash;
4518+
Hash.AddRecordDecl(this);
4519+
setHasODRHash();
4520+
ODRHash = Hash.CalculateHash();
4521+
4522+
return ODRHash;
4523+
}
4524+
45104525
//===----------------------------------------------------------------------===//
45114526
// BlockDecl Implementation
45124527
//===----------------------------------------------------------------------===//

clang/lib/AST/DeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ unsigned CXXRecordDecl::getODRHash() const {
484484
return DefinitionData->ODRHash;
485485

486486
// Only calculate hash on first call of getODRHash per record.
487-
ODRHash Hash;
487+
class ODRHash Hash;
488488
Hash.AddCXXRecordDecl(getDefinition());
489489
DefinitionData->HasODRHash = true;
490490
DefinitionData->ODRHash = Hash.CalculateHash();

clang/lib/AST/ODRHash.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,21 @@ void ODRHash::AddSubDecl(const Decl *D) {
464464
ODRDeclVisitor(ID, *this).Visit(D);
465465
}
466466

467+
void ODRHash::AddRecordDecl(const RecordDecl *Record) {
468+
AddDecl(Record);
469+
470+
// Filter out sub-Decls which will not be processed in order to get an
471+
// accurate count of Decl's.
472+
llvm::SmallVector<const Decl *, 16> Decls;
473+
for (Decl *SubDecl : Record->decls())
474+
if (isWhitelistedDecl(SubDecl, Record))
475+
Decls.push_back(SubDecl);
476+
477+
ID.AddInteger(Decls.size());
478+
for (auto SubDecl : Decls)
479+
AddSubDecl(SubDecl);
480+
}
481+
467482
void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
468483
assert(Record && Record->hasDefinition() &&
469484
"Expected non-null record to be a definition.");

0 commit comments

Comments
 (0)