[cxx-interop] Temporarily disable emitting debug info for C++ types.

When we try to emit debug info from C++ types we crash because we can't deserialize them. This is a temporary fix to circumnavigate the crash before a real fix can be created.
This commit is contained in:
zoecarver
2020-07-08 11:44:53 -07:00
parent 61cb9a5f4f
commit 5c3ccf5050
5 changed files with 56 additions and 0 deletions

View File

@@ -1586,6 +1586,13 @@ private:
/// 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<clang::CXXRecordDecl>(
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<MetatypeType>(ty))
ty = metaTy->getInstanceType().getPointer();
if (ty->getStructOrBoundGenericStruct() &&
ty->getStructOrBoundGenericStruct()->getClangDecl() &&
isa<clang::CXXRecordDecl>(
ty->getStructOrBoundGenericStruct()->getClangDecl()))
return;
}
llvm::DIType *DITy = getOrCreateType(DbgTy);
VarDecl *VD = nullptr;
if (Loc)

View File

@@ -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 @@ public:
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<MetatypeType>(ty))
ty = metaTy->getRootClass().getPointer();
if (ty->getStructOrBoundGenericStruct() &&
ty->getStructOrBoundGenericStruct()->getClangDecl() &&
isa<clang::CXXRecordDecl>(
ty->getStructOrBoundGenericStruct()->getClangDecl()))
return;
}
assert(IGM.DebugInfo && "debug info not enabled");
if (VarInfo.ArgNo) {
PrologueLocation AutoRestore(IGM.DebugInfo.get(), Builder);

View File

@@ -0,0 +1,3 @@
struct IntWrapper {
int value;
};

View File

@@ -25,3 +25,7 @@ module ProtocolConformance {
module SynthesizedInitializers {
header "synthesized-initializers.h"
}
module DebugInfo {
header "debug-info.h"
}

View File

@@ -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())
}