Skip to content

Commit a3bad1a

Browse files
committed
[DebugInfo] Fix debug info round tripping of types inside functions
Types with @_originallyDefinedIn cannot be round tripped, Types declared inside functions have their mangling affected by the function signature. If the generic signature mentions an @_originallyDefinedIn type, the type inside the function cannot be round tripped either. This commit disables round tripping for this scenario.
1 parent e87c1c3 commit a3bad1a

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/AST/ASTMangler.h"
2626
#include "swift/AST/Attr.h"
2727
#include "swift/AST/Decl.h"
28+
#include "swift/AST/DeclContext.h"
2829
#include "swift/AST/Expr.h"
2930
#include "swift/AST/GenericEnvironment.h"
3031
#include "swift/AST/IRGenOptions.h"
@@ -34,6 +35,7 @@
3435
#include "swift/AST/Pattern.h"
3536
#include "swift/AST/TypeDifferenceVisitor.h"
3637
#include "swift/AST/TypeWalker.h"
38+
#include "swift/AST/Types.h"
3739
#include "swift/Basic/Assertions.h"
3840
#include "swift/Basic/Compiler.h"
3941
#include "swift/Basic/SourceManager.h"
@@ -65,6 +67,7 @@
6567
#include "llvm/IR/DebugInfo.h"
6668
#include "llvm/IR/IntrinsicInst.h"
6769
#include "llvm/IR/Module.h"
70+
#include "llvm/Support/Casting.h"
6871
#include "llvm/Support/CommandLine.h"
6972
#include "llvm/Support/Debug.h"
7073
#include "llvm/Support/FileSystem.h"
@@ -2343,11 +2346,16 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
23432346
if (visitedOriginallyDefinedIn)
23442347
return TypeWalker::Action::Stop;
23452348

2346-
// A typealias inside a function used that function's signature as part of
2349+
DeclContext *D = nullptr;
2350+
if (auto *TAT = llvm::dyn_cast<TypeAliasType>(T))
2351+
D = TAT->getDecl()->getDeclContext();
2352+
else if (auto *NT = llvm::dyn_cast<NominalOrBoundGenericNominalType>(T))
2353+
D = NT->getDecl()->getDeclContext();
2354+
2355+
// A type inside a function uses that function's signature as part of
23472356
// its mangling, so check if any types in the generic signature are
23482357
// annotated with @_originallyDefinedIn.
2349-
if (auto *TAT = llvm::dyn_cast<TypeAliasType>(T)) {
2350-
auto D = TAT->getDecl()->getDeclContext();
2358+
if (D) {
23512359
if (auto AFD = llvm::dyn_cast<AbstractFunctionDecl>(D)) {
23522360
OriginallyDefinedInFinder InnerWalker;
23532361
AFD->getInterfaceType().walk(InnerWalker);

test/DebugInfo/local_type_originally_defined_in.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ public func localTypeAliasTest(horse: Horse) {
2121
// CHECK: DIDerivedType(tag: DW_TAG_typedef, name: "$s32local_type_originally_defined_in0A13TypeAliasTest5horsey4Barn5HorseV_tF1AL_aD"
2222
}
2323

24+
25+
public func localTypeTest(horse: Horse) {
26+
// The local type mangling for 'A' mentions 'Horse', which must
27+
// be mangled using it's current module name, and not the
28+
// original module name, for consistency with the debug info
29+
// mangling.
30+
struct LocalStruct {}
31+
32+
let info = UnsafeMutablePointer<LocalStruct>.allocate(capacity: 1)
33+
_ = info
34+
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "$s32local_type_originally_defined_in0A8TypeTest5horsey4Barn5HorseV_tF11LocalStructL_VD"
35+
}
36+
2437
public func localTypeAliasTest() -> Horse {
2538
typealias B = Int
2639

0 commit comments

Comments
 (0)