[PATCH] D86624: [clang] Exclude invalid destructors from lookups.
Adam Czachorowski via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 26 07:46:25 PDT 2020
adamcz created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
adamcz requested review of this revision.
This fixes a crash when declaring a destructor with a wrong name, then
writing result to pch file and loading it again. The PCH storage uses
DeclarationNameKey as key and it is the same key for both the invalid
destructor and the implicit one that was created because the other one
was invalid. When querying for the Foo::~Foo we end up getting
Foo::~Bar, which is then rejected and we end up with nullptr in
CXXRecordDecl::GetDestructor().
Fixes https://bugs.llvm.org/show_bug.cgi?id=47270
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86624
Files:
clang/lib/AST/DeclBase.cpp
clang/test/PCH/cxx-invalid-destructor.cpp
clang/test/PCH/cxx-invalid-destructor.h
Index: clang/test/PCH/cxx-invalid-destructor.h
===================================================================
--- /dev/null
+++ clang/test/PCH/cxx-invalid-destructor.h
@@ -0,0 +1,14 @@
+class Base {
+public:
+ ~Base();
+};
+
+class Bar {
+public:
+ ~Bar();
+};
+
+class Foo : public Base {
+public:
+ ~Bar();
+};
Index: clang/test/PCH/cxx-invalid-destructor.cpp
===================================================================
--- /dev/null
+++ clang/test/PCH/cxx-invalid-destructor.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -x c++ -std=c++11 -emit-pch -o %t %S/cxx-invalid-destructor.h -fallow-pch-with-compiler-errors
+// RUN: %clang_cc1 -x c++ -std=c++11 -include-pch %t %S/cxx-invalid-destructor.cpp -fsyntax-only -fno-validate-pch
+
+Foo f;
Index: clang/lib/AST/DeclBase.cpp
===================================================================
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1486,6 +1486,8 @@
if (auto *FD = dyn_cast<FunctionDecl>(D))
if (FD->isFunctionTemplateSpecialization())
return true;
+ if (isa<CXXDestructorDecl>(D) && D->isInvalidDecl())
+ return true;
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86624.287973.patch
Type: text/x-patch
Size: 1151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200826/537bc7b0/attachment.bin>
More information about the cfe-commits
mailing list