r255754 - [Objective-c] Fix a crash that occurs when ObjCTypeParamList::back() is

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 15 22:25:38 PST 2015


Author: ahatanak
Date: Wed Dec 16 00:25:38 2015
New Revision: 255754

URL: http://llvm.org/viewvc/llvm-project?rev=255754&view=rev
Log:
[Objective-c] Fix a crash that occurs when ObjCTypeParamList::back() is
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

Modified:
    cfe/trunk/lib/Parse/ParseObjc.cpp
    cfe/trunk/test/SemaObjC/kindof.m

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=255754&r1=255753&r2=255754&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Dec 16 00:25:38 2015
@@ -603,7 +603,7 @@ ObjCTypeParamList *Parser::parseObjCType
   // whether there are any protocol references.
   lAngleLoc = SourceLocation();
   rAngleLoc = SourceLocation();
-  return list;
+  return invalid ? nullptr : list;
 }
 
 /// Parse an objc-type-parameter-list.

Modified: cfe/trunk/test/SemaObjC/kindof.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/kindof.m?rev=255754&r1=255753&r2=255754&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/kindof.m (original)
+++ cfe/trunk/test/SemaObjC/kindof.m Wed Dec 16 00:25:38 2015
@@ -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.
+ at interface Array1<T> : NSObject
+ at end
+
+ at interface I1 : NSObject
+ at end
+
+ at interface Array1<__kindof I1*>(extensions1) // expected-error{{expected type parameter name}}
+ at end
+
+ at interface Array2<T1, T2, T3> : NSObject
+ at end
+
+ at interface Array2<T, T, __kindof I1*>(extensions2) // expected-error{{expected type parameter name}} expected-error{{redeclaration of type parameter 'T'}}
+ at end




More information about the cfe-commits mailing list