llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Vlad Serebrennikov (Endilll) <details> <summary>Changes</summary> Fixes #<!-- -->10518 Fixes #<!-- -->67914 Fixes #<!-- -->78388 Also addresses the second example in #<!-- -->49103 This patch is based on suggestion from @<!-- -->cor3ntin in https://github.com/llvm/llvm-project/issues/67914#issuecomment-1896011898 --- Full diff: https://github.com/llvm/llvm-project/pull/78898.diff 2 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+5) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+7) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8bb26fcae18d6b..5971bda21a5e25 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1013,6 +1013,11 @@ Bug Fixes to C++ Support - Fix a false-positive ODR violation for different definitions for `std::align_val_t`. Fixes (`#76638 <https://github.com/llvm/llvm-project/issues/76638>`_) +- Fix crash when calling the constructor of an invalid class. + Fixes (`#10518 <https://github.com/llvm/llvm-project/issues/10518>`_), + (`#67914 <https://github.com/llvm/llvm-project/issues/10518>`_), + and (`#78388 <https://github.com/llvm/llvm-project/issues/78388>`_) + - Remove recorded `#pragma once` state for headers included in named modules. Fixes (`#77995 <https://github.com/llvm/llvm-project/issues/77995>`_) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index df5bd55e7c2836..634af573480b45 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -5990,6 +5990,10 @@ void Sema::ActOnDefaultCtorInitializers(Decl *CDtorDecl) { if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(CDtorDecl)) { + if (CXXRecordDecl *ClassDecl = Constructor->getParent(); + !ClassDecl || ClassDecl->isInvalidDecl()) { + return; + } SetCtorInitializers(Constructor, /*AnyErrors=*/false); DiagnoseUninitializedFields(*this, Constructor); } @@ -14030,6 +14034,9 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, CXXRecordDecl *ClassDecl = Constructor->getParent(); assert(ClassDecl && "DefineImplicitDefaultConstructor - invalid constructor"); + if (ClassDecl->isInvalidDecl()) { + return; + } SynthesizedFunctionScope Scope(*this, Constructor); `````````` </details> https://github.com/llvm/llvm-project/pull/78898 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits