Skip to content

Commit 15cb180

Browse files
committed
[ODRHash diagnostics] Split err_module_odr_violation_mismatch_decl_diff into per-entity diagnostics. NFC.
We'll need to add more cases for Objective-C entities and adding everything to `err_module_odr_violation_mismatch_decl_diff` makes it harder to work with over time. Differential Revision: https://reviews.llvm.org/D128488
1 parent 4639486 commit 15cb180

File tree

2 files changed

+103
-68
lines changed

2 files changed

+103
-68
lines changed

clang/include/clang/Basic/DiagnosticSerializationKinds.td

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,13 @@ def note_module_odr_violation_mismatch_decl : Note<"but in '%0' found "
177177
"protected access specifier|static assert|field|method|type alias|typedef|"
178178
"data member|friend declaration|function template}1">;
179179

180-
def err_module_odr_violation_mismatch_decl_diff : Error<
180+
def err_module_odr_violation_record : Error<
181181
"%q0 has different definitions in different modules; first difference is "
182182
"%select{definition in module '%2'|defined here}1 found "
183183
"%select{"
184184
"static assert with condition|"
185185
"static assert with message|"
186186
"static assert with %select{|no }4message|"
187-
"field %4|"
188-
"field %4 with type %5|"
189-
"%select{non-|}5bitfield %4|"
190-
"bitfield %4 with one width expression|"
191-
"%select{non-|}5mutable field %4|"
192-
"field %4 with %select{no|an}5 initalizer|"
193-
"field %4 with an initializer|"
194187
"%select{method %5|constructor|destructor}4|"
195188
"%select{method %5|constructor|destructor}4 "
196189
"is %select{not deleted|deleted}6|"
@@ -226,13 +219,6 @@ def err_module_odr_violation_mismatch_decl_diff : Error<
226219
"with %select{no body|body}6|"
227220
"%select{method %5|constructor|destructor}4 "
228221
"with body|"
229-
"%select{typedef|type alias}4 name %5|"
230-
"%select{typedef|type alias}4 %5 with underlying type %6|"
231-
"data member with name %4|"
232-
"data member %4 with type %5|"
233-
"data member %4 with%select{out|}5 an initializer|"
234-
"data member %4 with an initializer|"
235-
"data member %4 %select{is constexpr|is not constexpr}5|"
236222
"friend %select{class|function}4|"
237223
"friend %4|"
238224
"friend function %4|"
@@ -250,18 +236,11 @@ def err_module_odr_violation_mismatch_decl_diff : Error<
250236
"being a template parameter pack|"
251237
"}3">;
252238

253-
def note_module_odr_violation_mismatch_decl_diff : Note<"but in '%0' found "
239+
def note_module_odr_violation_record : Note<"but in '%0' found "
254240
"%select{"
255241
"static assert with different condition|"
256242
"static assert with different message|"
257243
"static assert with %select{|no }2message|"
258-
"field %2|"
259-
"field %2 with type %3|"
260-
"%select{non-|}3bitfield %2|"
261-
"bitfield %2 with different width expression|"
262-
"%select{non-|}3mutable field %2|"
263-
"field %2 with %select{no|an}3 initializer|"
264-
"field %2 with a different initializer|"
265244
"%select{method %3|constructor|destructor}2|"
266245
"%select{method %3|constructor|destructor}2 "
267246
"is %select{not deleted|deleted}4|"
@@ -297,13 +276,6 @@ def note_module_odr_violation_mismatch_decl_diff : Note<"but in '%0' found "
297276
"with %select{no body|body}4|"
298277
"%select{method %3|constructor|destructor}2 "
299278
"with different body|"
300-
"%select{typedef|type alias}2 name %3|"
301-
"%select{typedef|type alias}2 %3 with different underlying type %4|"
302-
"data member with name %2|"
303-
"data member %2 with different type %3|"
304-
"data member %2 with%select{out|}3 an initializer|"
305-
"data member %2 with a different initializer|"
306-
"data member %2 %select{is constexpr|is not constexpr}3|"
307279
"friend %select{class|function}2|"
308280
"friend %2|"
309281
"friend function %2|"
@@ -321,6 +293,61 @@ def note_module_odr_violation_mismatch_decl_diff : Note<"but in '%0' found "
321293
"being a template parameter pack|"
322294
"}1">;
323295

