diff options
author | Qizhi Hu <836744285@qq.com> | 2024-04-18 08:52:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 08:52:25 +0800 |
commit | 156ab4d4fb06be93b0cfce675e4cf86d330d879c (patch) | |
tree | e30800b6fd72b0c558d380838fe83cff41073e44 /clang/lib/Sema/SemaDecl.cpp | |
parent | 823eb1a3252dd773f9c4d92093591f1b39ac27d4 (diff) | |
download | llvm-156ab4d4fb06be93b0cfce675e4cf86d330d879c.zip llvm-156ab4d4fb06be93b0cfce675e4cf86d330d879c.tar.gz llvm-156ab4d4fb06be93b0cfce675e4cf86d330d879c.tar.bz2 |
[Clang][Sema] set declaration invalid earlier to prevent crash in calculating record layout (#87173)
Try to fix https://github.com/llvm/llvm-project/issues/75221
This crash caused by calculating record layout which contains a field
declaration with dependent type. Make it invalid before it is a complete
definition to prevent this crash. Define a new scope type to record this
type alias and set the record declaration invalid when it is defined in
a type alias template.
Co-authored-by: huqizhi <836744285@qq.com>
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 1bde99d..356abe0 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -19529,6 +19529,13 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, // Okay, we successfully defined 'Record'. if (Record) { bool Completed = false; + if (S) { + Scope *Parent = S->getParent(); + if (Parent && Parent->isTypeAliasScope() && + Parent->isTemplateParamScope()) + Record->setInvalidDecl(); + } + if (CXXRecord) { if (!CXXRecord->isInvalidDecl()) { // Set access bits correctly on the directly-declared conversions. |