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

2024-01-31 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > @jcsxky this patch introduced a regression. Please see the reproducer here: 
> > https://godbolt.org/z/rEfWP75Ta. It compiles before this change and fails 
> > at this change. It also compiles with gcc and clang-17.
> 
> Sorry for importing new bugs. @erichkeane Could you help me revert this patch 
> in order to not influence others since I am not familiar with github 
> reverting operation? I afraid I would spent a long time to look into the root 
> cause of the issue. Appreciate for you help and many thanks!

No worries, happens all the time :)  Reverting because you requested it, feel 
free to submit a new version of this review that fixes that as well!  Revert 
will be commited from here: https://github.com/llvm/llvm-project/pull/80144

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-31 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> @jcsxky this patch introduced a regression. Please see the reproducer here: 
> https://godbolt.org/z/rEfWP75Ta. It compiles before this change and fails at 
> this change. It also compiles with gcc and clang-17.

Sorry for importing new bugs. @erichkeane Could you help me revert this patch 
in order to not influence others since I am not familiar with github reverting 
operation? I afraid I would spent a long time to look into the root cause of 
the issue. Appreciate for you help and many thanks!

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-31 Thread via cfe-commits

bgra8 wrote:

@jcsxky this patch introduced a regression. Please see the reproducer here: 
https://godbolt.org/z/rEfWP75Ta. It compiles before this change and fails at 
this change. It also compiles with gcc and clang-17.


https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-26 Thread Shafik Yaghmour via cfe-commits


@@ -3061,11 +3062,19 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+TemplateArgumentList *CurrentTemplateArgumentList =
+TemplateArgumentList::CreateCopy(getASTContext(),
+ TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), /*Final=*/false,
+CurrentTemplateArgumentList, /*RelativeToPrimary=*/true);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);

shafik wrote:

`/*DirectInit=*/false)`

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-26 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

nitpick

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-26 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-25 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-25 Thread Qizhi Hu via cfe-commits

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

>From fbf5cca3ecdbcc0a440c42a1f0f52552a0f8ece6 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 13 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 3 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c441baf2d74162..5330cd9caad801 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -115,6 +115,10 @@ Bug Fixes to C++ Support
 
 - Fix crash when using lifetimebound attribute in function with trailing 
return.
   Fixes (`#73619 `_)
+- Fix a crash when specializing an out-of-line member function with a default
+  parameter where we did an incorrect specialization of the initialization of
+  the default parameter.
+  Fixes (`#68490 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index e12186d7d82f8d..41e58b91de4e08 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3049,6 +3049,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3061,11 +3062,19 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+TemplateArgumentList *CurrentTemplateArgumentList =
+TemplateArgumentList::CreateCopy(getASTContext(),
+ TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), /*Final=*/false,
+CurrentTemplateArgumentList, /*RelativeToPrimary=*/true);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 00..4bcea7eaa10176
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-24 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.

LGTM, let me know if you need someone to merge this for you.

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-23 Thread Qizhi Hu via cfe-commits


@@ -859,6 +859,9 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- Fix crash when specialize out-of-line member function with default parameter

jcsxky wrote:

Yeah, thanks for your guidance of grammar and expression! I have update the 
note according to you suggestion.

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-23 Thread Qizhi Hu via cfe-commits

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

>From 71660611976c4f21f71ebfe509fc021b1e3586e2 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 13 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 3 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 060bc7669b72a5..53bbf582420837 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -859,6 +859,10 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- Fix a crash when specializing an out-of-line member function with a default
+  parameter where we did an incorrect specialization of the initialization of
+  the default parameter.
+  Fixes (`#68490 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index e12186d7d82f8d..41e58b91de4e08 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3049,6 +3049,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3061,11 +3062,19 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+TemplateArgumentList *CurrentTemplateArgumentList =
+TemplateArgumentList::CreateCopy(getASTContext(),
+ TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), /*Final=*/false,
+CurrentTemplateArgumentList, /*RelativeToPrimary=*/true);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 00..4bcea7eaa10176
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-23 Thread Erich Keane via cfe-commits


@@ -859,6 +859,9 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- Fix crash when specialize out-of-line member function with default parameter

erichkeane wrote:

```suggestion
- Fix a crash when specializing an out-of-line member function with a default 
parameter where we did an incorrect specialization of the initialization of the 
default parameter.
```

