-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Generate full debug info for special builtins and classes #71332
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
//===----------------------------------------------------------------------===// | ||
|
||
#include "IRGenDebugInfo.h" | ||
#include "GenEnum.h" | ||
#include "GenOpaque.h" | ||
#include "GenStruct.h" | ||
#include "GenType.h" | ||
|
@@ -1078,8 +1079,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |
llvm::dwarf::DW_TAG_structure_type, UniqueID, Scope, File, Line, | ||
llvm::dwarf::DW_LANG_Swift, SizeInBits, 0); | ||
} | ||
if (OffsetInBits > SizeInBits) | ||
SizeInBits = OffsetInBits; | ||
|
||
auto DITy = DBuilder.createStructType( | ||
Scope, Name, File, Line, SizeInBits, AlignInBits, Flags, DerivedFrom, | ||
|
@@ -1525,7 +1524,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |
? 0 | ||
: DbgTy.getAlignment().getValue() * SizeOfByte; | ||
unsigned Encoding = 0; | ||
uint32_t NumExtraInhabitants = 0; | ||
uint32_t NumExtraInhabitants = DbgTy.getNumExtraInhabitants().value_or(0); | ||
|
||
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero; | ||
|
||
TypeBase *BaseTy = DbgTy.getType(); | ||
|
@@ -1549,17 +1549,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |
Encoding = llvm::dwarf::DW_ATE_unsigned; | ||
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get(DbgTy)) | ||
SizeInBits = getSizeOfBasicType(*CompletedDbgTy); | ||
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants()) | ||
NumExtraInhabitants = *DbgTyNumExtraInhabitants; | ||
break; | ||
} | ||
|
||
case TypeKind::BuiltinIntegerLiteral: { | ||
Encoding = llvm::dwarf::DW_ATE_unsigned; // ? | ||
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get(DbgTy)) | ||
SizeInBits = getSizeOfBasicType(*CompletedDbgTy); | ||
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants()) | ||
NumExtraInhabitants = *DbgTyNumExtraInhabitants; | ||
break; | ||
} | ||
|
||
|
@@ -1568,48 +1564,30 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |
// Assuming that the bitwidth and FloatTy->getFPKind() are identical. | ||
SizeInBits = FloatTy->getBitWidth(); | ||
Encoding = llvm::dwarf::DW_ATE_float; | ||
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants()) | ||
NumExtraInhabitants = *DbgTyNumExtraInhabitants; | ||
break; | ||
} | ||
|
||
case TypeKind::BuiltinNativeObject: { | ||
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(clang::LangAS::Default); | ||
auto PTy = DBuilder.createPointerType(nullptr, PtrSize, 0, | ||
/* DWARFAddressSpace */ llvm::None, | ||
MangledName); | ||
return DBuilder.createObjectPointerType(PTy); | ||
} | ||
|
||
case TypeKind::BuiltinBridgeObject: { | ||
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(clang::LangAS::Default); | ||
auto PTy = DBuilder.createPointerType(nullptr, PtrSize, 0, | ||
/* DWARFAddressSpace */ llvm::None, | ||
MangledName); | ||
return DBuilder.createObjectPointerType(PTy); | ||
} | ||
|
||
case TypeKind::BuiltinRawPointer: { | ||
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(clang::LangAS::Default); | ||
return DBuilder.createPointerType(nullptr, PtrSize, 0, | ||
/* DWARFAddressSpace */ llvm::None, | ||
MangledName); | ||
} | ||
case TypeKind::BuiltinNativeObject: | ||
case TypeKind::BuiltinBridgeObject: | ||
case TypeKind::BuiltinRawPointer: | ||
case TypeKind::BuiltinRawUnsafeContinuation: | ||
case TypeKind::BuiltinJob: { | ||
unsigned PtrSize = | ||
CI.getTargetInfo().getPointerWidth(clang::LangAS::Default); | ||
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) { | ||
Flags |= llvm::DINode::FlagArtificial; | ||
llvm::DICompositeType *PTy = DBuilder.createStructType( | ||
Scope, MangledName, File, 0, PtrSize, 0, Flags, nullptr, nullptr, | ||
llvm::dwarf::DW_LANG_Swift, nullptr, {}, NumExtraInhabitants); | ||
return PTy; | ||
|
||
case TypeKind::BuiltinRawUnsafeContinuation: { | ||
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(clang::LangAS::Default); | ||
return DBuilder.createPointerType(nullptr, PtrSize, 0, | ||
/* DWARFAddressSpace */ llvm::None, | ||
MangledName); | ||
} | ||
} | ||
llvm::DIDerivedType *PTy = DBuilder.createPointerType( | ||
nullptr, PtrSize, 0, | ||
/* DWARFAddressSpace */ llvm::None, MangledName); | ||
|
||
case TypeKind::BuiltinJob: { | ||
unsigned PtrSize = CI.getTargetInfo().getPointerWidth(clang::LangAS::Default); | ||
return DBuilder.createPointerType(nullptr, PtrSize, 0, | ||
/* DWARFAddressSpace */ llvm::None, | ||
MangledName); | ||
return DBuilder.createObjectPointerType(PTy); | ||
} | ||
|
||
case TypeKind::BuiltinExecutor: { | ||
return createDoublePointerSizedStruct( | ||
Scope, "Builtin.Executor", nullptr, MainFile, 0, | ||
|
@@ -1663,6 +1641,25 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |
unsigned FwdDeclLine = 0; | ||
assert(SizeInBits == | ||
CI.getTargetInfo().getPointerWidth(clang::LangAS::Default)); | ||
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) { | ||
auto *DIType = createStructType( | ||
DbgTy, Decl, ClassTy, Scope, File, L.Line, SizeInBits, AlignInBits, | ||
Flags, nullptr, llvm::dwarf::DW_LANG_Swift, MangledName); | ||
assert(DIType && "Unexpected null DIType!"); | ||
assert(DIType && "createStructType should never return null!"); | ||
auto SuperClassTy = ClassTy->getSuperclass(); | ||
if (SuperClassTy) { | ||
auto SuperClassDbgTy = DebugTypeInfo::getFromTypeInfo( | ||
SuperClassTy, IGM.getTypeInfoForUnlowered(SuperClassTy), IGM, | ||
false); | ||
|
||
llvm::DIType *SuperClassDITy = getOrCreateType(SuperClassDbgTy); | ||
assert(SuperClassDITy && "getOrCreateType should never return null!"); | ||
DBuilder.retainType(DBuilder.createInheritance( | ||
DIType, SuperClassDITy, 0, 0, llvm::DINode::FlagZero)); | ||
} | ||
return DIType; | ||
} | ||
return createPointerSizedStruct(Scope, Decl->getNameStr(), L.File, | ||
FwdDeclLine, Flags, MangledName); | ||
} | ||
|
@@ -2033,6 +2030,20 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |
} | ||
#endif | ||
|
||
/// Emits the special builtin types into the debug info. These types are the | ||
/// ones that are unconditionally emitted into the stdlib's metadata and are | ||
/// needed to correctly calculate the layout of more complex types built on | ||
/// top of them. | ||
void createSpecialStlibBuiltinTypes() { | ||
augusto2112 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::ASTTypes) | ||
return; | ||
for (auto BuiltinType: IGM.getOrCreateSpecialStlibBuiltinTypes()) { | ||
auto DbgTy = DebugTypeInfo::getFromTypeInfo( | ||
BuiltinType, IGM.getTypeInfoForUnlowered(BuiltinType), IGM, false); | ||
DBuilder.retainType(getOrCreateType(DbgTy)); | ||
} | ||
} | ||
|
||
llvm::DIType *getOrCreateType(DebugTypeInfo DbgTy) { | ||
// Is this an empty type? | ||
if (DbgTy.isNull()) | ||
|
@@ -2079,6 +2090,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |
TypeDecl = ND; | ||
Context = ND->getParent(); | ||
ClangDecl = ND->getClangDecl(); | ||
} else if (auto BNO = dyn_cast<BuiltinType>(DbgTy.getType())) { | ||
Context = BNO->getASTContext().TheBuiltinModule; | ||
} | ||
if (ClangDecl) { | ||
clang::ASTReader &Reader = *CI.getClangInstance().getASTReader(); | ||
|
@@ -2255,6 +2268,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts, | |
} | ||
OS << '"'; | ||
} | ||
createSpecialStlibBuiltinTypes(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit #1 doesn't have any tests, but we should at least be able to test the special types? |
||
} | ||
|
||
void IRGenDebugInfoImpl::finalize() { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: %target-swift-frontend %s -Onone -emit-ir -gdwarf-types -o - | %FileCheck %s | ||
|
||
// File is empty as this test check for the builtin stdlib types that should | ||
// always be emitted. | ||
|
||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$sBoD", | ||
// CHECK-SAME: size: 64, num_extra_inhabitants: {{2147483647|4096}}, flags: DIFlagArtificial, | ||
// CHECK-SAME: runtimeLang: DW_LANG_Swift) | ||
|
||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$syXlD", | ||
// CHECK-SAME: size: 64, | ||
|
||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$sBbD", | ||
// CHECK-SAME: size: 64, num_extra_inhabitants: {{2147483647|4096}}, flags: DIFlagArtificial, | ||
// CHECK-SAME: runtimeLang: DW_LANG_Swift) | ||
|
||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$sBpD", | ||
// CHECK-SAME: size: 64, num_extra_inhabitants: 1, flags: DIFlagArtificial, | ||
// CHECK-SAME: runtimeLang: DW_LANG_Swift) | ||
|
||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$syyXfD", | ||
// CHECK-SAME: size: 64, | ||
// CHECK-SAME: runtimeLang: DW_LANG_Swift | ||
|
||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$sypXpD", size: 64, | ||
// CHECK-SAME: flags: DIFlagArtificial, runtimeLang: DW_LANG_Swift, identifier: "$sypXpD") | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// RUN: %target-swift-frontend -primary-file %s -emit-ir -gdwarf-types -o - | %FileCheck %s | ||
|
||
class SomeClass { | ||
let first = 4 | ||
let second = "Hello" | ||
} | ||
|
||
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "SomeClass", | ||
// CHECK-SAME: size: 64, elements: | ||
// CHECK-SAME: runtimeLang: DW_LANG_Swift, identifier: "$s7classes9SomeClassCD") | ||
|
||
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "first", | ||
// CHECK-SAME: size: 64) | ||
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "second", | ||
// CHECK-SAME: size: 128, offset: 64) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this intentionally change the behavior for BuiltinRawPointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I changed it because all of them seem artificial types to me (builtins not visible in user source code). What do you think?