Skip to content

Commit 11ccc71

Browse files
authored
Merge pull request swiftlang#63358 from adrian-prantl/104894694
Wire up mangled macro names in debug info.
2 parents 258b13b + 5ff139d commit 11ccc71

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
567567
if (L.isASTNode<DestructorDecl>())
568568
return "deinit";
569569

570+
if (ValueDecl *D = L.getAsASTNode<ValueDecl>())
571+
return D->getBaseIdentifier().str();
572+
570573
return StringRef();
571574
}
572575

lib/SILGen/SILGenExpr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6035,8 +6035,11 @@ RValue RValueEmitter::visitMacroExpansionExpr(MacroExpansionExpr *E,
60356035
SGFContext C) {
60366036
auto *rewritten = E->getRewritten();
60376037
assert(rewritten && "Macro should have been rewritten by SILGen");
6038-
MacroScope scope(SGF, CleanupLocation(rewritten), E, E->getMacroName(),
6039-
E->getMacroNameLoc());
6038+
Mangle::ASTMangler mangler;
6039+
auto name =
6040+
SGF.getASTContext().getIdentifier(mangler.mangleMacroExpansion(E));
6041+
MacroScope scope(SGF, CleanupLocation(rewritten), E, name.str(),
6042+
E->getMacroRef().getDecl());
60406043
return visit(rewritten, C);
60416044
}
60426045

lib/SILGen/SILGenFunction.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,16 @@ DeclName SILGenModule::getMagicFunctionName(SILDeclRef ref) {
163163

164164
void SILGenFunction::enterDebugScope(SILLocation Loc, bool isBindingScope,
165165
Optional<SILLocation> MacroExpansion,
166-
DeclNameRef MacroName,
167-
DeclNameLoc MacroNameLoc) {
166+
StringRef MacroName,
167+
Optional<SILLocation> MacroLoc) {
168168
auto *Parent = DebugScopeStack.size() ? DebugScopeStack.back().getPointer()
169169
: F.getDebugScope();
170170
auto *Scope = Parent;
171171
// Don't nest a scope for Loc under Parent unless it's actually different.
172172
if (RegularLocation(Parent->getLoc()) != RegularLocation(Loc)) {
173173
SILDebugScope *InlinedAt = nullptr;
174174
// Create an inline scope for a macro expansion.
175-
if (MacroExpansion && MacroName && MacroNameLoc.isValid()) {
175+
if (MacroExpansion && !MacroName.empty() && MacroLoc) {
176176
InlinedAt = new (SGM.M) SILDebugScope(RegularLocation(*MacroExpansion),
177177
&getFunction(), Parent);
178178
SILGenFunctionBuilder B(SGM);
@@ -183,10 +183,9 @@ void SILGenFunction::enterDebugScope(SILLocation Loc, bool isBindingScope,
183183
/*Results*/ {}, None, SubstitutionMap(), SubstitutionMap(),
184184
SGM.M.getASTContext());
185185
SILFunction *MacroFn = B.getOrCreateFunction(
186-
Loc, MacroName.getBaseIdentifier().str(),
187-
SILLinkage::DefaultForDeclaration, FunctionType, IsNotBare,
188-
IsNotTransparent, IsNotSerialized, IsNotDynamic, IsNotDistributed,
189-
IsNotRuntimeAccessible);
186+
*MacroLoc, MacroName, SILLinkage::DefaultForDeclaration, FunctionType,
187+
IsNotBare, IsNotTransparent, IsNotSerialized, IsNotDynamic,
188+
IsNotDistributed, IsNotRuntimeAccessible);
190189
auto MacroScope = new (SGM.M) SILDebugScope(Loc, MacroFn);
191190
Parent = MacroScope;
192191
}

lib/SILGen/SILGenFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
614614
/// ends.
615615
void enterDebugScope(SILLocation Loc, bool isBindingScope = false,
616616
Optional<SILLocation> MacroExpansion = {},
617-
DeclNameRef MacroName = {},
618-
DeclNameLoc MacroNameLoc = {});
617+
StringRef MacroName = {},
618+
Optional<SILLocation> MacroLoc = {});
619619

620620
/// Return to the previous debug scope.
621621
void leaveDebugScope();

lib/SILGen/Scope.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ class LLVM_LIBRARY_VISIBILITY MacroScope {
167167

168168
public:
169169
explicit MacroScope(SILGenFunction &SGF, CleanupLocation loc,
170-
SILLocation MacroExpansion, DeclNameRef MacroName,
171-
DeclNameLoc MacroNameLoc)
170+
SILLocation MacroExpansion, StringRef MacroName,
171+
SILLocation MacroNameLoc)
172172
: SGF(SGF) {
173173
SGF.enterDebugScope(loc, false, MacroExpansion, MacroName, MacroNameLoc);
174174
}

test/Macros/macro_expand.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
// Debug info SIL testing
1414
// RUN: %target-swift-frontend -emit-sil -enable-experimental-feature Macros -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser -o - -g | %FileCheck --check-prefix CHECK-SIL %s
1515

16-
// RUN: %target-swift-frontend -emit-sil -enable-experimental-feature Macros -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser -o - -g | %FileCheck --check-prefix CHECK-SIL %s
16+
// Debug info IR testing
17+
// RUN: %target-swift-frontend -emit-ir -enable-experimental-feature Macros -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser -o - -g | %FileCheck --check-prefix CHECK-IR %s
1718

1819
// Execution testing
1920
// RUN: %target-build-swift -g -enable-experimental-feature Macros -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -L %swift-host-lib-dir %s -o %t/main -module-name MacroUser
@@ -31,9 +32,10 @@
3132
func testFileID(a: Int, b: Int) {
3233
// CHECK: MacroUser/macro_expand.swift
3334
print("Result is \(#customFileID)")
34-
// CHECK-SIL: sil_scope [[MACRO_SCOPE:[0-9]+]] { loc "{{.*}}":1:1 parent @customFileID {{.*}} }
35+
// CHECK-SIL: sil_scope [[MACRO_SCOPE:[0-9]+]] { loc "{{.*}}":1:1 parent @$s9MacroUser10testFileID1a1bySi_SitF06customdE0fMf_ {{.*}} }
3536
// CHECK-SIL: sil_scope [[SRC_SCOPE:[0-9]+]] { loc "{{.*}}macro_expand.swift":[[@LINE-2]]
3637
// CHECK-SIL: sil_scope {{[0-9]+}} { loc "{{.*}}":1:1 parent [[MACRO_SCOPE]] inlined_at [[SRC_SCOPE]] }
38+
// CHECK-IR: !DISubprogram(name: "customFileID", linkageName: "$s9MacroUser10testFileID1a1bySi_SitF06customdE0fMf_"
3739
3840
3941
// CHECK: Builtin result is MacroUser/macro_expand.swift

0 commit comments

Comments
 (0)