296+
def err_module_odr_violation_field : Error<
297+
"%q0 has different definitions in different modules; first difference is "
298+
"%select{definition in module '%2'|defined here}1 found "
299+
"%select{"
300+
"field %4|"
301+
"field %4 with type %5|"
302+
"%select{non-|}5bitfield %4|"
303+
"bitfield %4 with one width expression|"
304+
"%select{non-|}5mutable field %4|"
305+
"field %4 with %select{no|an}5 initalizer|"
306+
"field %4 with an initializer"
307+
"}3">;
308+
def note_module_odr_violation_field : Note<"but in '%0' found "
309+
"%select{"
310+
"field %2|"
311+
"field %2 with type %3|"
312+
"%select{non-|}3bitfield %2|"
313+
"bitfield %2 with different width expression|"
314+
"%select{non-|}3mutable field %2|"
315+
"field %2 with %select{no|an}3 initializer|"
316+
"field %2 with a different initializer"
317+
"}1">;
318+
319+
def err_module_odr_violation_typedef : Error<
320+
"%q0 has different definitions in different modules; first difference is "
321+
"%select{definition in module '%2'|defined here}1 found "
322+
"%select{"
323+
"%select{typedef|type alias}4 name %5|"
324+
"%select{typedef|type alias}4 %5 with underlying type %6"
325+
"}3">;
326+
def note_module_odr_violation_typedef : Note<"but in '%0' found "
327+
"%select{"
328+
"%select{typedef|type alias}2 name %3|"
329+
"%select{typedef|type alias}2 %3 with different underlying type %4"
330+
"}1">;
331+
332+
def err_module_odr_violation_variable : Error<
333+
"%q0 has different definitions in different modules; first difference is "
334+
"%select{definition in module '%2'|defined here}1 found "
335+
"%select{"
336+
"data member with name %4|"
337+
"data member %4 with type %5|"
338+
"data member %4 with%select{out|}5 an initializer|"
339+
"data member %4 with an initializer|"
340+
"data member %4 %select{is constexpr|is not constexpr}5"
341+
"}3">;
342+
def note_module_odr_violation_variable : Note<"but in '%0' found "
343+
"%select{"
344+
"data member with name %2|"
345+
"data member %2 with different type %3|"
346+
"data member %2 with%select{out|}3 an initializer|"
347+
"data member %2 with a different initializer|"
348+
"data member %2 %select{is constexpr|is not constexpr}3"
349+
"}1">;
350+
324351
def err_module_odr_violation_function : Error<
325352
"%q0 has different definitions in different modules; "
326353
"%select{definition in module '%2'|defined here}1 "

clang/lib/Serialization/ASTReader.cpp

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9637,19 +9637,12 @@ void ASTReader::diagnoseOdrViolations() {
96379637
Other
96389638
};
96399639

