]> granicus.if.org Git - clang/commitdiff
[Objective-c] Fix a crash that occurs when ObjCTypeParamList::back() is
authorAkira Hatanaka <ahatanaka@apple.com>
Wed, 16 Dec 2015 06:25:38 +0000 (06:25 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Wed, 16 Dec 2015 06:25:38 +0000 (06:25 +0000)
called on an empty list.

This commit makes Parser::parseObjCTypeParamListOrProtocolRefs return
nullptr if it sees an invalid type parameter (e.g., __kindof) in the
type parameter list.

rdar://problem/23068920

Differential Revision: http://reviews.llvm.org/D15463

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

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

index 63c01932c1a6a659cc436dba7be4c6f5ca0203e0..8a028b5037651ac3003ec6c891e6e33776d3e3ea 100644 (file)
@@ -603,7 +603,7 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs(
   // whether there are any protocol references.
   lAngleLoc = SourceLocation();
   rAngleLoc = SourceLocation();
-  return list;
+  return invalid ? nullptr : list;
 }
 
 /// Parse an objc-type-parameter-list.
index b19e4237207880603cc8a780fd1462519c645920..f205e68ea128a1c84325df1e561f2b08215cdcb4 100644 (file)
@@ -302,3 +302,19 @@ void testNullability() {
   void processCopyable(__typeof(getSomeCopyable()) string);
   processCopyable(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
 }
+
+// Check that clang doesn't crash when a type parameter is illegal.
+@interface Array1<T> : NSObject
+@end
+
+@interface I1 : NSObject
+@end
+
+@interface Array1<__kindof I1*>(extensions1) // expected-error{{expected type parameter name}}
+@end
+
+@interface Array2<T1, T2, T3> : NSObject
+@end
+
+@interface Array2<T, T, __kindof I1*>(extensions2) // expected-error{{expected type parameter name}} expected-error{{redeclaration of type parameter 'T'}}
+@end