Skip to content

Commit bb0c8ec

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 (cherry picked from commit 15cb180)
1 parent 5339ef1 commit bb0c8ec

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
@@ -9589,19 +9589,12 @@ void ASTReader::diagnoseOdrViolations() {
95899589
Other
95909590
};
95919591

9592-
// Used with err_module_odr_violation_mismatch_decl_diff and
9593-
// note_module_odr_violation_mismatch_decl_diff
9594-
enum ODRMismatchDeclDifference {
9592+
// Used with err_module_odr_violation_record and
9593+
// note_module_odr_violation_record
9594+
enum ODRCXXRecordDifference {
95959595
StaticAssertCondition,
95969596
StaticAssertMessage,
95979597
StaticAssertOnlyMessage,
9598-
FieldName,
9599-
FieldTypeName,
9600-
FieldSingleBitField,
9601-
FieldDifferentWidthBitField,
9602-
FieldSingleMutable,
9603-
FieldSingleInitializer,
9604-
FieldDifferentInitializers,
96059598
MethodName,
96069599
MethodDeleted,
96079600
MethodDefaulted,
@@ -9620,13 +9613,6 @@ void ASTReader::diagnoseOdrViolations() {
96209613
MethodDifferentTemplateArgument,
96219614
MethodSingleBody,
96229615
MethodDifferentBody,
9623-
TypedefName,
9624-
TypedefType,
9625-
VarName,
9626-
VarType,
9627-
VarSingleInitializer,
9628-
VarDifferentInitializer,
9629-
VarConstexpr,
96309616
FriendTypeFunction,
96319617
FriendType,
96329618
FriendFunction,
@@ -9646,17 +9632,27 @@ void ASTReader::diagnoseOdrViolations() {
96469632
NamedDecl *FirstRecord, StringRef FirstModule,
96479633
StringRef SecondModule, FieldDecl *FirstField,
96489634
FieldDecl *SecondField) {
9635+
enum ODRFieldDifference {
9636+
FieldName,
9637+
FieldTypeName,
9638+
FieldSingleBitField,
9639+
FieldDifferentWidthBitField,
9640+
FieldSingleMutable,
9641+
FieldSingleInitializer,
9642+
FieldDifferentInitializers,
9643+
};
9644+
96499645
auto DiagError = [FirstRecord, FirstField, FirstModule,
9650-
this](ODRMismatchDeclDifference DiffType) {
9646+
this](ODRFieldDifference DiffType) {
96519647
return Diag(FirstField->getLocation(),
9652-
diag::err_module_odr_violation_mismatch_decl_diff)
9648+
diag::err_module_odr_violation_field)
96539649
<< FirstRecord << FirstModule.empty() << FirstModule
96549650
<< FirstField->getSourceRange() << DiffType;
96559651
};
96569652
auto DiagNote = [SecondField, SecondModule,
9657-
this](ODRMismatchDeclDifference DiffType) {
9653+
this](ODRFieldDifference DiffType) {
96589654
return Diag(SecondField->getLocation(),
9659-
diag::note_module_odr_violation_mismatch_decl_diff)
9655+
diag::note_module_odr_violation_field)
96609656
<< SecondModule << SecondField->getSourceRange() << DiffType;
96619657
};
96629658

@@ -9744,17 +9740,22 @@ void ASTReader::diagnoseOdrViolations() {
97449740
NamedDecl *FirstRecord, StringRef FirstModule, StringRef SecondModule,
97459741
TypedefNameDecl *FirstTD, TypedefNameDecl *SecondTD,
97469742
bool IsTypeAlias) {
9743+
enum ODRTypedefDifference {
9744+
TypedefName,
9745+
TypedefType,
9746+
};
9747+
97479748
auto DiagError = [FirstRecord, FirstTD, FirstModule,
9748-
this](ODRMismatchDeclDifference DiffType) {
9749+
this](ODRTypedefDifference DiffType) {
97499750
return Diag(FirstTD->getLocation(),
9750-
diag::err_module_odr_violation_mismatch_decl_diff)
9751+
diag::err_module_odr_violation_typedef)
97519752
<< FirstRecord << FirstModule.empty() << FirstModule
97529753
<< FirstTD->getSourceRange() << DiffType;
97539754
};
97549755
auto DiagNote = [SecondTD, SecondModule,
9755-
this](ODRMismatchDeclDifference DiffType) {
9756+
this](ODRTypedefDifference DiffType) {
97569757
return Diag(SecondTD->getLocation(),
9757-
diag::note_module_odr_violation_mismatch_decl_diff)
9758+
diag::note_module_odr_violation_typedef)
97589759
<< SecondModule << SecondTD->getSourceRange() << DiffType;
97599760
};
97609761

@@ -9782,17 +9783,24 @@ void ASTReader::diagnoseOdrViolations() {
97829783
this](NamedDecl *FirstRecord, StringRef FirstModule,
97839784
StringRef SecondModule, VarDecl *FirstVD,
97849785
VarDecl *SecondVD) {
9786+
enum ODRVarDifference {
9787+
VarName,
9788+
VarType,
9789+
VarSingleInitializer,
9790+
VarDifferentInitializer,
9791+
VarConstexpr,
9792+
};
9793+
97859794
auto DiagError = [FirstRecord, FirstVD, FirstModule,
9786-
this](ODRMismatchDeclDifference DiffType) {
9795+
this](ODRVarDifference DiffType) {
97879796
return Diag(FirstVD->getLocation(),
9788-
diag::err_module_odr_violation_mismatch_decl_diff)
9797+
diag::err_module_odr_violation_variable)
97899798
<< FirstRecord << FirstModule.empty() << FirstModule
97909799
<< FirstVD->getSourceRange() << DiffType;
97919800
};
9792-
auto DiagNote = [SecondVD, SecondModule,
9793-
this](ODRMismatchDeclDifference DiffType) {
9801+
auto DiagNote = [SecondVD, SecondModule, this](ODRVarDifference DiffType) {
97949802
return Diag(SecondVD->getLocation(),
9795-
diag::note_module_odr_violation_mismatch_decl_diff)
9803+
diag::note_module_odr_violation_variable)
97969804
<< SecondModule << SecondVD->getSourceRange() << DiffType;
97979805
};
97989806

@@ -10005,15 +10013,15 @@ void ASTReader::diagnoseOdrViolations() {
1000510013
std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord);
1000610014
auto ODRDiagDeclError = [FirstRecord, &FirstModule,
1000710015
this](SourceLocation Loc, SourceRange Range,
10008-
ODRMismatchDeclDifference DiffType) {
10009-
return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff)
10016+
ODRCXXRecordDifference DiffType) {
10017+
return Diag(Loc, diag::err_module_odr_violation_record)
1001010018
<< FirstRecord << FirstModule.empty() << FirstModule << Range
1001110019
<< DiffType;
1001210020
};
1001310021
auto ODRDiagDeclNote = [&SecondModule,
1001410022
this](SourceLocation Loc, SourceRange Range,
10015-
ODRMismatchDeclDifference DiffType) {
10016-
return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff)
10023+
ODRCXXRecordDifference DiffType) {
10024+
return Diag(Loc, diag::note_module_odr_violation_record)
1001710025
<< SecondModule << Range << DiffType;
1001810026
};
1001910027

