diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index b15fb6a69a6a1..d0c1850f98ee9 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -1586,6 +1586,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { /// Determine if there exists a name mangling for the given type. static bool canMangle(TypeBase *Ty) { + // TODO: C++ types are not yet supported (SR-13223). + if (Ty->getStructOrBoundGenericStruct() && + Ty->getStructOrBoundGenericStruct()->getClangDecl() && + isa( + Ty->getStructOrBoundGenericStruct()->getClangDecl())) + return false; + switch (Ty->getKind()) { case TypeKind::GenericFunction: // Not yet supported. case TypeKind::SILBlockStorage: // Not supported at all. @@ -2378,6 +2385,17 @@ void IRGenDebugInfoImpl::emitGlobalVariableDeclaration( if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::LineTables) return; + // TODO: fix demangling for C++ types (SR-13223). + if (swift::TypeBase *ty = DbgTy.getType()) { + if (MetatypeType *metaTy = dyn_cast(ty)) + ty = metaTy->getInstanceType().getPointer(); + if (ty->getStructOrBoundGenericStruct() && + ty->getStructOrBoundGenericStruct()->getClangDecl() && + isa( + ty->getStructOrBoundGenericStruct()->getClangDecl())) + return; + } + llvm::DIType *DITy = getOrCreateType(DbgTy); VarDecl *VD = nullptr; if (Loc) diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index ad2d0dfc79c44..8c0562c7df300 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -37,6 +37,7 @@ #include "swift/SIL/SILType.h" #include "swift/SIL/SILVisitor.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/DeclCXX.h" #include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/CodeGenABITypes.h" #include "llvm/ADT/MapVector.h" @@ -817,6 +818,17 @@ class IRGenSILFunction : SILType SILTy, const SILDebugScope *DS, VarDecl *VarDecl, SILDebugVariable VarInfo, IndirectionKind Indirection = DirectValue) { + // TODO: fix demangling for C++ types (SR-13223). + if (swift::TypeBase *ty = SILTy.getASTType().getPointer()) { + if (MetatypeType *metaTy = dyn_cast(ty)) + ty = metaTy->getRootClass().getPointer(); + if (ty->getStructOrBoundGenericStruct() && + ty->getStructOrBoundGenericStruct()->getClangDecl() && + isa( + ty->getStructOrBoundGenericStruct()->getClangDecl())) + return; + } + assert(IGM.DebugInfo && "debug info not enabled"); if (VarInfo.ArgNo) { PrologueLocation AutoRestore(IGM.DebugInfo.get(), Builder); diff --git a/test/Interop/Cxx/class/Inputs/debug-info.h b/test/Interop/Cxx/class/Inputs/debug-info.h new file mode 100644 index 0000000000000..9cee158dd9b4a --- /dev/null +++ b/test/Interop/Cxx/class/Inputs/debug-info.h @@ -0,0 +1,3 @@ +struct IntWrapper { + int value; +}; diff --git a/test/Interop/Cxx/class/Inputs/module.modulemap b/test/Interop/Cxx/class/Inputs/module.modulemap index 24cde705fcde9..04c3bdedfda87 100644 --- a/test/Interop/Cxx/class/Inputs/module.modulemap +++ b/test/Interop/Cxx/class/Inputs/module.modulemap @@ -25,3 +25,7 @@ module ProtocolConformance { module SynthesizedInitializers { header "synthesized-initializers.h" } + +module DebugInfo { + header "debug-info.h" +} diff --git a/test/Interop/Cxx/class/debug-info-irgen.swift b/test/Interop/Cxx/class/debug-info-irgen.swift new file mode 100644 index 0000000000000..cb5332701725d --- /dev/null +++ b/test/Interop/Cxx/class/debug-info-irgen.swift @@ -0,0 +1,19 @@ +// RUN: %target-swift-frontend -enable-cxx-interop -I %S/Inputs %s -emit-ir -g | %FileCheck %s + +// Validate that we don't crash when trying to deserialize C++ type debug info. +// Note, however, that the actual debug info is not generated, see SR-13223. + +import DebugInfo + +public func create(_ x: Int32) -> IntWrapper { IntWrapper(value: x) } + +public func getInt() -> Int32 { 0 } + +// CHECK-LABEL: define {{.*}}void @"$s4main4testyyF" +// CHECK: [[I:%.*]] = call swiftcc i32 @"$s4main6getInts5Int32VyF"() +// CHECK: call swiftcc i32 @"$s4main6createySo10IntWrapperVs5Int32VF"(i32 [[I]]) +// CHECK: ret void +public func test() { + let f = create(getInt()) +} +