r364664 - [ODRHash] Fix null pointer dereference for ObjC selectors with empty slots.
Volodymyr Sapsai via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 28 10:42:17 PDT 2019
Author: vsapsai
Date: Fri Jun 28 10:42:17 2019
New Revision: 364664
URL: http://llvm.org/viewvc/llvm-project?rev=364664&view=rev
Log:
[ODRHash] Fix null pointer dereference for ObjC selectors with empty slots.
`Selector::getIdentifierInfoForSlot` returns NULL if a slot has no
corresponding identifier. Add a boolean to the hash and a NULL check.
rdar://problem/51615164
Reviewers: rtrieu
Reviewed By: rtrieu
Subscribers: dexonsmith, cfe-commits, jkorous
Differential Revision: https://reviews.llvm.org/D63789
Modified:
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/test/Modules/odr_hash.mm
Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=364664&r1=364663&r2=364664&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Fri Jun 28 10:42:17 2019
@@ -71,8 +71,13 @@ void ODRHash::AddDeclarationNameImpl(Dec
AddBoolean(S.isKeywordSelector());
AddBoolean(S.isUnarySelector());
unsigned NumArgs = S.getNumArgs();
+ ID.AddInteger(NumArgs);
for (unsigned i = 0; i < NumArgs; ++i) {
- AddIdentifierInfo(S.getIdentifierInfoForSlot(i));
+ const IdentifierInfo *II = S.getIdentifierInfoForSlot(i);
+ AddBoolean(II);
+ if (II) {
+ AddIdentifierInfo(II);
+ }
}
break;
}
Modified: cfe/trunk/test/Modules/odr_hash.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.mm?rev=364664&r1=364663&r2=364664&view=diff
==============================================================================
--- cfe/trunk/test/Modules/odr_hash.mm (original)
+++ cfe/trunk/test/Modules/odr_hash.mm Fri Jun 28 10:42:17 2019
@@ -57,6 +57,14 @@
@interface Interface3 <T : I1 *>
@end
+ at interface EmptySelectorSlot
+- (void)method:(int)arg;
+- (void)method:(int)arg :(int)empty;
+
+- (void)multiple:(int)arg1 args:(int)arg2 :(int)arg3;
+- (void)multiple:(int)arg1 :(int)arg2 args:(int)arg3;
+ at end
+
#endif
#if defined(FIRST)
@@ -289,6 +297,29 @@ Invalid3 i3;
} // namespace ObjCTypeParam
} // namespace Types
+namespace CallMethods {
+#if defined(FIRST)
+void invalid1(EmptySelectorSlot *obj) {
+ [obj method:0];
+}
+void invalid2(EmptySelectorSlot *obj) {
+ [obj multiple:0 args:0 :0];
+}
+#elif defined(SECOND)
+void invalid1(EmptySelectorSlot *obj) {
+ [obj method:0 :0];
+}
+void invalid2(EmptySelectorSlot *obj) {
+ [obj multiple:0 :0 args:0];
+}
+#endif
+// expected-error at second.h:* {{'CallMethods::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
+// expected-note at first.h:* {{but in 'FirstModule' found a different body}}
+
+// expected-error at second.h:* {{'CallMethods::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
+// expected-note at first.h:* {{but in 'FirstModule' found a different body}}
+} // namespace CallMethods
+
// Keep macros contained to one file.
#ifdef FIRST
#undef FIRST
More information about the cfe-commits
mailing list