[clang] [clang][NFC] Move `concepts::createSubstDiagAt` from AST to Sema (PR #113294)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 22 05:09:39 PDT 2024


https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/113294

>From a36a7b77b2fbabf29fe69a1e23c60ecfc9a53279 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Tue, 22 Oct 2024 13:42:51 +0300
Subject: [PATCH 1/2] [clang][NFC] Move `concepts::createSubstDiagAt` from AST
 to Sema

This fixes layering violation introduced in 2fd01d75a863184766ee0c82b5c0fc8be172448a. The declaration is moved to `SemaTemplateInstantiate` section of `Sema.h`, after the file where it's implemented.
---
 clang/include/clang/AST/ExprConcepts.h     |  8 --------
 clang/include/clang/Sema/Sema.h            |  7 +++++++
 clang/lib/Sema/SemaExprCXX.cpp             | 10 +++++-----
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  7 +++----
 4 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/AST/ExprConcepts.h b/clang/include/clang/AST/ExprConcepts.h
index 29913fd84c58b4..f3e32ce3961981 100644
--- a/clang/include/clang/AST/ExprConcepts.h
+++ b/clang/include/clang/AST/ExprConcepts.h
@@ -489,14 +489,6 @@ class NestedRequirement : public Requirement {
     return R->getKind() == RK_Nested;
   }
 };
-
-using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
-
-/// \brief create a Requirement::SubstitutionDiagnostic with only a
-/// SubstitutedEntity and DiagLoc using Sema's allocator.
-Requirement::SubstitutionDiagnostic *
-createSubstDiagAt(Sema &S, SourceLocation Location, EntityPrinter Printer);
-
 } // namespace concepts
 
 /// C++2a [expr.prim.req]:
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bc9c422ed4c477..18ba63ab5a7867 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13435,6 +13435,13 @@ class Sema final : public SemaBase {
     return CodeSynthesisContexts.size() > NonInstantiationEntries;
   }
 
+  using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
+
+  /// \brief create a Requirement::SubstitutionDiagnostic with only a
+  /// SubstitutedEntity and DiagLoc using Sema's allocator.
+  concepts::Requirement::SubstitutionDiagnostic *
+  createSubstDiagAt(SourceLocation Location, EntityPrinter Printer);
+
   ///@}
 
   //
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 40f24ea0ab2eaa..e19016ab23abe7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -9444,11 +9444,11 @@ Sema::BuildExprRequirement(
     ExprResult Constraint = SubstExpr(IDC, MLTAL);
     if (Constraint.isInvalid()) {
       return new (Context) concepts::ExprRequirement(
-          concepts::createSubstDiagAt(*this, IDC->getExprLoc(),
-                                      [&](llvm::raw_ostream &OS) {
-                                        IDC->printPretty(OS, /*Helper=*/nullptr,
-                                                         getPrintingPolicy());
-                                      }),
+          createSubstDiagAt(IDC->getExprLoc(),
+                            [&](llvm::raw_ostream &OS) {
+                              IDC->printPretty(OS, /*Helper=*/nullptr,
+                                               getPrintingPolicy());
+                            }),
           IsSimple, NoexceptLoc, ReturnTypeRequirement);
     }
     SubstitutedConstraintExpr =
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 457a9968c32a4a..198442dd9821ec 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2654,7 +2654,7 @@ QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
 
 static concepts::Requirement::SubstitutionDiagnostic *
 createSubstDiag(Sema &S, TemplateDeductionInfo &Info,
-                concepts::EntityPrinter Printer) {
+                Sema::EntityPrinter Printer) {
   SmallString<128> Message;
   SourceLocation ErrorLoc;
   if (Info.hasSFINAEDiagnostic()) {
@@ -2675,12 +2675,11 @@ createSubstDiag(Sema &S, TemplateDeductionInfo &Info,
 }
 
 concepts::Requirement::SubstitutionDiagnostic *
-concepts::createSubstDiagAt(Sema &S, SourceLocation Location,
-                            EntityPrinter Printer) {
+Sema::createSubstDiagAt(SourceLocation Location, EntityPrinter Printer) {
   SmallString<128> Entity;
   llvm::raw_svector_ostream OS(Entity);
   Printer(OS);
-  const ASTContext &C = S.Context;
+  const ASTContext &C = Context;
   return new (C) concepts::Requirement::SubstitutionDiagnostic{
       /*SubstitutedEntity=*/C.backupStr(Entity),
       /*DiagLoc=*/Location, /*DiagMessage=*/StringRef()};

>From d23e5deb407bbf865f758af2ab5d018fe276fd3a Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Tue, 22 Oct 2024 15:09:19 +0300
Subject: [PATCH 2/2] Fix comment per zyn0217's suggestion

---
 clang/include/clang/Sema/Sema.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 18ba63ab5a7867..9e6b04bc3f8f7c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13438,7 +13438,7 @@ class Sema final : public SemaBase {
   using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
 
   /// \brief create a Requirement::SubstitutionDiagnostic with only a
-  /// SubstitutedEntity and DiagLoc using Sema's allocator.
+  /// SubstitutedEntity and DiagLoc using ASTContext's allocator.
   concepts::Requirement::SubstitutionDiagnostic *
   createSubstDiagAt(SourceLocation Location, EntityPrinter Printer);
 



More information about the cfe-commits mailing list