]> granicus.if.org Git - clang/commitdiff
[ASTImporter] Fix importing OperatorDelete from CXXConstructorDecl
authorRaphael Isemann <teemperor@gmail.com>
Tue, 22 Jan 2019 17:59:45 +0000 (17:59 +0000)
committerRaphael Isemann <teemperor@gmail.com>
Tue, 22 Jan 2019 17:59:45 +0000 (17:59 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351849 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTImporter.cpp
test/Import/destructor/Inputs/F.cpp [new file with mode: 0644]
test/Import/destructor/test.cpp [new file with mode: 0644]

index 6c245991031f643c782a15e1555d0d38fe0da9f3..f24a5698f583c32570adf92ba1ce90eec70557e0 100644 (file)
@@ -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/test/Import/destructor/Inputs/F.cpp b/test/Import/destructor/Inputs/F.cpp
new file mode 100644 (file)
index 0000000..c33c453
--- /dev/null
@@ -0,0 +1,3 @@
+struct B {
+  virtual ~B() {}
+};
diff --git a/test/Import/destructor/test.cpp b/test/Import/destructor/test.cpp
new file mode 100644 (file)
index 0000000..bfdee39
--- /dev/null
@@ -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