diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-01-22 17:59:45 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-01-22 17:59:45 +0000 |
commit | 1c5d23f1405994da05697b3b66c9f5a32735fdc3 (patch) | |
tree | 647eda30b7be74ffef59603447dceb063f39d869 | |
parent | 922b54064312d158f61e0875f92054ac705ebd3e (diff) | |
download | bcm5719-llvm-1c5d23f1405994da05697b3b66c9f5a32735fdc3.tar.gz bcm5719-llvm-1c5d23f1405994da05697b3b66c9f5a32735fdc3.zip |
[ASTImporter] Fix importing OperatorDelete from CXXConstructorDecl
Summary:
Shafik found out that importing a CXXConstructorDecl will create a translation unit that
causes Clang's CodeGen to crash. The reason for that is that we don't copy the OperatorDelete
from the CXXConstructorDecl when importing. This patch fixes it and adds a test case for that.
Reviewers: shafik, martong, a_sidorin, a.sidorin
Reviewed By: martong, a_sidorin
Subscribers: rnkovacs, cfe-commits
Differential Revision: https://reviews.llvm.org/D56651
llvm-svn: 351849
-rw-r--r-- | clang/lib/AST/ASTImporter.cpp | 18 | ||||
-rw-r--r-- | clang/test/Import/destructor/Inputs/F.cpp | 3 | ||||
-rw-r--r-- | clang/test/Import/destructor/test.cpp | 10 |
3 files changed, 30 insertions, 1 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 6c245991031..f24a5698f58 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3091,12 +3091,28 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { FromConstructor->isExplicit(), D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) return ToFunction; - } else if (isa<CXXDestructorDecl>(D)) { + } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { + + auto Imp = + importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), + FromDtor->getOperatorDeleteThisArg()); + + if (!Imp) + return Imp.takeError(); + + FunctionDecl *ToOperatorDelete; + Expr *ToThisArg; + std::tie(ToOperatorDelete, ToThisArg) = *Imp; + if (GetImportedOrCreateDecl<CXXDestructorDecl>( ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), D->isImplicit())) return ToFunction; + + CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); + + ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); } else if (CXXConversionDecl *FromConversion = dyn_cast<CXXConversionDecl>(D)) { if (GetImportedOrCreateDecl<CXXConversionDecl>( diff --git a/clang/test/Import/destructor/Inputs/F.cpp b/clang/test/Import/destructor/Inputs/F.cpp new file mode 100644 index 00000000000..c33c45399d4 --- /dev/null +++ b/clang/test/Import/destructor/Inputs/F.cpp @@ -0,0 +1,3 @@ +struct B { + virtual ~B() {} +}; diff --git a/clang/test/Import/destructor/test.cpp b/clang/test/Import/destructor/test.cpp new file mode 100644 index 00000000000..bfdee398c86 --- /dev/null +++ b/clang/test/Import/destructor/test.cpp @@ -0,0 +1,10 @@ +// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s + +// Triggers the deserialization of B's destructor. +B b1; + +// CHECK: CXXDestructorDecl + +// CHECK-NEXT: ~B 'void () noexcept' virtual +// CHECK-SAME: 'void () noexcept' +// CHECK-SAME: virtual |