@@ -10340,13 +10348,13 @@ void ASTReader::diagnoseOdrViolations() {
1034010348
DeclarationName FirstName = FirstMethod->getDeclName();
1034110349
DeclarationName SecondName = SecondMethod->getDeclName();
1034210350
auto DiagMethodError = [&ODRDiagDeclError, FirstMethod, FirstMethodType,
10343-
FirstName](ODRMismatchDeclDifference DiffType) {
10351+
FirstName](ODRCXXRecordDifference DiffType) {
1034410352
return ODRDiagDeclError(FirstMethod->getLocation(),
1034510353
FirstMethod->getSourceRange(), DiffType)
1034610354
<< FirstMethodType << FirstName;
1034710355
};
1034810356
auto DiagMethodNote = [&ODRDiagDeclNote, SecondMethod, SecondMethodType,
10349-
SecondName](ODRMismatchDeclDifference DiffType) {
10357+
SecondName](ODRCXXRecordDifference DiffType) {
1035010358
return ODRDiagDeclNote(SecondMethod->getLocation(),
1035110359
SecondMethod->getSourceRange(), DiffType)
1035210360
<< SecondMethodType << SecondName;
@@ -10681,13 +10689,13 @@ void ASTReader::diagnoseOdrViolations() {
1068110689
SecondTemplate->getTemplateParameters();
1068210690

1068310691
auto DiagTemplateError = [&ODRDiagDeclError, FirstTemplate](
10684-
ODRMismatchDeclDifference DiffType) {
10692+
ODRCXXRecordDifference DiffType) {
1068510693
return ODRDiagDeclError(FirstTemplate->getLocation(),
1068610694
FirstTemplate->getSourceRange(), DiffType)
1068710695
<< FirstTemplate;
1068810696
};
1068910697
auto DiagTemplateNote = [&ODRDiagDeclNote, SecondTemplate](
10690-
ODRMismatchDeclDifference DiffType) {
10698+
ODRCXXRecordDifference DiffType) {
1069110699
return ODRDiagDeclNote(SecondTemplate->getLocation(),
1069210700
SecondTemplate->getSourceRange(), DiffType)
1069310701
<< SecondTemplate;

0 commit comments

Comments
 (0)