Skip to content
This repository was archived by the owner on Mar 30, 2021. It is now read-only.

Commit 0c38f81

Browse files
authored
Make ODR error handling configurable
ODR errors are not necessarily true errors during the import of ASTs. ASTMerge and CrossTU should use the warning equivalent of every CTU error, while Sema should emit errors as before.
1 parent bf73078 commit 0c38f81

File tree

10 files changed

+209
-55
lines changed

10 files changed

+209
-55
lines changed

include/clang/AST/ASTStructuralEquivalence.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,20 @@ struct StructuralEquivalenceContext {
6464
/// Whether to complain about failures.
6565
bool Complain;
6666

67+
/// Whether warn or error on tag type mismatches.
68+
bool ErrorOnTagTypeMismatch;
69+
6770
/// \c true if the last diagnostic came from ToCtx.
6871
bool LastDiagFromC2 = false;
6972

7073
StructuralEquivalenceContext(ASTContext &FromCtx, ASTContext &ToCtx,
7174
StructuralEquivalenceKind EqKind,
7275
bool StrictTypeSpelling = false,
73-
bool Complain = true)
76+
bool Complain = true,
77+
bool ErrorOnTagTypeMismatch = false)
7478
: FromCtx(FromCtx), ToCtx(ToCtx), EqKind(EqKind),
75-
StrictTypeSpelling(StrictTypeSpelling), Complain(Complain) {}
79+
StrictTypeSpelling(StrictTypeSpelling), Complain(Complain),
80+
ErrorOnTagTypeMismatch(ErrorOnTagTypeMismatch) {}
7681

