@@ -193,43 +193,63 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
193
193
return StringRef ();
194
194
}
195
195
196
- SILLocation::DebugLoc getDeserializedLoc (Pattern *) { return {}; }
197
- SILLocation:: DebugLoc getDeserializedLoc (Expr *) { return {}; }
198
- SILLocation:: DebugLoc getDeserializedLoc (Stmt *) { return {}; }
199
- SILLocation:: DebugLoc getDeserializedLoc (Decl *D) {
200
- SILLocation:: DebugLoc L;
196
+ using DebugLoc = SILLocation::DebugLoc;
197
+ DebugLoc getDeserializedLoc (Pattern *) { return {}; }
198
+ DebugLoc getDeserializedLoc (Expr *) { return {}; }
199
+ DebugLoc getDeserializedLoc (Decl *D) {
200
+ DebugLoc L;
201
201
const DeclContext *DC = D->getDeclContext ()->getModuleScopeContext ();
202
202
StringRef Filename = getFilenameFromDC (DC);
203
203
if (!Filename.empty ())
204
204
L.Filename = Filename;
205
205
return L;
206
206
}
207
207
208
- // / Use the SM to figure out the actual line/column of a SourceLoc.
208
+ // / Use the Swift SM to figure out the actual line/column of a SourceLoc.
209
209
template <typename WithLoc>
210
- SILLocation::DebugLoc getDebugLoc (IRGenDebugInfo &DI, WithLoc *S,
211
- bool End = false ) {
212
- SILLocation::DebugLoc L;
213
- if (S == nullptr )
214
- return L;
210
+ DebugLoc getSwiftDebugLoc (IRGenDebugInfo &DI, WithLoc *ASTNode, bool End) {
211
+ if (!ASTNode)
212
+ return {};
215
213
216
- SourceLoc Loc = End ? S ->getEndLoc () : S ->getStartLoc ();
214
+ SourceLoc Loc = End ? ASTNode ->getEndLoc () : ASTNode ->getStartLoc ();
217
215
if (Loc.isInvalid ())
218
216
// This may be a deserialized or clang-imported decl. And modules
219
217
// don't come with SourceLocs right now. Get at least the name of
220
218
// the module.
221
- return getDeserializedLoc (S );
219
+ return getDeserializedLoc (ASTNode );
222
220
223
221
return DI.decodeSourceLoc (Loc);
224
222
}
225
223
226
- SILLocation::DebugLoc getStartLocation (Optional<SILLocation> OptLoc) {
224
+ DebugLoc getDebugLoc (IRGenDebugInfo &DI, Pattern *P, bool End = false ) {
225
+ return getSwiftDebugLoc (DI, P, End);
226
+ }
227
+ DebugLoc getDebugLoc (IRGenDebugInfo &DI, Expr *E, bool End = false ) {
228
+ return getSwiftDebugLoc (DI, E, End);
229
+ }
230
+ DebugLoc getDebugLoc (IRGenDebugInfo &DI, Decl *D, bool End = false ) {
231
+ DebugLoc L;
232
+ if (!D)
233
+ return L;
234
+
235
+ if (auto *ClangDecl = D->getClangDecl ()) {
236
+ auto ClangSrcLoc = ClangDecl->getLocStart ();
237
+ clang::SourceManager &ClangSM =
238
+ CI.getClangASTContext ().getSourceManager ();
239
+ L.Line = ClangSM.getPresumedLineNumber (ClangSrcLoc);
240
+ L.Filename = ClangSM.getBufferName (ClangSrcLoc);
241
+ return L;
242
+ }
243
+ return getSwiftDebugLoc (DI, D, End);
244
+ }
245
+
246
+ DebugLoc getStartLocation (Optional<SILLocation> OptLoc) {
227
247
if (!OptLoc)
228
248
return {};
229
249
return decodeSourceLoc (OptLoc->getStartSourceLoc ());
230
250
}
231
251
232
- SILLocation:: DebugLoc sanitizeCodeViewDebugLoc (SILLocation:: DebugLoc DLoc) {
252
+ DebugLoc sanitizeCodeViewDebugLoc (DebugLoc DLoc) {
233
253
if (Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
234
254
// When WinDbg finds two locations with the same line but different
235
255
// columns, the user must select an address when they break on that
@@ -238,13 +258,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
238
258
return DLoc;
239
259
}
240
260
241
- SILLocation:: DebugLoc decodeDebugLoc (SILLocation Loc) {
261
+ DebugLoc decodeDebugLoc (SILLocation Loc) {
242
262
if (Loc.isDebugInfoLoc ())
243
263
return sanitizeCodeViewDebugLoc (Loc.getDebugInfoLoc ());
244
264
return decodeSourceLoc (Loc.getDebugSourceLoc ());
245
265
}
246
266
247
- SILLocation:: DebugLoc getDebugLocation (Optional<SILLocation> OptLoc) {
267
+ DebugLoc getDebugLocation (Optional<SILLocation> OptLoc) {
248
268
if (!OptLoc || (Opts.DebugInfoFormat != IRGenDebugInfoFormat::CodeView &&
249
269
OptLoc->isInPrologue ()))
250
270
return {};
@@ -1187,13 +1207,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1187
1207
auto *StructTy = BaseTy->castTo <StructType>();
1188
1208
auto *Decl = StructTy->getDecl ();
1189
1209
auto L = getDebugLoc (*this , Decl);
1190
- if (auto *ClangDecl = Decl->getClangDecl ()) {
1191
- auto ClangSrcLoc = ClangDecl->getLocStart ();
1192
- clang::SourceManager &ClangSM =
1193
- CI.getClangASTContext ().getSourceManager ();
1194
- L.Line = ClangSM.getPresumedLineNumber (ClangSrcLoc);
1195
- L.Filename = ClangSM.getBufferName (ClangSrcLoc);
1196
- }
1197
1210
auto *File = getOrCreateFile (L.Filename );
1198
1211
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes)
1199
1212
return createStructType (DbgTy, Decl, StructTy, Scope, File, L.Line ,
@@ -1212,13 +1225,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1212
1225
auto *ClassTy = BaseTy->castTo <ClassType>();
1213
1226
auto *Decl = ClassTy->getDecl ();
1214
1227
auto L = getDebugLoc (*this , Decl);
1215
- if (auto *ClangDecl = Decl->getClangDecl ()) {
1216
- auto ClangSrcLoc = ClangDecl->getLocStart ();
1217
- clang::SourceManager &ClangSM =
1218
- CI.getClangASTContext ().getSourceManager ();
1219
- L.Line = ClangSM.getPresumedLineNumber (ClangSrcLoc);
1220
- L.Filename = ClangSM.getBufferName (ClangSrcLoc);
1221
- }
1222
1228
assert (SizeInBits == CI.getTargetInfo ().getPointerWidth (0 ));
1223
1229
return createPointerSizedStruct (Scope, Decl->getNameStr (),
1224
1230
getOrCreateFile (L.Filename ), L.Line ,
@@ -1414,13 +1420,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1414
1420
auto L = getDebugLoc (*this , Decl);
1415
1421
auto AliasedTy = TypeAliasTy->getSinglyDesugaredType ();
1416
1422
auto File = getOrCreateFile (L.Filename );
1417
- // For TypeAlias types, the DeclContext for the aliasED type is
1423
+ // For TypeAlias types, the DeclContext for the aliased type is
1418
1424
// in the decl of the alias type.
1419
1425
DebugTypeInfo AliasedDbgTy (
1420
1426
DbgTy.getDeclContext (), DbgTy.getGenericEnvironment (), AliasedTy,
1421
1427
DbgTy.StorageType , DbgTy.size , DbgTy.align , DbgTy.DefaultAlignment );
1422
1428
return DBuilder.createTypedef (getOrCreateType (AliasedDbgTy), MangledName,
1423
- File, L.Line , File );
1429
+ File, L.Line , Scope );
1424
1430
}
1425
1431
1426
1432
case TypeKind::Paren: {
@@ -1529,26 +1535,35 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1529
1535
// FIXME: Builtin and qualified types in LLVM have no parent
1530
1536
// scope. TODO: This can be fixed by extending DIBuilder.
1531
1537
llvm::DIScope *Scope = nullptr ;
1532
- DeclContext *Context = DbgTy.getType ()->getNominalOrBoundGenericNominal ();
1533
- if (Context) {
1534
- if (auto *D = Context->getSelfNominalTypeDecl ())
1535
- if (auto *ClangDecl = D->getClangDecl ()) {
1536
- clang::ASTReader &Reader = *CI.getClangInstance ().getModuleManager ();
1537
- auto Idx = ClangDecl->getOwningModuleID ();
1538
- auto SubModuleDesc = Reader.getSourceDescriptor (Idx);
1539
- auto TopLevelModuleDesc = getClangModule (*D->getModuleContext ());
1540
- if (SubModuleDesc && TopLevelModuleDesc) {
1541
- // Describe the submodule, but substitute the cached ASTFile from
1542
- // the toplevel module. The ASTFile pointer in SubModule may be
1543
- // dangling and cant be trusted.
1544
- Scope = getOrCreateModule ({SubModuleDesc->getModuleName (),
1545
- SubModuleDesc->getPath (),
1546
- TopLevelModuleDesc->getASTFile (),
1547
- TopLevelModuleDesc->getSignature ()},
1548
- SubModuleDesc->getModuleOrNull ());
1549
- }
1550
- }
1551
- Context = Context->getParent ();
1538
+ // Make sure to retrieve the context of the type alias, not the pointee.
1539
+ DeclContext *Context = nullptr ;
1540
+ const Decl *TypeDecl = nullptr ;
1541
+ const clang::Decl *ClangDecl = nullptr ;
1542
+ if (auto Alias = dyn_cast<TypeAliasType>(DbgTy.getType ())) {
1543
+ TypeAliasDecl *AliasDecl = Alias->getDecl ();
1544
+ TypeDecl = AliasDecl;
1545
+ Context = AliasDecl->getParent ();
1546
+ ClangDecl = AliasDecl->getClangDecl ();
1547
+ } else if (auto *ND = DbgTy.getType ()->getNominalOrBoundGenericNominal ()) {
1548
+ TypeDecl = ND;
1549
+ Context = ND->getParent ();
1550
+ ClangDecl = ND->getClangDecl ();
1551
+ }
1552
+ if (ClangDecl) {
1553
+ clang::ASTReader &Reader = *CI.getClangInstance ().getModuleManager ();
1554
+ auto Idx = ClangDecl->getOwningModuleID ();
1555
+ auto SubModuleDesc = Reader.getSourceDescriptor (Idx);
1556
+ auto TopLevelModuleDesc = getClangModule (*TypeDecl->getModuleContext ());
1557
+ if (SubModuleDesc && TopLevelModuleDesc) {
1558
+ // Describe the submodule, but substitute the cached ASTFile from
1559
+ // the toplevel module. The ASTFile pointer in SubModule may be
1560
+ // dangling and cant be trusted.
1561
+ Scope = getOrCreateModule ({SubModuleDesc->getModuleName (),
1562
+ SubModuleDesc->getPath (),
1563
+ TopLevelModuleDesc->getASTFile (),
1564
+ TopLevelModuleDesc->getSignature ()},
1565
+ SubModuleDesc->getModuleOrNull ());
1566
+ }
1552
1567
}
1553
1568
if (!Scope)
1554
1569
Scope = getOrCreateContext (Context);
0 commit comments