Skip to content

Commit 4ee4536

Browse files
committed
Factor out logic from CXXRecordDecl to reuse for RecordDecl handling (NFC)
1 parent 832737b commit 4ee4536

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

clang/lib/Serialization/ASTReader.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9459,7 +9459,7 @@ void ASTReader::diagnoseOdrViolations() {
94599459
// Used with err_module_odr_violation_mismatch_decl and
94609460
// note_module_odr_violation_mismatch_decl
94619461
// This list should be the same Decl's as in ODRHash::isWhiteListedDecl
9462-
enum RecordDiffType {
9462+
enum ODRMismatchDecl {
94639463
EndOfClass,
94649464
PublicSpecifer,
94659465
PrivateSpecifer,
@@ -9477,7 +9477,7 @@ void ASTReader::diagnoseOdrViolations() {
94779477

94789478
// Used with err_module_odr_violation_mismatch_decl_diff and
94799479
// note_module_odr_violation_mismatch_decl_diff
9480-
enum ODRDeclDifference {
9480+
enum ODRMismatchDeclDifference {
94819481
StaticAssertCondition,
94829482
StaticAssertMessage,
94839483
StaticAssertOnlyMessage,
@@ -9530,13 +9530,13 @@ void ASTReader::diagnoseOdrViolations() {
95309530
// in with operator<<
95319531
auto ODRDiagDeclError = [this](NamedDecl *FirstRecord, StringRef FirstModule,
95329532
SourceLocation Loc, SourceRange Range,
9533-
ODRDeclDifference DiffType) {
9533+
ODRMismatchDeclDifference DiffType) {
95349534
return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff)
95359535
<< FirstRecord << FirstModule.empty() << FirstModule << Range
95369536
<< DiffType;
95379537
};
95389538
auto ODRDiagDeclNote = [this](StringRef SecondModule, SourceLocation Loc,
9539-
SourceRange Range, ODRDeclDifference DiffType) {
9539+
SourceRange Range, ODRMismatchDeclDifference DiffType) {
95409540
return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff)
95419541
<< SecondModule << Range << DiffType;
95429542
};
@@ -9803,7 +9803,7 @@ void ASTReader::diagnoseOdrViolations() {
98039803

98049804
struct DiffResult {
98059805
Decl *FirstDecl = nullptr, *SecondDecl = nullptr;
9806-
RecordDiffType FirstDiffType = Other, SecondDiffType = Other;
9806+
ODRMismatchDecl FirstDiffType = Other, SecondDiffType = Other;
98079807
};
98089808

98099809
// If there is a diagnoseable difference, FirstDiffType and
@@ -9835,6 +9835,9 @@ void ASTReader::diagnoseOdrViolations() {
98359835
return DR;
98369836
};
98379837

9838+
// Use this to diagnose that an unexpected Decl was encountered
9839+
// or no difference was detected. This causes a generic error
9840+
// message to be emitted.
98389841
auto DiagnoseODRUnexpected = [this](DiffResult &DR, NamedDecl *FirstRecord,
98399842
StringRef FirstModule,
98409843
NamedDecl *SecondRecord,
@@ -9859,12 +9862,13 @@ void ASTReader::diagnoseOdrViolations() {
98599862
};
98609863

98619864
auto DiagnoseODRMismatch =
9862-
[this](DiffResult &DR, TagDecl *FirstRecord, StringRef FirstModule,
9863-
TagDecl *SecondRecord, StringRef SecondModule) {
9865+
[this](DiffResult &DR, NamedDecl *FirstRecord, StringRef FirstModule,
9866+
NamedDecl *SecondRecord, StringRef SecondModule) {
98649867
SourceLocation FirstLoc;
98659868
SourceRange FirstRange;
9866-
if (DR.FirstDiffType == EndOfClass) {
9867-
FirstLoc = FirstRecord->getBraceRange().getEnd();
9869+
auto *FirstTag = dyn_cast<TagDecl>(FirstRecord);
9870+
if (DR.FirstDiffType == EndOfClass && FirstTag) {
9871+
FirstLoc = FirstTag->getBraceRange().getEnd();
98689872
} else {
98699873
FirstLoc = DR.FirstDecl->getLocation();
98709874
FirstRange = DR.FirstDecl->getSourceRange();
@@ -9875,8 +9879,9 @@ void ASTReader::diagnoseOdrViolations() {
98759879

98769880
SourceLocation SecondLoc;
98779881
SourceRange SecondRange;
9878-
if (DR.SecondDiffType == EndOfClass) {
9879-
SecondLoc = SecondRecord->getBraceRange().getEnd();
9882+
auto *SecondTag = dyn_cast<TagDecl>(SecondRecord);
9883+
if (DR.SecondDiffType == EndOfClass && SecondTag) {
9884+
SecondLoc = SecondTag->getBraceRange().getEnd();
98809885
} else {
98819886
SecondLoc = DR.SecondDecl->getLocation();
98829887
SecondRange = DR.SecondDecl->getSourceRange();
@@ -10219,14 +10224,11 @@ void ASTReader::diagnoseOdrViolations() {
1021910224
PopulateHashes(SecondHashes, SecondRecord, DC);
1022010225

1022110226
auto DR = FindTypeDiffs(FirstHashes, SecondHashes);
10222-
RecordDiffType FirstDiffType = DR.FirstDiffType;
10223-
RecordDiffType SecondDiffType = DR.SecondDiffType;
10227+
ODRMismatchDecl FirstDiffType = DR.FirstDiffType;
10228+
ODRMismatchDecl SecondDiffType = DR.SecondDiffType;
1022410229
Decl *FirstDecl = DR.FirstDecl;
1022510230
Decl *SecondDecl = DR.SecondDecl;
1022610231

10227-
// Reaching this point means an unexpected Decl was encountered
10228-
// or no difference was detected. This causes a generic error
10229-
// message to be emitted.
1023010232
if (FirstDiffType == Other || SecondDiffType == Other) {
1023110233
DiagnoseODRUnexpected(DR, FirstRecord, FirstModule, SecondRecord,
1023210234
SecondModule);
@@ -11128,14 +11130,11 @@ void ASTReader::diagnoseOdrViolations() {
1112811130
PopulateHashes(SecondHashes, SecondRecord, DC);
1112911131

1113011132
auto DR = FindTypeDiffs(FirstHashes, SecondHashes);
11131-
RecordDiffType FirstDiffType = DR.FirstDiffType;
11132-
RecordDiffType SecondDiffType = DR.SecondDiffType;
11133+
ODRMismatchDecl FirstDiffType = DR.FirstDiffType;
11134+
ODRMismatchDecl SecondDiffType = DR.SecondDiffType;
1113311135
Decl *FirstDecl = DR.FirstDecl;
1113411136
Decl *SecondDecl = DR.SecondDecl;
1113511137

11136-
// Reaching this point means an unexpected Decl was encountered
11137-
// or no difference was detected. This causes a generic error
11138-
// message to be emitted.
1113911138
if (FirstDiffType == Other || SecondDiffType == Other) {
1114011139
DiagnoseODRUnexpected(DR, FirstRecord, FirstModule, SecondRecord,
1114111140
SecondModule);

0 commit comments

Comments
 (0)