9640-
// Used with err_module_odr_violation_mismatch_decl_diff and
9641-
// note_module_odr_violation_mismatch_decl_diff
9642-
enum ODRMismatchDeclDifference {
9640+
// Used with err_module_odr_violation_record and
9641+
// note_module_odr_violation_record
9642+
enum ODRCXXRecordDifference {
96439643
StaticAssertCondition,
96449644
StaticAssertMessage,
96459645
StaticAssertOnlyMessage,
9646-
FieldName,
9647-
FieldTypeName,
9648-
FieldSingleBitField,
9649-
FieldDifferentWidthBitField,
9650-
FieldSingleMutable,
9651-
FieldSingleInitializer,
9652-
FieldDifferentInitializers,
96539646
MethodName,
96549647
MethodDeleted,
96559648
MethodDefaulted,
@@ -9668,13 +9661,6 @@ void ASTReader::diagnoseOdrViolations() {
96689661
MethodDifferentTemplateArgument,
96699662
MethodSingleBody,
96709663
MethodDifferentBody,
9671-
TypedefName,
9672-
TypedefType,
9673-
VarName,
9674-
VarType,
9675-
VarSingleInitializer,
9676-
VarDifferentInitializer,
9677-
VarConstexpr,
96789664
FriendTypeFunction,
96799665
FriendType,
96809666
FriendFunction,
@@ -9694,17 +9680,27 @@ void ASTReader::diagnoseOdrViolations() {
96949680
NamedDecl *FirstRecord, StringRef FirstModule,
96959681
StringRef SecondModule, FieldDecl *FirstField,
96969682
FieldDecl *SecondField) {
9683+
enum ODRFieldDifference {
9684+
FieldName,
9685+
FieldTypeName,
9686+
FieldSingleBitField,
9687+
FieldDifferentWidthBitField,
9688+
FieldSingleMutable,
9689+
FieldSingleInitializer,
9690+
FieldDifferentInitializers,
9691+
};
9692+
96979693
auto DiagError = [FirstRecord, FirstField, FirstModule,
9698-
this](ODRMismatchDeclDifference DiffType) {
9694+
this](ODRFieldDifference DiffType) {
96999695
return Diag(FirstField->getLocation(),
9700-
diag::err_module_odr_violation_mismatch_decl_diff)
9696+
diag::err_module_odr_violation_field)
97019697
<< FirstRecord << FirstModule.empty() << FirstModule
97029698
<< FirstField->getSourceRange() << DiffType;
97039699
};
97049700
auto DiagNote = [SecondField, SecondModule,
9705-
this](ODRMismatchDeclDifference DiffType) {
9701+
this](ODRFieldDifference DiffType) {
97069702
return Diag(SecondField->getLocation(),
9707-
diag::note_module_odr_violation_mismatch_decl_diff)
9703+
diag::note_module_odr_violation_field)
97089704
<< SecondModule << SecondField->getSourceRange() << DiffType;
97099705
};
97109706

@@ -9792,17 +9788,22 @@ void ASTReader::diagnoseOdrViolations() {
97929788
NamedDecl *FirstRecord, StringRef FirstModule, StringRef SecondModule,
97939789
TypedefNameDecl *FirstTD, TypedefNameDecl *SecondTD,
97949790
bool IsTypeAlias) {
9791+
enum ODRTypedefDifference {
9792+
TypedefName,
9793+
TypedefType,
9794+
};
9795+
97959796
auto DiagError = [FirstRecord, FirstTD, FirstModule,
9796-
this](ODRMismatchDeclDifference DiffType) {
9797+
this](ODRTypedefDifference DiffType) {
97979798
return Diag(FirstTD->getLocation(),
9798-
diag::err_module_odr_violation_mismatch_decl_diff)
9799+
diag::err_module_odr_violation_typedef)
97999800
<< FirstRecord << FirstModule.empty() << FirstModule
98009801
<< FirstTD->getSourceRange() << DiffType;
98019802
};
98029803
auto DiagNote = [SecondTD, SecondModule,
9803-
this](ODRMismatchDeclDifference DiffType) {
9804+
this](ODRTypedefDifference DiffType) {
98049805
return Diag(SecondTD->getLocation(),
9805-
diag::note_module_odr_violation_mismatch_decl_diff)
9806+
diag::note_module_odr_violation_typedef)
98069807
<< SecondModule << SecondTD->getSourceRange() << DiffType;
98079808
};
98089809

@@ -9830,17 +9831,24 @@ void ASTReader::diagnoseOdrViolations() {
98309831
this](NamedDecl *FirstRecord, StringRef FirstModule,
98319832
StringRef SecondModule, VarDecl *FirstVD,
98329833
VarDecl *SecondVD) {
9834+
enum ODRVarDifference {
9835+
VarName,
9836+
VarType,
9837+
VarSingleInitializer,
9838+
VarDifferentInitializer,
9839+
VarConstexpr,
9840+
};
9841+
98339842
auto DiagError = [FirstRecord, FirstVD, FirstModule,
9834-
this](ODRMismatchDeclDifference DiffType) {
9843+
this](ODRVarDifference DiffType) {
98359844
return Diag(FirstVD->getLocation(),
9836-
diag::err_module_odr_violation_mismatch_decl_diff)
9845+
diag::err_module_odr_violation_variable)
98379846
<< FirstRecord << FirstModule.empty() << FirstModule
98389847
<< FirstVD->getSourceRange() << DiffType;
98399848
};
9840-
auto DiagNote = [SecondVD, SecondModule,
9841-
this](ODRMismatchDeclDifference DiffType) {
9849+
auto DiagNote = [SecondVD, SecondModule, this](ODRVarDifference DiffType) {
98429850
return Diag(SecondVD->getLocation(),
9843-
diag::note_module_odr_violation_mismatch_decl_diff)
9851+
diag::note_module_odr_violation_variable)
98449852
<< SecondModule << SecondVD->getSourceRange() << DiffType;
98459853
};
98469854

@@ -10053,15 +10061,15 @@ void ASTReader::diagnoseOdrViolations() {
1005310061
std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord);
1005410062
auto ODRDiagDeclError = [FirstRecord, &FirstModule,
1005510063
this](SourceLocation Loc, SourceRange Range,
10056-
ODRMismatchDeclDifference DiffType) {
10057-
return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff)
10064+
ODRCXXRecordDifference DiffType) {
10065+
return Diag(Loc, diag::err_module_odr_violation_record)
1005810066
<< FirstRecord << FirstModule.empty() << FirstModule << Range
1005910067
<< DiffType;
1006010068
};
1006110069
auto ODRDiagDeclNote = [&SecondModule,
1006210070
this](SourceLocation Loc, SourceRange Range,
10063-
ODRMismatchDeclDifference DiffType) {
10064-
return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff)
10071+
ODRCXXRecordDifference DiffType) {
10072+
return Diag(Loc, diag::note_module_odr_violation_record)
1006510073
<< SecondModule << Range << DiffType;
1006610074
};
1006710075

