Author: Erich Keane Date: 2023-04-28T10:09:26-07:00 New Revision: 15f0491d3963d91202aef659acc20f59aa83fae7
URL: https://github.com/llvm/llvm-project/commit/15f0491d3963d91202aef659acc20f59aa83fae7 DIFF: https://github.com/llvm/llvm-project/commit/15f0491d3963d91202aef659acc20f59aa83fae7.diff LOG: [NFC] Fix a mem-sanitizer found issue in AutoType We only need the list of constriant template arguments when we have a valid constraint. We give up on merging the auto-type constraints if the template arguments don't match, but neglected to clear the collection of template arguments. The result was we had an AutoType where we initialized the number of template arguments, but never initialized the template arguments themselves. This patch adds an assert to catch this in the future, plus ensures we clear out the vector so we don't try to create the AutoType incorrectly. Added: Modified: clang/lib/AST/ASTContext.cpp clang/lib/AST/Type.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e331df86235b2..6bc202ecd5b02 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -12982,8 +12982,10 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X, SmallVector<TemplateArgument, 8> As; if (CD && getCommonTemplateArguments(Ctx, As, AX->getTypeConstraintArguments(), - AY->getTypeConstraintArguments())) + AY->getTypeConstraintArguments())) { CD = nullptr; // The arguments diff er, so make it unconstrained. + As.clear(); + } // Both auto types can't be dependent, otherwise they wouldn't have been // sugar. This implies they can't contain unexpanded packs either. diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index e1686a7c69d52..c0d225034be89 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -4630,6 +4630,7 @@ AutoType::AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword, AutoTypeBits.Keyword = (unsigned)Keyword; AutoTypeBits.NumArgs = TypeConstraintArgs.size(); this->TypeConstraintConcept = TypeConstraintConcept; + assert(TypeConstraintConcept || AutoTypeBits.NumArgs == 0); if (TypeConstraintConcept) { auto *ArgBuffer = const_cast<TemplateArgument *>(getTypeConstraintArguments().data()); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits