[PATCH] D146680: Add test for AST Writer crash

Walter Gray via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 22 17:58:53 PDT 2023


yeswalrus created this revision.
Herald added a project: All.
yeswalrus requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix ArgsAsWritten being null in certain circumstances when parsing ASTs


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146680

Files:
  clang/include/clang/AST/ExprConcepts.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ExprConcepts.cpp
  clang/test/PCH/cxx2a-constraints.cpp


Index: clang/test/PCH/cxx2a-constraints.cpp
===================================================================
--- clang/test/PCH/cxx2a-constraints.cpp
+++ clang/test/PCH/cxx2a-constraints.cpp
@@ -26,6 +26,8 @@
 
 void j(SizedLike<int> auto ...ints) {}
 
+template<template<SizedLike> class P> struct S1 { };
+
 #else /*included pch*/
 
 int main() {
Index: clang/lib/AST/ExprConcepts.cpp
===================================================================
--- clang/lib/AST/ExprConcepts.cpp
+++ clang/lib/AST/ExprConcepts.cpp
@@ -72,13 +72,14 @@
 
 ConceptSpecializationExpr::ConceptSpecializationExpr(
     const ASTContext &C, ConceptDecl *NamedConcept,
+    const ASTTemplateArgumentListInfo *ArgsAsWritten,
     ImplicitConceptSpecializationDecl *SpecDecl,
     const ConstraintSatisfaction *Satisfaction, bool Dependent,
     bool ContainsUnexpandedParameterPack)
     : Expr(ConceptSpecializationExprClass, C.BoolTy, VK_PRValue, OK_Ordinary),
       ConceptReference(NestedNameSpecifierLoc(), SourceLocation(),
                        DeclarationNameInfo(), NamedConcept, NamedConcept,
-                       nullptr),
+                       ArgsAsWritten),
       SpecDecl(SpecDecl),
       Satisfaction(Satisfaction
                        ? ASTConstraintSatisfaction::Create(C, *Satisfaction)
@@ -95,12 +96,13 @@
 
 ConceptSpecializationExpr *ConceptSpecializationExpr::Create(
     const ASTContext &C, ConceptDecl *NamedConcept,
+    const ASTTemplateArgumentListInfo *ArgsAsWritten,
     ImplicitConceptSpecializationDecl *SpecDecl,
     const ConstraintSatisfaction *Satisfaction, bool Dependent,
     bool ContainsUnexpandedParameterPack) {
-  return new (C)
-      ConceptSpecializationExpr(C, NamedConcept, SpecDecl, Satisfaction,
-                                Dependent, ContainsUnexpandedParameterPack);
+  return new (C) ConceptSpecializationExpr(C, NamedConcept, ArgsAsWritten,
+                                           SpecDecl, Satisfaction, Dependent,
+                                           ContainsUnexpandedParameterPack);
 }
 
 const TypeConstraint *
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -765,8 +765,8 @@
       CSE->getNamedConcept()->getLocation(), NewConverted);
 
   Expr *NewIDC = ConceptSpecializationExpr::Create(
-      C, CSE->getNamedConcept(), CSD, nullptr, CSE->isInstantiationDependent(),
-      CSE->containsUnexpandedParameterPack());
+      C, CSE->getNamedConcept(), CSE->getTemplateArgsAsWritten(), CSD, nullptr,
+      CSE->isInstantiationDependent(), CSE->containsUnexpandedParameterPack());
 
   if (auto *OrigFold = dyn_cast<CXXFoldExpr>(IDC))
     NewIDC = new (C) CXXFoldExpr(
Index: clang/include/clang/AST/ExprConcepts.h
===================================================================
--- clang/include/clang/AST/ExprConcepts.h
+++ clang/include/clang/AST/ExprConcepts.h
@@ -64,6 +64,7 @@
                             const ConstraintSatisfaction *Satisfaction);
 
   ConceptSpecializationExpr(const ASTContext &C, ConceptDecl *NamedConcept,
+                            const ASTTemplateArgumentListInfo *ArgsAsWritten,
                             ImplicitConceptSpecializationDecl *SpecDecl,
                             const ConstraintSatisfaction *Satisfaction,
                             bool Dependent,
@@ -81,6 +82,7 @@
 
   static ConceptSpecializationExpr *
   Create(const ASTContext &C, ConceptDecl *NamedConcept,
+         const ASTTemplateArgumentListInfo *ArgsAsWritten,
          ImplicitConceptSpecializationDecl *SpecDecl,
          const ConstraintSatisfaction *Satisfaction, bool Dependent,
          bool ContainsUnexpandedParameterPack);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146680.507568.patch
Type: text/x-patch
Size: 3769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230323/862eb685/attachment-0001.bin>


More information about the cfe-commits mailing list