Is this accurate?  

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-22 Thread Qizhi Hu via cfe-commits


@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);

jcsxky wrote:

All review has been applied.

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-22 Thread Qizhi Hu via cfe-commits

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

>From 852e2d26ee3433e09978da93dfe6303faac92876 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 13 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 3 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb15dfb99bec977..bff8e496cbeed5f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -859,6 +859,9 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- Fix crash when specialize out-of-line member function with default parameter
+  and issue with incorrect specialization of the initialization of default 
parameter.
+  Fixes (`#68490 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index e12186d7d82f8d0..41e58b91de4e08e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3049,6 +3049,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3061,11 +3062,19 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+TemplateArgumentList *CurrentTemplateArgumentList =
+TemplateArgumentList::CreateCopy(getASTContext(),
+ TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), /*Final=*/false,
+CurrentTemplateArgumentList, /*RelativeToPrimary=*/true);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 000..4bcea7eaa101763
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-22 Thread Qizhi Hu via cfe-commits

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

>From b9de8c52a2ffbd03c8a5368f6e62ba6c68ce2125 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 13 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 3 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bb26fcae18d6b..ccdce2c299b022 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -828,6 +828,9 @@ Bug Fixes in This Version
 - Fix an issue with missing symbol definitions when the first coroutine
   statement appears in a discarded ``if constexpr`` branch.
   Fixes (`#78290 `_)
+- Fix crash when specialize out-of-line member function with default parameter
+  and issue with incorrect specialization of the initialization of default 
parameter.
+  Fixes (`#68490 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..d310dfdd61c600 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,19 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+TemplateArgumentList *CurrentTemplateArgumentList =
+TemplateArgumentList::CreateCopy(getASTContext(),
+ TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), /*Final=*/false,
+CurrentTemplateArgumentList, /*RelativeToPrimary=*/true);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 00..4bcea7eaa10176
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-22 Thread Erich Keane via cfe-commits


@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;

erichkeane wrote:

Don't use auto here.

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-22 Thread Erich Keane via cfe-commits


@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);

erichkeane wrote:

Needs `/*argname=*/ ` comments on bools/nullptrs.

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-22 Thread Erich Keane via cfe-commits

https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-22 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

Also needs a release note.

https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-20 Thread Qizhi Hu via cfe-commits

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

>From e4ac395028e651721677d85caf6c76e3a7f79308 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 2 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..1ed63db75294aa 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 00..4bcea7eaa10176
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From 774f1abbe16cd642b0838105f68e5c5d02e37aef Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 2 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..1ed63db75294aa 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 00..4bcea7eaa10176
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From 07b6d2105b84ba045bc8093ac0541d2db6e29cd5 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 -
 clang/test/SemaTemplate/default-parm-init.cpp | 51 +++
 2 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..1ed63db75294aa 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 00..ecdffa9c21d373
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From 9bb08560d401018cc63dc3b3e635c4f95cad7819 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 -
 clang/test/SemaTemplate/default-parm-init.cpp | 51 +++
 2 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b4..1ed63db75294aab 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 000..78ad71ee7141d66
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}
\ No newline at end of file

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/78400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From e8a5715a6255bc110823dbe36734bb7bd17753d5 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b4..1ed63db75294aab 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From 1a1ae44bc9b937f8a79afa3b40c7ad32e1fde8dd Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] fix

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..1ed63db75294aa 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From c3856543fd56ec33bab6bcdcd3d833c0e19f58f9 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] fix

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b4..262fe71545a2a61 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3064,10 +3064,18 @@ bool Sema::SubstDefaultArgument(
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
 }
+auto NewTemplateArgs = TemplateArgs;
+if (FD->isOutOfLine()) {
+  auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+  getASTContext(), TemplateArgs.getInnermost());
+  NewTemplateArgs = getTemplateInstantiationArgs(
+  FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+  nullptr, false, false);
+}
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From 4c1f1d6427f27f7ed3cee8b49ee43a96025f2f0e Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH] fix

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..286da30529f038 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3064,10 +3064,14 @@ bool Sema::SubstDefaultArgument(
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
 }
-
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+auto NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-19 Thread Qizhi Hu via cfe-commits

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

>From 08382e9f909bace4dbaf1f0c5d62d4e17978e3aa Mon Sep 17 00:00:00 2001
From: huqizhi 
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 &&

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits