Skip to content

Commit

Permalink
[clang][CodeComplete] Ensure there are no crashes when completing wit…
Browse files Browse the repository at this point in the history
…h ParenListExprs as LHS

Differential Revision: https://reviews.llvm.org/D96950
  • Loading branch information
kadircet committed Feb 23, 2021
1 parent 99df95f commit 7fc6c60
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5158,25 +5158,32 @@ class ConceptInfo {

llvm::DenseMap<const IdentifierInfo *, Member> Results;
};

// If \p Base is ParenListExpr, assume a chain of comma operators and pick the
// last expr. We expect other ParenListExprs to be resolved to e.g. constructor
// calls before here. (So the ParenListExpr should be nonempty, but check just
// in case)
Expr *unwrapParenList(Expr *Base) {
if (auto *PLE = llvm::dyn_cast_or_null<ParenListExpr>(Base)) {
if (PLE->getNumExprs() == 0)
return nullptr;
Base = PLE->getExpr(PLE->getNumExprs() - 1);
}
return Base;
}

} // namespace

void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
Expr *OtherOpBase,
SourceLocation OpLoc, bool IsArrow,
bool IsBaseExprStatement,
QualType PreferredType) {
Base = unwrapParenList(Base);
OtherOpBase = unwrapParenList(OtherOpBase);
if (!Base || !CodeCompleter)
return;

// 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))
Base = PLE->getExpr(PLE->getNumExprs() - 1);
if (OtherOpBase) {
if (auto *PLE = llvm::dyn_cast<ParenListExpr>(OtherOpBase))
OtherOpBase = PLE->getExpr(PLE->getNumExprs() - 1);
}

ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
if (ConvertedBase.isInvalid())
return;
Expand Down Expand Up @@ -5606,14 +5613,10 @@ ProduceSignatureHelp(Sema &SemaRef, Scope *S,
QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
ArrayRef<Expr *> Args,
SourceLocation OpenParLoc) {
Fn = unwrapParenList(Fn);
if (!CodeCompleter || !Fn)
return QualType();

// 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))
Fn = PLE->getExpr(PLE->getNumExprs() - 1);

// FIXME: Provide support for variadic template functions.
// Ignore type-dependent call expressions entirely.
if (Fn->isTypeDependent() || anyNullArguments(Args))
Expand Down

0 comments on commit 7fc6c60

Please sign in to comment.