@@ -10388,13 +10396,13 @@ void ASTReader::diagnoseOdrViolations() {
1038810396
DeclarationName FirstName = FirstMethod->getDeclName();
1038910397
DeclarationName SecondName = SecondMethod->getDeclName();
1039010398
auto DiagMethodError = [&ODRDiagDeclError, FirstMethod, FirstMethodType,
10391-
FirstName](ODRMismatchDeclDifference DiffType) {
10399+
FirstName](ODRCXXRecordDifference DiffType) {
1039210400
return ODRDiagDeclError(FirstMethod->getLocation(),
1039310401
FirstMethod->getSourceRange(), DiffType)
1039410402
<< FirstMethodType << FirstName;
1039510403
};
1039610404
auto DiagMethodNote = [&ODRDiagDeclNote, SecondMethod, SecondMethodType,
10397-
SecondName](ODRMismatchDeclDifference DiffType) {
10405+
SecondName](ODRCXXRecordDifference DiffType) {
1039810406
return ODRDiagDeclNote(SecondMethod->getLocation(),
1039910407
SecondMethod->getSourceRange(), DiffType)
1040010408
<< SecondMethodType << SecondName;
@@ -10729,13 +10737,13 @@ void ASTReader::diagnoseOdrViolations() {
1072910737
SecondTemplate->getTemplateParameters();
1073010738

1073110739
auto DiagTemplateError = [&ODRDiagDeclError, FirstTemplate](
10732-
ODRMismatchDeclDifference DiffType) {
10740+
ODRCXXRecordDifference DiffType) {
1073310741
return ODRDiagDeclError(FirstTemplate->getLocation(),
1073410742
FirstTemplate->getSourceRange(), DiffType)
1073510743
<< FirstTemplate;
1073610744
};
1073710745
auto DiagTemplateNote = [&ODRDiagDeclNote, SecondTemplate](
10738-
ODRMismatchDeclDifference DiffType) {
10746+
ODRCXXRecordDifference DiffType) {
1073910747
return ODRDiagDeclNote(SecondTemplate->getLocation(),
1074010748
SecondTemplate->getSourceRange(), DiffType)
1074110749
<< SecondTemplate;

0 commit comments

Comments
 (0)