r351849 - [ASTImporter] Fix importing OperatorDelete from CXXConstructorDecl

Raphael Isemann via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 22 09:59:45 PST 2019


Author: teemperor
Date: Tue Jan 22 09:59:45 2019
New Revision: 351849

URL: http://llvm.org/viewvc/llvm-project?rev=351849&view=rev
Log:
[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

Added:
    cfe/trunk/test/Import/destructor/
    cfe/trunk/test/Import/destructor/Inputs/
    cfe/trunk/test/Import/destructor/Inputs/F.cpp
    cfe/trunk/test/Import/destructor/test.cpp
Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=351849&r1=351848&r2=351849&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jan 22 09:59:45 2019
@@ -3091,12 +3091,28 @@ ExpectedDecl ASTNodeImporter::VisitFunct
         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>(

Added: cfe/trunk/test/Import/destructor/Inputs/F.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/destructor/Inputs/F.cpp?rev=351849&view=auto
==============================================================================
--- cfe/trunk/test/Import/destructor/Inputs/F.cpp (added)
+++ cfe/trunk/test/Import/destructor/Inputs/F.cpp Tue Jan 22 09:59:45 2019
@@ -0,0 +1,3 @@
+struct B {
+  virtual ~B() {}
+};

Added: cfe/trunk/test/Import/destructor/test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/destructor/test.cpp?rev=351849&view=auto
==============================================================================
--- cfe/trunk/test/Import/destructor/test.cpp (added)
+++ cfe/trunk/test/Import/destructor/test.cpp Tue Jan 22 09:59:45 2019
@@ -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




More information about the cfe-commits mailing list