From 15f0491d3963d91202aef659acc20f59aa83fae7 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Fri, 28 Apr 2023 09:54:28 -0700 Subject: [PATCH] [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. --- clang/lib/AST/ASTContext.cpp | 4 +++- clang/lib/AST/Type.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e331df8..6bc202e 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 As; if (CD && getCommonTemplateArguments(Ctx, As, AX->getTypeConstraintArguments(), - AY->getTypeConstraintArguments())) + AY->getTypeConstraintArguments())) { CD = nullptr; // The arguments differ, 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 e1686a7..c0d2250 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(getTypeConstraintArguments().data()); -- 2.7.4