[PATCH] D56651: [ASTImporter] Fix importing OperatorDelete from CXXConstructorDecl

Raphael Isemann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 13 14:07:17 PST 2019


teemperor created this revision.
teemperor added reviewers: shafik, martong, a_sidorin.
Herald added subscribers: cfe-commits, rnkovacs.
Herald added a reviewer: a.sidorin.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D56651

Files:
  lib/AST/ASTImporter.cpp
  test/Import/destructor/Inputs/F.cpp
  test/Import/destructor/test.cpp


Index: test/Import/destructor/test.cpp
===================================================================
--- /dev/null
+++ 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
Index: test/Import/destructor/Inputs/F.cpp
===================================================================
--- /dev/null
+++ test/Import/destructor/Inputs/F.cpp
@@ -0,0 +1,3 @@
+struct B {
+  virtual ~B() {}
+};
Index: lib/AST/ASTImporter.cpp
===================================================================
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -3238,7 +3238,25 @@
 }
 
 ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
-  return VisitCXXMethodDecl(D);
+  ExpectedDecl R = VisitCXXMethodDecl(D);
+
+  if (R) {
+    CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(*R);
+
+    auto Imp = importSeq(const_cast<FunctionDecl *>(D->getOperatorDelete()),
+                         D->getOperatorDeleteThisArg());
+
+    if (!Imp)
+      return Imp.takeError();
+
+    FunctionDecl *ToOperatorDelete;
+    Expr *ToThisArg;
+    std::tie(ToOperatorDelete, ToThisArg) = *Imp;
+
+    ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
+  }
+
+  return R;
 }
 
 ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56651.181472.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190113/3404576b/attachment.bin>


More information about the cfe-commits mailing list