Skip to content

Commit d0986a4

Browse files
authored
Merge pull request #5265 from apple/eng/compare-objcprotocols-cherry-pick-01
[ODRHash diagnostics] Cherry-picking a series of ODRHash commits.
2 parents 7b17e32 + bb0c8ec commit d0986a4

File tree

8 files changed

+424
-569
lines changed

8 files changed

+424
-569
lines changed

clang/include/clang/Basic/DiagnosticSerializationKinds.td

Lines changed: 62 additions & 33 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 "
@@ -355,7 +382,7 @@ def err_module_odr_violation_enum : Error<
355382
"enum with specified type %4|"
356383
"enum with %4 element%s4|"
357384
"%ordinal4 element has name %5|"
358-
"%ordinal4 element %5 %select{has|does not have}6 an initilizer|"
385+
"%ordinal4 element %5 %select{has|does not have}6 an initializer|"
359386
"%ordinal4 element %5 has an initializer|"
360387
"}3">;
361388

@@ -375,12 +402,14 @@ def err_module_odr_violation_mismatch_decl_unknown : Error<
375402
"%q0 %select{with definition in module '%2'|defined here}1 has different "
376403
"definitions in different modules; first difference is this "
377404
"%select{||||static assert|field|method|type alias|typedef|data member|"
378-
"friend declaration|unexpected decl}3">;
405+
"friend declaration|function template|"
406+
"unexpected decl}3">;
379407
def note_module_odr_violation_mismatch_decl_unknown : Note<
380408
"but in '%0' found "
381409
"%select{||||different static assert|different field|different method|"
382410
"different type alias|different typedef|different data member|"
383-
"different friend declaration|another unexpected decl}1">;
411+
"different friend declaration|different function template|"
412+
"another unexpected decl}1">;
384413

385414
def warn_duplicate_module_file_extension : Warning<
386415
"duplicate module file extension block name '%0'">,

clang/include/clang/Parse/Parser.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ class Parser : public CodeCompletionHandler {
447447
return Actions.incrementMSManglingNumber();
448448
}
449449

450-
Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); }
450+
ObjCContainerDecl *getObjCDeclContext() const {
451+
return Actions.getObjCDeclContext();
452+
}
451453

452454
// Type forwarding. All of these are statically 'void*', but they may all be
453455
// different actual classes based on the actions in place.
@@ -1001,18 +1003,18 @@ class Parser : public CodeCompletionHandler {
10011003
/// back.
10021004
class ObjCDeclContextSwitch {
10031005
Parser &P;
1004-
Decl *DC;
1006+
ObjCContainerDecl *DC;
10051007
SaveAndRestore<bool> WithinObjCContainer;
10061008
public:
10071009
explicit ObjCDeclContextSwitch(Parser &p)
10081010
: P(p), DC(p.getObjCDeclContext()),
10091011
WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) {
10101012
if (DC)
1011-
P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
1013+
P.Actions.ActOnObjCTemporaryExitContainerContext(DC);
10121014
}
10131015
~ObjCDeclContextSwitch() {
10141016
if (DC)
1015-
P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
1017+
P.Actions.ActOnObjCReenterContainerContext(DC);
10161018
}
10171019
};
10181020

@@ -1614,11 +1616,12 @@ class Parser : public CodeCompletionHandler {
16141616
SmallVectorImpl<IdentifierLocPair> &protocolIdents,
16151617
SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
16161618

1617-
void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc,
1619+
void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
1620+
SourceLocation atLoc,
16181621
BalancedDelimiterTracker &T,
16191622
SmallVectorImpl<Decl *> &AllIvarDecls,
16201623
bool RBraceMissing);
1621-
void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
1624+
void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
16221625
tok::ObjCKeywordKind visibility,
16231626
SourceLocation atLoc);
16241627
bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P,

clang/include/clang/Sema/Sema.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,7 +3298,7 @@ class Sema final {
32983298
/// Invoked when we enter a tag definition that we're skipping.
32993299
SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD);
33003300

3301-
Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
3301+
void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl);
33023302

33033303
/// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
33043304
/// C++ record definition's base-specifiers clause and are starting its
@@ -3322,8 +3322,8 @@ class Sema final {
33223322
/// scope for parsing/looking-up C constructs.
33233323
///
33243324
/// Must be followed by a call to \see ActOnObjCReenterContainerContext
3325-
void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
3326-
void ActOnObjCReenterContainerContext(DeclContext *DC);
3325+
void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx);
3326+
void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx);
33273327

