|
32 | 32 | #include "swift/AST/GenericEnvironment.h" |
33 | 33 | #include "swift/AST/PrettyStackTrace.h" |
34 | 34 | #include "swift/AST/SwiftNameTranslation.h" |
| 35 | +#include "swift/AST/Type.h" |
35 | 36 | #include "swift/AST/TypeCheckRequests.h" |
36 | 37 | #include "swift/AST/TypeVisitor.h" |
37 | 38 | #include "swift/AST/Types.h" |
|
45 | 46 | #include "clang/AST/ASTContext.h" |
46 | 47 | #include "clang/AST/Attr.h" |
47 | 48 | #include "clang/AST/Decl.h" |
| 49 | +#include "clang/AST/DeclCXX.h" |
48 | 50 | #include "clang/AST/DeclObjC.h" |
49 | 51 | #include "clang/Basic/CharInfo.h" |
50 | 52 | #include "clang/Basic/SourceManager.h" |
@@ -475,6 +477,17 @@ class DeclAndTypePrinter::Implementation |
475 | 477 | os << "@end\n"; |
476 | 478 | } |
477 | 479 |
|
| 480 | + static bool isClangPOD(const NominalTypeDecl *ntd) { |
| 481 | + auto clangDecl = ntd->getClangDecl(); |
| 482 | + if (!clangDecl) |
| 483 | + return false; |
| 484 | + if (const auto *rd = dyn_cast<clang::RecordDecl>(clangDecl)) { |
| 485 | + return !isa<clang::CXXRecordDecl>(rd) || |
| 486 | + cast<clang::CXXRecordDecl>(rd)->isPOD(); |
| 487 | + } |
| 488 | + return false; |
| 489 | + } |
| 490 | + |
478 | 491 | void visitEnumDeclCxx(EnumDecl *ED) { |
479 | 492 | assert(owningPrinter.outputLang == OutputLanguageMode::Cxx); |
480 | 493 |
|
@@ -588,7 +601,9 @@ class DeclAndTypePrinter::Implementation |
588 | 601 | assert(objectTypeDecl != nullptr || paramType->isOptional()); |
589 | 602 |
|
590 | 603 | if (objectTypeDecl && |
591 | | - owningPrinter.typeMapping.getKnownCxxTypeInfo(objectTypeDecl)) { |
| 604 | + (owningPrinter.typeMapping.getKnownCxxTypeInfo( |
| 605 | + objectTypeDecl) || |
| 606 | + isClangPOD(objectTypeDecl))) { |
592 | 607 | outOfLineOS << " " << types[paramType] << " result;\n"; |
593 | 608 | outOfLineOS << " " |
594 | 609 | "memcpy(&result, payloadFromDestruction, " |
@@ -755,8 +770,9 @@ class DeclAndTypePrinter::Implementation |
755 | 770 | assert(objectTypeDecl != nullptr || paramType->isOptional()); |
756 | 771 |
|
757 | 772 | if (objectTypeDecl && |
758 | | - owningPrinter.typeMapping.getKnownCxxTypeInfo( |
759 | | - objectTypeDecl)) { |
| 773 | + (owningPrinter.typeMapping.getKnownCxxTypeInfo( |
| 774 | + objectTypeDecl) || |
| 775 | + isClangPOD(objectTypeDecl))) { |
760 | 776 | outOfLineOS |
761 | 777 | << " memcpy(result._getOpaquePointer(), &val, " |
762 | 778 | "sizeof(val));\n"; |
|
0 commit comments