Skip to content
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] Fix a "!CodeSynthesisContexts.empty()" assertion failure when constructing aggregate deduction guides. #89227

Merged
merged 2 commits into from
Apr 18, 2024

Conversation

hokein
Copy link
Collaborator

@hokein hokein commented Apr 18, 2024

We were missing to push an record to the instantiation stack in DeclareAggregateDeductionGuideForTypeAlias. This patch fixes that.

constructing the aggregate deduction guides.

We were missing to push an record to the instantiation stack in
`DeclareAggregateDeductionGuideForTypeAlias`.  This patch fixes that.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 18, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 18, 2024

@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)

Changes

We were missing to push an record to the instantiation stack in DeclareAggregateDeductionGuideForTypeAlias. This patch fixes that.


Full diff: https://github.com/llvm/llvm-project/pull/89227.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaTemplate.cpp (+5)
  • (modified) clang/test/SemaCXX/cxx20-ctad-type-alias.cpp (+10)
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 95171359f0ab17..8b039c26f2cef5 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3043,6 +3043,11 @@ FunctionTemplateDecl *DeclareAggregateDeductionGuideForTypeAlias(
     return nullptr;
 
   LocalInstantiationScope Scope(SemaRef);
+  Sema::InstantiatingTemplate BuildingDeductionGuides(
+        SemaRef, AliasTemplate->getLocation(), RHSDeductionGuide,
+        Sema::InstantiatingTemplate::BuildingDeductionGuidesTag{});
+  if (BuildingDeductionGuides.isInvalid())
+    return nullptr;
 
   // Build a new template parameter list for the synthesized aggregate deduction
   // guide by transforming the one from RHSDeductionGuide.
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index b71cd46f884d63..6f04264a655ad5 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -279,3 +279,13 @@ Bar t = Foo<K<Container>>();
 
 Bar s = 1; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of}}
 } // namespace test20
+
+namespace test21 {
+template <typename T, unsigned N>
+struct Array { const T member[N]; };
+template <unsigned N>
+using String = Array<char, N>;
+
+// Verify no crash on constructing the aggregate deduction guides.
+String s("hello");
+} // namespace test21

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link

github-actions bot commented Apr 18, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@hokein hokein merged commit 4c3514f into llvm:main Apr 18, 2024
3 of 4 checks passed
@hokein hokein deleted the fix-crash-aggregate branch April 18, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants