[SemaObjC] Fix a crash on an invalid ternary with ARC pointers
authorErik Pilkington <erik.pilkington@gmail.com>
Tue, 13 Oct 2020 16:40:55 +0000 (12:40 -0400)
committerErik Pilkington <erik.pilkington@gmail.com>
Wed, 14 Oct 2020 01:20:20 +0000 (21:20 -0400)
FindCompositeObjCPointerType nulls out the subexpressions on error, so bail out
instead of trying to deref them.

clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaObjCXX/arc-type-conversion.mm

index ed57772..d39820f 100644 (file)
@@ -6325,6 +6325,8 @@ QualType Sema::CXXCheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
 
   // Similarly, attempt to find composite type of two objective-c pointers.
   Composite = FindCompositeObjCPointerType(LHS, RHS, QuestionLoc);
+  if (LHS.isInvalid() || RHS.isInvalid())
+    return QualType();
   if (!Composite.isNull())
     return Composite;
 
index 1e3790b..e8580cf 100644 (file)
@@ -216,3 +216,10 @@ void ownership_transfer_in_cast(void *vp, Block *pblk) {
 
 // Make sure we don't crash.
 void writeback_test(NSString & &) {} // expected-error {{type name declared as a reference to a reference}}
+
+void test_strong_opaque() {
+  __strong NSString *sptr;
+  void *vptr;
+
+  (void)(0 ? sptr : vptr); // expected-error{{operands to conditional of types 'NSString *' and 'void *' are incompatible in ARC mode}}
+}