ahatanak created this revision.
ahatanak added a subscriber: cfe-commits.

This patch fixes a crash that occurs when __kindof is incorrectly used in the 
type parameter list of an interface. The crash occurs because 
ObjCTypeParamList::back() is called in checkTypeParamListConsistency on an 
empty list:

00762       diagLoc = S.getLocForEndOfToken(newTypeParams->back()->getLocEnd());

http://reviews.llvm.org/D15463

Files:
  lib/Parse/ParseObjc.cpp
  test/SemaObjC/kindof.m

Index: test/SemaObjC/kindof.m
===================================================================
--- test/SemaObjC/kindof.m
+++ test/SemaObjC/kindof.m
@@ -302,3 +302,13 @@
   void processCopyable(__typeof(getSomeCopyable()) string);
   processCopyable(0); // expected-warning{{null passed to a callee that 
requires a non-null argument}}
 }
+
+// __kinddof cannot be used in parameter list. 
+@interface Array1<T> : NSObject
+@end
+
+@interface I1 : NSObject
+@end
+
+@interface Array1<__kindof I1*>(extensions) // // expected-error{{expected 
type parameter name}}
+@end
Index: lib/Parse/ParseObjc.cpp
===================================================================
--- lib/Parse/ParseObjc.cpp
+++ lib/Parse/ParseObjc.cpp
@@ -603,7 +603,7 @@
   // whether there are any protocol references.
   lAngleLoc = SourceLocation();
   rAngleLoc = SourceLocation();
-  return list;
+  return invalid ? nullptr : list;
 }
 
 /// Parse an objc-type-parameter-list.


Index: test/SemaObjC/kindof.m
===================================================================
--- test/SemaObjC/kindof.m
+++ test/SemaObjC/kindof.m
@@ -302,3 +302,13 @@
   void processCopyable(__typeof(getSomeCopyable()) string);
   processCopyable(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
 }
+
+// __kinddof cannot be used in parameter list. 
+@interface Array1<T> : NSObject
+@end
+
+@interface I1 : NSObject
+@end
+
+@interface Array1<__kindof I1*>(extensions) // // expected-error{{expected type parameter name}}
+@end
Index: lib/Parse/ParseObjc.cpp
===================================================================
--- lib/Parse/ParseObjc.cpp
+++ lib/Parse/ParseObjc.cpp
@@ -603,7 +603,7 @@
   // whether there are any protocol references.
   lAngleLoc = SourceLocation();
   rAngleLoc = SourceLocation();
-  return list;
+  return invalid ? nullptr : list;
 }
 
 /// Parse an objc-type-parameter-list.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to