Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::CXXRecordDecl>(
Ty->getStructOrBoundGenericStruct()->getClangDecl()))
return false;

switch (Ty->getKind()) {
case TypeKind::GenericFunction: // Not yet supported.
case TypeKind::SILBlockStorage: // Not supported at all.
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<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);
Expand Down
3 changes: 3 additions & 0 deletions test/Interop/Cxx/class/Inputs/debug-info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct IntWrapper {
int value;
};
4 changes: 4 additions & 0 deletions test/Interop/Cxx/class/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ module ProtocolConformance {
module SynthesizedInitializers {
header "synthesized-initializers.h"
}

module DebugInfo {
header "debug-info.h"
}
19 changes: 19 additions & 0 deletions test/Interop/Cxx/class/debug-info-irgen.swift
Original file line number Diff line number Diff line change
@@ -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())
}