[PATCH] D96950: [clang][CodeComplete] Ensure there are no crashes when completing with ParenListExprs as LHS

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 18 04:49:58 PST 2021


kadircet created this revision.
kadircet added a reviewer: sammccall.
kadircet requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96950

Files:
  clang/lib/Sema/SemaCodeComplete.cpp


Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5257,11 +5257,21 @@
 
   // Peel off the ParenListExpr by chosing the last one, as they don't have a
   // predefined type.
-  if (auto *PLE = llvm::dyn_cast<ParenListExpr>(Base))
+  if (auto *PLE = llvm::dyn_cast<ParenListExpr>(Base)) {
+    // FIXME: Get rid of this check once we are sure the ParenListExpr in here
+    // cannot be empty. This is assumed to ultimately be a chain of comma
+    // operators. We expect other ParenListExprs to be resolved to e.g.
+    // constructor calls before getting here. Same for OtherOpBase.
+    if (PLE->getNumExprs() == 0)
+      return;
     Base = PLE->getExpr(PLE->getNumExprs() - 1);
+  }
   if (OtherOpBase) {
-    if (auto *PLE = llvm::dyn_cast<ParenListExpr>(OtherOpBase))
+    if (auto *PLE = llvm::dyn_cast<ParenListExpr>(OtherOpBase)) {
+      if (PLE->getNumExprs() == 0)
+        return;
       OtherOpBase = PLE->getExpr(PLE->getNumExprs() - 1);
+    }
   }
 
   ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
@@ -5698,8 +5708,15 @@
 
   // If we have a ParenListExpr for LHS, peel it off by chosing the last expr.
   // As ParenListExprs don't have a predefined type.
-  if (auto *PLE = llvm::dyn_cast<ParenListExpr>(Fn))
+  if (auto *PLE = llvm::dyn_cast<ParenListExpr>(Fn)) {
+    // FIXME: Get rid of this check once we are sure the ParenListExpr in here
+    // cannot be empty. This is assumed to ultimately be a chain of comma
+    // operators. We expect other ParenListExprs to be resolved to e.g.
+    // constructor calls before getting here.
+    if (PLE->getNumExprs() == 0)
+      return QualType();
     Fn = PLE->getExpr(PLE->getNumExprs() - 1);
+  }
 
   // FIXME: Provide support for variadic template functions.
   // Ignore type-dependent call expressions entirely.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96950.324600.patch
Type: text/x-patch
Size: 1968 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210218/866ed411/attachment.bin>


More information about the cfe-commits mailing list