Skip to content

Commit 5c3ccf5

Browse files
committed
[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.
1 parent 61cb9a5 commit 5c3ccf5

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15861586

15871587
/// Determine if there exists a name mangling for the given type.
15881588
static bool canMangle(TypeBase *Ty) {
1589+
// TODO: C++ types are not yet supported (SR-13223).
1590+
if (Ty->getStructOrBoundGenericStruct() &&
1591+
Ty->getStructOrBoundGenericStruct()->getClangDecl() &&
1592+
isa<clang::CXXRecordDecl>(
1593+
Ty->getStructOrBoundGenericStruct()->getClangDecl()))
1594+
return false;
1595+
15891596
switch (Ty->getKind()) {
15901597
case TypeKind::GenericFunction: // Not yet supported.
15911598
case TypeKind::SILBlockStorage: // Not supported at all.
@@ -2378,6 +2385,17 @@ void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
23782385
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::LineTables)
23792386
return;
23802387

2388+
// TODO: fix demangling for C++ types (SR-13223).
2389+
if (swift::TypeBase *ty = DbgTy.getType()) {
2390+
if (MetatypeType *metaTy = dyn_cast<MetatypeType>(ty))
2391+
ty = metaTy->getInstanceType().getPointer();
2392+
if (ty->getStructOrBoundGenericStruct() &&
2393+
ty->getStructOrBoundGenericStruct()->getClangDecl() &&
2394+
isa<clang::CXXRecordDecl>(
2395+
ty->getStructOrBoundGenericStruct()->getClangDecl()))
2396+
return;
2397+
}
2398+
23812399
llvm::DIType *DITy = getOrCreateType(DbgTy);
23822400
VarDecl *VD = nullptr;
23832401
if (Loc)

lib/IRGen/IRGenSIL.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "swift/SIL/SILType.h"
3838
#include "swift/SIL/SILVisitor.h"
3939
#include "clang/AST/ASTContext.h"
40+
#include "clang/AST/DeclCXX.h"
4041
#include "clang/Basic/TargetInfo.h"
4142
#include "clang/CodeGen/CodeGenABITypes.h"
4243
#include "llvm/ADT/MapVector.h"
@@ -817,6 +818,17 @@ class IRGenSILFunction :
817818
SILType SILTy, const SILDebugScope *DS,
818819
VarDecl *VarDecl, SILDebugVariable VarInfo,
819820
IndirectionKind Indirection = DirectValue) {
821+
// TODO: fix demangling for C++ types (SR-13223).
822+
if (swift::TypeBase *ty = SILTy.getASTType().getPointer()) {
823+
if (MetatypeType *metaTy = dyn_cast<MetatypeType>(ty))
824+
ty = metaTy->getRootClass().getPointer();
825+
if (ty->getStructOrBoundGenericStruct() &&
826+
ty->getStructOrBoundGenericStruct()->getClangDecl() &&
827+
isa<clang::CXXRecordDecl>(
828+
ty->getStructOrBoundGenericStruct()->getClangDecl()))
829+
return;
830+
}
831+
820832
assert(IGM.DebugInfo && "debug info not enabled");
821833
if (VarInfo.ArgNo) {
822834
PrologueLocation AutoRestore(IGM.DebugInfo.get(), Builder);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct IntWrapper {
2+
int value;
3+
};

test/Interop/Cxx/class/Inputs/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ module ProtocolConformance {
2525
module SynthesizedInitializers {
2626
header "synthesized-initializers.h"
2727
}
28+
29+
module DebugInfo {
30+
header "debug-info.h"
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -enable-cxx-interop -I %S/Inputs %s -emit-ir -g | %FileCheck %s
2+
3+
// Validate that we don't crash when trying to deserialize C++ type debug info.
4+
// Note, however, that the actual debug info is not generated, see SR-13223.
5+
6+
import DebugInfo
7+
8+
public func create(_ x: Int32) -> IntWrapper { IntWrapper(value: x) }
9+
10+
public func getInt() -> Int32 { 0 }
11+
12+
// CHECK-LABEL: define {{.*}}void @"$s4main4testyyF"
13+
// CHECK: [[I:%.*]] = call swiftcc i32 @"$s4main6getInts5Int32VyF"()
14+
// CHECK: call swiftcc i32 @"$s4main6createySo10IntWrapperVs5Int32VF"(i32 [[I]])
15+
// CHECK: ret void
16+
public func test() {
17+
let f = create(getInt())
18+
}
19+

0 commit comments

Comments
 (0)