-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][Sema] fix outline member function template with default align crash #78400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang][Sema] fix outline member function template with default align crash #78400
Conversation
@llvm/pr-subscribers-clang Author: Qizhi Hu (jcsxky) ChangesFull diff: https://github.com/llvm/llvm-project/pull/78400.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..92bbc4e51cb4c7 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -201,7 +201,7 @@ 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() && !Function->isOutOfLine())
return Response::Done();
// If this function is a generic lambda specialization, we are done.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
07b6d21
to
774f1ab
Compare
774f1ab
to
e4ac395
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs a release note.
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument( | |||
// default argument expression appears. | |||
ContextRAII SavedContext(*this, FD); | |||
std::unique_ptr<LocalInstantiationScope> LIS; | |||
auto NewTemplateArgs = TemplateArgs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use auto here.
getASTContext(), TemplateArgs.getInnermost()); | ||
NewTemplateArgs = getTemplateInstantiationArgs( | ||
FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true, | ||
nullptr, false, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs /*argname=*/
comments on bools/nullptrs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All review has been applied.
b9de8c5
to
852e2d2
Compare
clang/docs/ReleaseNotes.rst
Outdated
@@ -859,6 +859,9 @@ Bug Fixes in This Version | |||
Fixes (`#78290 <https://github.com/llvm/llvm-project/issues/78290>`_) | |||
- Fixed assertion failure with deleted overloaded unary operators. | |||
Fixes (`#78314 <https://github.com/llvm/llvm-project/issues/78314>`_) | |||
- Fix crash when specialize out-of-line member function with default parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix crash when specialize out-of-line member function with default parameter | |
- 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thanks for your guidance of grammar and expression! I have update the note according to you suggestion.
852e2d2
to
7166061
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, let me know if you need someone to merge this for you.
7166061
to
fbf5cca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick
Result = SubstInitializer(PatternExpr, TemplateArgs, | ||
/*DirectInit*/false); | ||
Result = SubstInitializer(PatternExpr, NewTemplateArgs, | ||
/*DirectInit*/ false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/*DirectInit=*/false)
@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! |
…lt align crash (llvm#78400)" This reverts commit 7b33899. A regression was discovered here: llvm#78400 and the author requested a revert to give time to review.
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: #80144 |
Try to fix issue and some extented problem. Root cause of current issue is that error handling in instantiation of function parameter with default initialization on sizeof or align expression. When instance an out-of-line template member function, depth of
TemplateTypeParmDecl
in default initialization doesn't change while depth of other template parameter does and this will lead to some template parameter uninstanced. Also, sometime it will leader to wrong instantiation when it uses the template parameter of class.Fix it by add template args of context when it's out-of-line. This will make
MultiLevelTemplateArgumentList::getNumLevels
matching the depth of template parameter. Testcase with somestatic_assert
demonstrates the template parameter has been instanced correctly.