mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
3
test/Interop/Cxx/class/Inputs/debug-info.h
Normal file
3
test/Interop/Cxx/class/Inputs/debug-info.h
Normal file
@@ -0,0 +1,3 @@
|
||||
struct IntWrapper {
|
||||
int value;
|
||||
};
|
||||
@@ -25,3 +25,7 @@ module ProtocolConformance {
|
||||
module SynthesizedInitializers {
|
||||
header "synthesized-initializers.h"
|
||||
}
|
||||
|
||||
module DebugInfo {
|
||||
header "debug-info.h"
|
||||
}
|
||||
|
||||
19
test/Interop/Cxx/class/debug-info-irgen.swift
Normal file
19
test/Interop/Cxx/class/debug-info-irgen.swift
Normal 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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user