[clang] [Clang][Sema] fix outline member function template with default align crash (PR #78400)

Qizhi Hu via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 19 02:12:50 PST 2024


https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/78400

>From 08382e9f909bace4dbaf1f0c5d62d4e17978e3aa Mon Sep 17 00:00:00 2001
From: huqizhi <huqizhi at feysh.com>
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] fix

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..ab3ac2d7dc0806 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -201,8 +201,16 @@ Response HandleFunction(const FunctionDecl *Function,
     // If this function was instantiated from a specialized member that is
     // a function template, we're done.
     assert(Function->getPrimaryTemplate() && "No function template?");
-    if (Function->getPrimaryTemplate()->isMemberSpecialization())
+    if (Function->getPrimaryTemplate()->isMemberSpecialization()) {
+      if (Function->isOutOfLine()) {
+        FunctionDecl *PatternFD =
+            Function->getTemplateInstantiationPattern(/*ForDefinition*/ false);
+        unsigned Depth = PatternFD->getTemplateDepth();
+        if (Depth > 0)
+          Result.addOuterRetainedLevels(Depth - 1);
+      }
       return Response::Done();
+    }
 
     // If this function is a generic lambda specialization, we are done.
     if (!ForConstraintInstantiation &&



More information about the cfe-commits mailing list