]> granicus.if.org Git - clang/commitdiff
[ODRHash] Fix null pointer dereference for ObjC selectors with empty slots.
authorVolodymyr Sapsai <vsapsai@apple.com>
Fri, 28 Jun 2019 17:42:17 +0000 (17:42 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Fri, 28 Jun 2019 17:42:17 +0000 (17:42 +0000)
`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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364664 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ODRHash.cpp
test/Modules/odr_hash.mm

index e47154088d9f99e89e558be78c71e49863374c19..3b89c630b451e334472b5ada4423bb8ffeedf531 100644 (file)
@@ -71,8 +71,13 @@ void ODRHash::AddDeclarationNameImpl(DeclarationName Name) {
     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;
   }
index f04fb7eb5e8e03bbfaa58abf0d81282663ec6494..86ddd16b94fb705d92e9c15c77854f1a4bba1167 100644 (file)
 @interface Interface3 <T : I1 *>
 @end
 
+@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;
+@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@second.h:* {{'CallMethods::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
+// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
+
+// expected-error@second.h:* {{'CallMethods::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
+// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
+}  // namespace CallMethods
+
 // Keep macros contained to one file.
 #ifdef FIRST
 #undef FIRST