33283328
/// ActOnTagDefinitionError - Invoked when there was an unrecoverable
33293329
/// error parsing the definition of a tag.
@@ -9766,7 +9766,7 @@ class Sema final {
97669766
SourceLocation rAngleLoc);
97679767
void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList);
97689768

9769-
Decl *ActOnStartClassInterface(
9769+
ObjCInterfaceDecl *ActOnStartClassInterface(
97709770
Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName,
97719771
SourceLocation ClassLoc, ObjCTypeParamList *typeParamList,
97729772
IdentifierInfo *SuperName, SourceLocation SuperLoc,
@@ -9800,33 +9800,29 @@ class Sema final {
98009800
SourceLocation &PLoc, SourceLocation PrevLoc,
98019801
const ObjCList<ObjCProtocolDecl> &PList);
98029802

9803-
Decl *ActOnStartProtocolInterface(
9803+
ObjCProtocolDecl *ActOnStartProtocolInterface(
98049804
SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName,
98059805
SourceLocation ProtocolLoc, Decl *const *ProtoRefNames,
98069806
unsigned NumProtoRefs, const SourceLocation *ProtoLocs,
98079807
SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList);
98089808

9809-
Decl *ActOnStartCategoryInterface(
9809+
ObjCCategoryDecl *ActOnStartCategoryInterface(
98109810
SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName,
98119811
SourceLocation ClassLoc, ObjCTypeParamList *typeParamList,
98129812
IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
98139813
Decl *const *ProtoRefs, unsigned NumProtoRefs,
98149814
const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc,
98159815
const ParsedAttributesView &AttrList);
98169816

9817-
Decl *ActOnStartClassImplementation(SourceLocation AtClassImplLoc,
9818-
IdentifierInfo *ClassName,
9819-
SourceLocation ClassLoc,
9820-
IdentifierInfo *SuperClassname,
9821-
SourceLocation SuperClassLoc,
9822-
const ParsedAttributesView &AttrList);
9817+
ObjCImplementationDecl *ActOnStartClassImplementation(
9818+
SourceLocation AtClassImplLoc, IdentifierInfo *ClassName,
9819+
SourceLocation ClassLoc, IdentifierInfo *SuperClassname,
9820+
SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList);
98239821

9824-
Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
9825-
IdentifierInfo *ClassName,
9826-
SourceLocation ClassLoc,
9827-
IdentifierInfo *CatName,
9828-
SourceLocation CatLoc,
9829-
const ParsedAttributesView &AttrList);
9822+
ObjCCategoryImplDecl *ActOnStartCategoryImplementation(
9823+
SourceLocation AtCatImplLoc, IdentifierInfo *ClassName,
9824+
SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc,
9825+
const ParsedAttributesView &AttrList);
98309826

98319827
DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl,
98329828
ArrayRef<Decl *> Decls);
@@ -13184,7 +13180,7 @@ class Sema final {
1318413180
IdentifierInfo *getSuperIdentifier() const;
1318513181
IdentifierInfo *getFloat128Identifier() const;
1318613182

13187-
Decl *getObjCDeclContext() const;
13183+
ObjCContainerDecl *getObjCDeclContext() const;
1318813184

1318913185
DeclContext *getCurLexicalContext() const {
1319013186
return OriginalLexicalContext ? OriginalLexicalContext : CurContext;

clang/lib/Parse/ParseObjc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
285285
/*consumeLastToken=*/true))
286286
return nullptr;
287287

288-
Decl *CategoryType = Actions.ActOnStartCategoryInterface(
288+
ObjCCategoryDecl *CategoryType = Actions.ActOnStartCategoryInterface(
289289
AtLoc, nameId, nameLoc, typeParameterList, categoryId, categoryLoc,
290290
ProtocolRefs.data(), ProtocolRefs.size(), ProtocolLocs.data(),
291291
EndProtoLoc, attrs);
@@ -355,7 +355,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
355355
Actions.ActOnTypedefedProtocols(protocols, protocolLocs,
356356
superClassId, superClassLoc);
357357

358-
Decl *ClsType = Actions.ActOnStartClassInterface(
358+
ObjCInterfaceDecl *ClsType = Actions.ActOnStartClassInterface(
359359
getCurScope(), AtLoc, nameId, nameLoc, typeParameterList, superClassId,
360360
superClassLoc, typeArgs,
361361
SourceRange(typeArgsLAngleLoc, typeArgsRAngleLoc), protocols.data(),
@@ -1866,10 +1866,10 @@ TypeResult Parser::parseObjCTypeArgsAndProtocolQualifiers(
18661866
protocolRAngleLoc);
18671867
}
18681868

1869-
void Parser::HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc,
1870-
BalancedDelimiterTracker &T,
1871-
SmallVectorImpl<Decl *> &AllIvarDecls,
1872-
bool RBraceMissing) {
1869+
void Parser::HelperActionsForIvarDeclarations(
1870+
ObjCContainerDecl *interfaceDecl, SourceLocation atLoc,
1871+
BalancedDelimiterTracker &T, SmallVectorImpl<Decl *> &AllIvarDecls,
1872+
bool RBraceMissing) {
18731873
if (!RBraceMissing)
18741874
T.consumeClose();
18751875

@@ -1904,7 +1904,7 @@ void Parser::HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocatio
19041904
/// objc-instance-variable-decl:
19051905
/// struct-declaration
19061906
///
1907-
void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl,
1907+
void Parser::ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
19081908
tok::ObjCKeywordKind visibility,
19091909
SourceLocation atLoc) {
19101910
assert(Tok.is(tok::l_brace) && "expected {");
@@ -2122,7 +2122,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
21222122
// We have a class or category name - consume it.
21232123
IdentifierInfo *nameId = Tok.getIdentifierInfo();
21242124
SourceLocation nameLoc = ConsumeToken(); // consume class or category name
2125-
Decl *ObjCImpDecl = nullptr;
2125+
ObjCImplDecl *ObjCImpDecl = nullptr;
21262126

21272127
// Neither a type parameter list nor a list of protocol references is
21282128
// permitted here. Parse and diagnose them.

clang/lib/Sema/SemaDecl.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17003,14 +17003,10 @@ bool Sema::ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody) {
1700317003
return true;
1700417004
}
1700517005

17006-
Decl *Sema::ActOnObjCContainerStartDefinition(Decl *IDecl) {
17007-
assert(isa<ObjCContainerDecl>(IDecl) &&
17008-
"ActOnObjCContainerStartDefinition - Not ObjCContainerDecl");
17009-
DeclContext *OCD = cast<DeclContext>(IDecl);
17010-
assert(OCD->getLexicalParent() == CurContext &&
17006+
void Sema::ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl) {
17007+
assert(IDecl->getLexicalParent() == CurContext &&
1701117008
"The next DeclContext should be lexically contained in the current one.");
17012-
CurContext = OCD;
17013-
return IDecl;
17009+
CurContext = IDecl;
1701417010
}
1701517011

1701617012
void Sema::ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagD,
@@ -17118,14 +17114,14 @@ void Sema::ActOnObjCContainerFinishDefinition() {
1711817114
PopDeclContext();
1711917115
}
1712017116

17121-
void Sema::ActOnObjCTemporaryExitContainerContext(DeclContext *DC) {
17122-
assert(DC == CurContext && "Mismatch of container contexts");
17123-
OriginalLexicalContext = DC;
17117+
void Sema::ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx) {
17118+
assert(ObjCCtx == CurContext && "Mismatch of container contexts");
17119+
OriginalLexicalContext = ObjCCtx;
1712417120
ActOnObjCContainerFinishDefinition();
1712517121
}
1712617122

17127-
void Sema::ActOnObjCReenterContainerContext(DeclContext *DC) {
17128-
ActOnObjCContainerStartDefinition(cast<Decl>(DC));
17123+
void Sema::ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx) {
17124+
ActOnObjCContainerStartDefinition(ObjCCtx);
1712917125
OriginalLexicalContext = nullptr;
1713017126
}
1713117127

@@ -19044,7 +19040,7 @@ void Sema::ActOnPragmaWeakAlias(IdentifierInfo* Name,
1904419040
}
1904519041
}
1904619042

19047-
Decl *Sema::getObjCDeclContext() const {
19043+
ObjCContainerDecl *Sema::getObjCDeclContext() const {
1904819044
return (dyn_cast_or_null<ObjCContainerDecl>(CurContext));
1904919045
}
1905019046

0 commit comments

Comments
 (0)