7782
DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID);
7883
DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID);
@@ -105,6 +110,10 @@ struct StructuralEquivalenceContext {
105110
static llvm::Optional<unsigned>
106111
findUntaggedStructOrUnionIndex(RecordDecl *Anon);
107112

113+
// If ErrorOnTagTypeMismatch is set, return the the error, otherwise get the
114+
// relevant warning for the input error diagnostic.
115+
unsigned getApplicableDiagnostic(unsigned ErrorDiagnostic);
116+
108117
private:
109118
/// Finish checking all of the structural equivalences.
110119
///

include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,34 @@ let CategoryName = "VTable ABI Issue" in {
199199
}
200200

201201
// Importing ASTs
202+
def err_odr_variable_type_inconsistent : Error<
203+
"external variable %0 declared with incompatible types in different "
204+
"translation units (%1 vs. %2)">;
202205
def warn_odr_variable_type_inconsistent : Warning<
203206
"external variable %0 declared with incompatible types in different "
204-
"translation units (%1 vs. %2)">, InGroup<OneDefinitionRule>;
207+
"translation units (%1 vs. %2)">,
208+
InGroup<ODR>;
209+
def err_odr_variable_multiple_def : Error<
210+
"external variable %0 defined in multiple translation units">;
205211
def warn_odr_variable_multiple_def : Warning<
206212
"external variable %0 defined in multiple translation units">,
207-
InGroup<OneDefinitionRule>;
213+
InGroup<ODR>;
208214
def note_odr_value_here : Note<"declared here with type %0">;
209215
def note_odr_defined_here : Note<"also defined here">;
216+
def err_odr_function_type_inconsistent : Error<
217+
"external function %0 declared with incompatible types in different "
218+
"translation units (%1 vs. %2)">;
210219
def warn_odr_function_type_inconsistent : Warning<
211220
"external function %0 declared with incompatible types in different "
212-
"translation units (%1 vs. %2)">, InGroup<OneDefinitionRule>;
221+
"translation units (%1 vs. %2)">,
222+
InGroup<ODR>;
223+
def err_odr_tag_type_inconsistent
224+
: Error<"type %0 has incompatible definitions in different translation "
225+
"units">;
213226
def warn_odr_tag_type_inconsistent
214227
: Warning<"type %0 has incompatible definitions in different translation "
215-
"units">, InGroup<OneDefinitionRule>;
228+
"units">,
229+
InGroup<ODR>;
216230
def note_odr_tag_kind_here: Note<
217231
"%0 is a %select{struct|interface|union|class|enum}1 here">;
218232
def note_odr_field : Note<"field %0 has type %1 here">;
@@ -228,69 +242,116 @@ def note_odr_number_of_bases : Note<
228242
"class has %0 base %plural{1:class|:classes}0">;
229243
def note_odr_enumerator : Note<"enumerator %0 with value %1 here">;
230244
def note_odr_missing_enumerator : Note<"no corresponding enumerator here">;
231-
245+
def err_odr_field_type_inconsistent : Error<
246+
"field %0 declared with incompatible types in different "
247+
"translation units (%1 vs. %2)">;
232248
def warn_odr_field_type_inconsistent : Warning<
233249
"field %0 declared with incompatible types in different "
234-
"translation units (%1 vs. %2)">, InGroup<OneDefinitionRule>;
250+
"translation units (%1 vs. %2)">,
251+
InGroup<ODR>;
235252

236253
// Importing Objective-C ASTs
254+
def err_odr_ivar_type_inconsistent : Error<
255+
"instance variable %0 declared with incompatible types in different "
256+
"translation units (%1 vs. %2)">;
237257
def warn_odr_ivar_type_inconsistent : Warning<
238258
"instance variable %0 declared with incompatible types in different "
239-
"translation units (%1 vs. %2)">, InGroup<OneDefinitionRule>;
259+
"translation units (%1 vs. %2)">,
260+
InGroup<ODR>;
261+
def err_odr_objc_superclass_inconsistent : Error<
262+
"class %0 has incompatible superclasses">;
240263
def warn_odr_objc_superclass_inconsistent : Warning<
241-
"class %0 has incompatible superclasses">, InGroup<OneDefinitionRule>;
264+
"class %0 has incompatible superclasses">,
265+
InGroup<ODR>;
242266
def note_odr_objc_superclass : Note<"inherits from superclass %0 here">;
243267
def note_odr_objc_missing_superclass : Note<"no corresponding superclass here">;
268+
def err_odr_objc_method_result_type_inconsistent : Error<
269+
"%select{class|instance}0 method %1 has incompatible result types in "
270+
"different translation units (%2 vs. %3)">;
244271
def warn_odr_objc_method_result_type_inconsistent : Warning<
245272
"%select{class|instance}0 method %1 has incompatible result types in "
246-
"different translation units (%2 vs. %3)">, InGroup<OneDefinitionRule>;
273+
"different translation units (%2 vs. %3)">,
274+
InGroup<ODR>;
275+
def err_odr_objc_method_num_params_inconsistent : Error<
276+
"%select{class|instance}0 method %1 has a different number of parameters in "
277+
"different translation units (%2 vs. %3)">;
247278
def warn_odr_objc_method_num_params_inconsistent : Warning<
248279
"%select{class|instance}0 method %1 has a different number of parameters in "
249-
"different translation units (%2 vs. %3)">, InGroup<OneDefinitionRule>;
280+
"different translation units (%2 vs. %3)">,
281+
InGroup<ODR>;
282+
def err_odr_objc_method_param_type_inconsistent : Error<
283+
"%select{class|instance}0 method %1 has a parameter with a different types "
284+
"in different translation units (%2 vs. %3)">;
250285
def warn_odr_objc_method_param_type_inconsistent : Warning<
251286
"%select{class|instance}0 method %1 has a parameter with a different types "
252-
"in different translation units (%2 vs. %3)">, InGroup<OneDefinitionRule>;
287+
"in different translation units (%2 vs. %3)">,
288+
InGroup<ODR>;
289+
def err_odr_objc_method_variadic_inconsistent : Error<
290+
"%select{class|instance}0 method %1 is variadic in one translation unit "
291+
"and not variadic in another">;
253292
def warn_odr_objc_method_variadic_inconsistent : Warning<
254293
"%select{class|instance}0 method %1 is variadic in one translation unit "
255-
"and not variadic in another">, InGroup<OneDefinitionRule>;
294+
"and not variadic in another">,
295+
InGroup<ODR>;
256296
def note_odr_objc_method_here : Note<
257297
"%select{class|instance}0 method %1 also declared here">;
298+
def err_odr_objc_property_type_inconsistent : Error<
299+
"property %0 declared with incompatible types in different "
300+
"translation units (%1 vs. %2)">;
258301
def warn_odr_objc_property_type_inconsistent : Warning<
259302
"property %0 declared with incompatible types in different "
260-
"translation units (%1 vs. %2)">, InGroup<OneDefinitionRule>;
303+
"translation units (%1 vs. %2)">,
304+
InGroup<ODR>;
305+
def err_odr_objc_property_impl_kind_inconsistent : Error<
306+
"property %0 is implemented with %select{@synthesize|@dynamic}1 in one "
307+
"translation but %select{@dynamic|@synthesize}1 in another translation unit">;
261308
def warn_odr_objc_property_impl_kind_inconsistent : Warning<
262309
"property %0 is implemented with %select{@synthesize|@dynamic}1 in one "
263310
"translation but %select{@dynamic|@synthesize}1 in another translation unit">,
264-
InGroup<OneDefinitionRule>;
311+
InGroup<ODR>;
265312
def note_odr_objc_property_impl_kind : Note<
266313
"property %0 is implemented with %select{@synthesize|@dynamic}1 here">;
314+
def err_odr_objc_synthesize_ivar_inconsistent : Error<
315+
"property %0 is synthesized to different ivars in different translation "
316+
"units (%1 vs. %2)">;
267317
def warn_odr_objc_synthesize_ivar_inconsistent : Warning<
268318
"property %0 is synthesized to different ivars in different translation "
269-
"units (%1 vs. %2)">, InGroup<OneDefinitionRule>;
319+
"units (%1 vs. %2)">,
320+
InGroup<ODR>;
270321
def note_odr_objc_synthesize_ivar_here : Note<
271322
"property is synthesized to ivar %0 here">;
272323

273324
// Importing C++ ASTs
274325
def note_odr_friend : Note<"friend declared here">;
275326
def note_odr_missing_friend : Note<"no corresponding friend here">;
327+
def err_odr_different_num_template_parameters : Error<
328+
"template parameter lists have a different number of parameters (%0 vs %1)">;
276329
def warn_odr_different_num_template_parameters : Warning<
277330
"template parameter lists have a different number of parameters (%0 vs %1)">,
278-
InGroup<OneDefinitionRule>;
331+
InGroup<ODR>;
279332
def note_odr_template_parameter_list : Note<
280333
"template parameter list also declared here">;
334+
def err_odr_different_template_parameter_kind : Error<
335+
"template parameter has different kinds in different translation units">;
281336
def warn_odr_different_template_parameter_kind : Warning<
282337
"template parameter has different kinds in different translation units">,
283-
InGroup<OneDefinitionRule>;
338+
InGroup<ODR>;
284339
def note_odr_template_parameter_here : Note<
285340
"template parameter declared here">;
341+
def err_odr_parameter_pack_non_pack : Error<
342+
"parameter kind mismatch; parameter is %select{not a|a}0 parameter pack">;
286343
def warn_odr_parameter_pack_non_pack : Warning<
287344
"parameter kind mismatch; parameter is %select{not a|a}0 parameter pack">,
288-
InGroup<OneDefinitionRule>;
345+
InGroup<ODR>;
289346
def note_odr_parameter_pack_non_pack : Note<
290347
"%select{parameter|parameter pack}0 declared here">;
348+
def err_odr_non_type_parameter_type_inconsistent : Error<
349+
"non-type template parameter declared with incompatible types in different "
350+
"translation units (%0 vs. %1)">;
291351
def warn_odr_non_type_parameter_type_inconsistent : Warning<
292352
"non-type template parameter declared with incompatible types in different "
293-
"translation units (%0 vs. %1)">, InGroup<OneDefinitionRule>;
353+
"translation units (%0 vs. %1)">,
354+
InGroup<ODR>;
294355
def err_unsupported_ast_node: Error<"cannot import unsupported AST node %0">;
295356
def warn_ast_importer_missing_decl_in_decl_context : Warning<
296357
"missing %0Decl in imported DeclContext <%1:%2:%3>">;

include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def Implicit : DiagGroup<"implicit", [
1717
]>;
1818

1919
// Empty DiagGroups are recognized by clang but ignored.
20+
def ODR : DiagGroup<"odr">;
2021
def : DiagGroup<"abi">;
2122
def AbsoluteValue : DiagGroup<"absolute-value">;
2223
def AddressOfTemporary : DiagGroup<"address-of-temporary">;
@@ -391,7 +392,6 @@ def ObjCPointerIntrospectPerformSelector : DiagGroup<"deprecated-objc-pointer-in
391392
def ObjCPointerIntrospect : DiagGroup<"deprecated-objc-pointer-introspection", [ObjCPointerIntrospectPerformSelector]>;
392393
def ObjCMultipleMethodNames : DiagGroup<"objc-multiple-method-names">;
393394
def ObjCFlexibleArray : DiagGroup<"objc-flexible-array">;
394-
def OneDefinitionRule : DiagGroup<"odr">;
395395
def OpenCLUnsupportedRGBA: DiagGroup<"opencl-unsupported-rgba">;
396396
def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
397397
def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;

0 commit comments

Comments
 (0)