diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-12-01 23:18:25 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-12-01 23:18:25 +0000 |
commit | 6bc9768408d4b45e00350018b6e3540bc05d267d (patch) | |
tree | 398e9f5f468f660922b527b95e0ff5e363ef312c | |
parent | fbcc7bed1a0661ecc91b62e0696b8310887713f6 (diff) |
Fix a code gen. crash synthesizing a destructor.
Fixes pr5660.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90283 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/Sema.h | 5 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 5 | ||||
-rw-r--r-- | test/CodeGenCXX/virtual-destructor-synthesis.cpp | 16 |
4 files changed, 26 insertions, 5 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 4b437995f1..3f8babbbbe 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1933,7 +1933,8 @@ public: QualType Argument); bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, - DeclarationName Name, FunctionDecl* &Operator); + DeclarationName Name, FunctionDecl* &Operator, + bool Diagnose=true); /// ActOnCXXDelete - Parsed a C++ 'delete' expression virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc, @@ -2160,7 +2161,7 @@ public: void CheckConstructor(CXXConstructorDecl *Constructor); QualType CheckDestructorDeclarator(Declarator &D, FunctionDecl::StorageClass& SC); - bool CheckDestructor(CXXDestructorDecl *Destructor); + bool CheckDestructor(CXXDestructorDecl *Destructor, bool Diagnose=true); void CheckConversionDeclarator(Declarator &D, QualType &R, FunctionDecl::StorageClass& SC); DeclPtrTy ActOnConversionDeclarator(CXXConversionDecl *Conversion); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index df27679a5a..3dad051a4e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2171,6 +2171,7 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) { ClassDecl->addDecl(Destructor); AddOverriddenMethods(ClassDecl, Destructor); + CheckDestructor(Destructor, false); } } @@ -2369,7 +2370,7 @@ void Sema::CheckConstructor(CXXConstructorDecl *Constructor) { /// CheckDestructor - Checks a fully-formed destructor for well-formedness, /// issuing any diagnostics required. Returns true on error. -bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) { +bool Sema::CheckDestructor(CXXDestructorDecl *Destructor, bool Diagnose) { CXXRecordDecl *RD = Destructor->getParent(); if (Destructor->isVirtual()) { @@ -2384,7 +2385,7 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) { FunctionDecl *OperatorDelete = 0; DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Delete); - if (FindDeallocationFunction(Loc, RD, Name, OperatorDelete)) + if (FindDeallocationFunction(Loc, RD, Name, OperatorDelete, Diagnose)) return true; Destructor->setOperatorDelete(OperatorDelete); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 00fb65df92..e626aff38b 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -776,7 +776,8 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, DeclarationName Name, - FunctionDecl* &Operator) { + FunctionDecl* &Operator, + bool Diagnose) { LookupResult Found(*this, Name, StartLoc, LookupOrdinaryName); // Try to find operator delete/operator delete[] in class scope. LookupQualifiedName(Found, RD); @@ -796,6 +797,8 @@ bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, // We did find operator delete/operator delete[] declarations, but // none of them were suitable. if (!Found.empty()) { + if (!Diagnose) + return true; Diag(StartLoc, diag::err_no_suitable_delete_member_function_found) << Name << RD; diff --git a/test/CodeGenCXX/virtual-destructor-synthesis.cpp b/test/CodeGenCXX/virtual-destructor-synthesis.cpp new file mode 100644 index 0000000000..b95218a322 --- /dev/null +++ b/test/CodeGenCXX/virtual-destructor-synthesis.cpp @@ -0,0 +1,16 @@ +// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s + +struct box { + virtual ~box(); +}; + +struct pile_box : public box { + pile_box(box *); +}; + +pile_box::pile_box(box *pp) +{ +} + +// CHECK: call void @_ZdlPv + |