aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/ASTWriterDecl.cpp
diff options
context:
space:
mode:
authorYounan Zhang <zyn7109@gmail.com>2025-01-08 19:40:16 +0800
committerGitHub <noreply@github.com>2025-01-08 19:40:16 +0800
commitedf14ed6b182b9ae9efa0c854f3d4744bb67bf08 (patch)
treefaf4c92ac2ce90f93eb12f7d1dbb6c3dcd342935 /clang/lib/Serialization/ASTWriterDecl.cpp
parentbfa711a970d50c9101c8962609f9aad4f5395825 (diff)
downloadllvm-edf14ed6b182b9ae9efa0c854f3d4744bb67bf08.zip
llvm-edf14ed6b182b9ae9efa0c854f3d4744bb67bf08.tar.gz
llvm-edf14ed6b182b9ae9efa0c854f3d4744bb67bf08.tar.bz2
[Clang] Don't form a type constraint if the concept is invalid (#122065)
After 0dedd6fe1 and 03229e7c0, invalid concept declarations might lack expressions for evaluation and normalization. This could make it crash in certain scenarios, apart from the one of evaluation concepts showed in 03229e7c0, there's also an issue when checking specializations where the normalization also relies on a non-null expression. This patch prevents that by avoiding building up a type constraint in such situations, thereafter the template parameter wouldn't have a concept specialization of a null expression. With this patch, the assumption in ASTWriterDecl is no longer valid. Namely, HasConstraint and TypeConstraintInitialized must now represent different meanings for both source fidelity and semantic requirements. Fixes https://github.com/llvm/llvm-project/issues/115004 Fixes https://github.com/llvm/llvm-project/issues/121980
Diffstat (limited to 'clang/lib/Serialization/ASTWriterDecl.cpp')
-rw-r--r--clang/lib/Serialization/ASTWriterDecl.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 75c1d9a..f8ed155 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1951,7 +1951,8 @@ void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Record.push_back(D->wasDeclaredWithTypename());
const TypeConstraint *TC = D->getTypeConstraint();
- assert((bool)TC == D->hasTypeConstraint());
+ if (D->hasTypeConstraint())
+ Record.push_back(/*TypeConstraintInitialized=*/TC != nullptr);
if (TC) {
auto *CR = TC->getConceptReference();
Record.push_back(CR != nullptr);
@@ -1969,7 +1970,7 @@ void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
if (OwnsDefaultArg)
Record.AddTemplateArgumentLoc(D->getDefaultArgument());
- if (!TC && !OwnsDefaultArg &&
+ if (!D->hasTypeConstraint() && !OwnsDefaultArg &&
D->getDeclContext() == D->getLexicalDeclContext() &&
!D->isInvalidDecl() && !D->hasAttrs() &&
!D->isTopLevelDeclInObjCContainer() && !D->isImplicit() &&