Skip to content

Commit 96cc406

Browse files
committed
Debug Info: Ensure classes report their storage size correctly
by wrapping them in a pointer-sized struct as we do for all things passed by reference. Fixes rdar://21409965 Swift SVN r29455
1 parent 4613548 commit 96cc406

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,17 +1534,14 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
15341534
auto *ClassTy = BaseTy->castTo<ClassType>();
15351535
auto *Decl = ClassTy->getDecl();
15361536
Location L = getLoc(SM, Decl);
1537-
// TODO: We may want to peek at Decl->isObjC() and set this
1538-
// attribute accordingly.
1539-
auto RuntimeLang = llvm::dwarf::DW_LANG_Swift;
15401537
if (auto *ClangDecl = Decl->getClangDecl()) {
15411538
auto ClangSrcLoc = ClangDecl->getLocStart();
15421539
clang::SourceManager &ClangSM =
15431540
CI.getClangASTContext().getSourceManager();
15441541
L.Line = ClangSM.getPresumedLineNumber(ClangSrcLoc);
15451542
L.Filename = ClangSM.getBufferName(ClangSrcLoc);
15461543

1547-
// Use "ObjectiveC" as default for implicit decls.
1544+
// Use "ObjectiveC" as default for implicit decls.
15481545
// FIXME 1: Do something more clever based on the decl's mangled name.
15491546
// FIXME 2: Clang submodules are not handled here.
15501547
StringRef ModuleName = "ObjectiveC";
@@ -1555,11 +1552,9 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
15551552
// This placeholder gets RAUW'd by finalize().
15561553
Scope = getOrCreateModule(ModuleFile, ModuleName, ModuleFile);
15571554
}
1558-
return createStructType(DbgTy, Decl, ClassTy, Scope,
1559-
getOrCreateFile(L.Filename), L.Line, SizeInBits,
1560-
AlignInBits, Flags,
1561-
nullptr, // DerivedFrom
1562-
RuntimeLang, MangledName);
1555+
return createPointerSizedStruct(Scope, Decl->getNameStr(),
1556+
getOrCreateFile(L.Filename), L.Line, Flags,
1557+
MangledName);
15631558
}
15641559

15651560
case TypeKind::Protocol: {

test/DebugInfo/structs.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -o - | FileCheck %s
2-
3-
// This is more of a crash test than anything else.
2+
// Capture the pointer size from type Int
3+
// CHECK: %Si = type <{ i[[PTRSIZE:[0-9]+]] }>
44

55
struct A {
66
var fn : () -> ()
@@ -9,8 +9,22 @@ struct A {
99
func test(var x : A) {}
1010
// CHECK: define hidden void @_TF7structs4test
1111
// CHECK: [[X:%.*]] = alloca [[A:%.*]], align {{(4|8)}}
12-
// CHECK-NEXT: call void @llvm.dbg.declare(metadata [[A]]* [[X]], metadata [[X_DBG:!.*]], metadata !{{[0-9]+}})
12+
// CHECK-NEXT: call void @llvm.dbg.declare(metadata [[A]]* [[X]],
13+
// CHECK-SAME: metadata [[X_DBG:!.*]], metadata
1314
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A"
1415
// CHECK-SAME: identifier: [[A_DI:"[^"]+"]]
16+
17+
class C {
18+
var lots_of_extra_storage: (Int, Int, Int) = (1, 2, 3)
19+
var member: C = C()
20+
}
21+
22+
// A class is represented by a pointer, so B's total size should be PTRSIZE.
23+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "B",
24+
// CHECK-SAME: {{.*}}size: [[PTRSIZE]]
25+
struct B {
26+
var c : C
27+
}
28+
1529
// CHECK: [[X_DBG]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "x",
16-
// CHECK-SAME: type: ![[A_DI]]
30+
// CHECK-SAME: type: ![[A_DI]]

test/DebugInfo/test-foundation.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,14 @@ class MyObject : NSObject {
3636
// LOC-CHECK: ret {{.*}}, !dbg ![[DBG:.*]]
3737
// LOC-CHECK: ret
3838
var MyArr = NSArray()
39-
// Capture the pointer size from type Int
40-
// IMPORT-CHECK: %Si = type <{ i[[PTRSIZE:[0-9]+]] }>
4139
// IMPORT-CHECK: filename: "test-foundation.swift"
4240
// IMPORT-CHECK: !MDModule(name: "ObjectiveC"
43-
// IMPORT-CHECK: !DIDerivedType(tag: DW_TAG_member, name: "MyArr",
44-
// IMPORT-CHECK-NOT: line:
45-
// IMPORT-CHECK-SAME: baseType: ![[NSARRAY:"[^"]+"]]
46-
// IMPORT-CHECK-SAME: size: [[PTRSIZE]], align: [[PTRSIZE]]
47-
// IMPORT-CHECK-NOT: offset: 0
48-
// IMPORT-CHECK-SAME: ){{$}}
49-
// IMPORT-CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "NSArray", scope: ![[FOUNDATION:[0-9]+]]
50-
// IMPORT-CHECK-SAME: identifier: [[NSARRAY]]
51-
// IMPORT-CHECK: [[FOUNDATION]] = !MDModule(name: "Foundation",{{.*}} file: ![[FOUNDATION_FILE:[0-9]+]]
41+
// IMPORT-CHECK: [[FOUNDATION:[0-9]+]] = !MDModule(name: "Foundation",
42+
// IMPORT-CHECK-SAME: {{.*}}file: ![[FOUNDATION_FILE:[0-9]+]]
5243
// IMPORT-CHECK: ![[FOUNDATION_FILE]] = !DIFile(filename: "Foundation-{{.*}}.pcm"
53-
// IMPORT-CHECK: !DIImportedEntity(tag: DW_TAG_imported_module,{{.*}} entity: ![[FOUNDATION]]
54-
44+
// IMPORT-CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "NSArray",
45+
// IMPORT-CHECK-SAME: scope: ![[FOUNDATION]]
46+
// IMPORT-CHECK: !DIImportedEntity(tag: DW_TAG_imported_module, {{.*}}entity: ![[FOUNDATION]]
5547

5648
// Force the use of Int.
5749
var count : Int = 0

0 commit comments

Comments
 (0)