Skip to content

Commit 52c1f50

Browse files
Merge pull request swiftlang#71934 from adrian-prantl/123117522
Emit original-source-range comment in inline macro expansion files.
2 parents 8532092 + 1e50be3 commit 52c1f50

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,31 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
286286
// We only care about macros, so skip everything else.
287287
if (generatedInfo->kind != GeneratedSourceInfo::ReplacedFunctionBody &&
288288
generatedInfo->kind != GeneratedSourceInfo::PrettyPrinted)
289-
if (auto *MemBuf = SM.getLLVMSourceMgr().getMemoryBuffer(BufferID))
289+
if (auto *MemBuf = SM.getLLVMSourceMgr().getMemoryBuffer(BufferID)) {
290290
Source = MemBuf->getBuffer();
291+
// This is copying the buffer twice, but Xcode depends on this
292+
// comment in the file.
293+
auto origRange = generatedInfo->originalSourceRange;
294+
if (origRange.isValid()) {
295+
std::string s;
296+
{
297+
llvm::raw_string_ostream buffer(s);
298+
buffer << MemBuf->getBuffer() << "\n";
299+
auto originalFilename =
300+
SM.getDisplayNameForLoc(origRange.getStart(), true);
301+
unsigned startLine, startColumn, endLine, endColumn;
302+
std::tie(startLine, startColumn) =
303+
SM.getPresumedLineAndColumnForLoc(origRange.getStart());
304+
std::tie(endLine, endColumn) =
305+
SM.getPresumedLineAndColumnForLoc(origRange.getEnd());
306+
buffer << "// original-source-range: "
307+
<< DebugPrefixMap.remapPath(originalFilename) << ":"
308+
<< startLine << ":" << startColumn << "-" << endLine
309+
<< ":" << endColumn << "\n";
310+
}
311+
Source = BumpAllocatedString(s);
312+
}
313+
}
291314
}
292315
}
293316
Cached.File = getOrCreateFile(

test/Macros/macro_expand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func testFileID(a: Int, b: Int) {
165165
print(
166166
// CHECK-IR-DAG: ![[L1:[0-9]+]] = distinct !DILocation(line: [[@LINE+3]], column: 5
167167
// CHECK-IR-DAG: ![[L2:[0-9]+]] = distinct !DILocation({{.*}}inlinedAt: ![[L1]])
168-
// CHECK-IR-DAG: !DIFile(filename: "{{.*}}@__swiftmacro_9MacroUser10testFileID1a1bySi_SitF06customdE0fMf_.swift", {{.*}}source: "{{.*}}MacroUser/macro_expand.swift{{.*}}")
168+
// CHECK-IR-DAG: !DIFile(filename: "{{.*}}@__swiftmacro_9MacroUser10testFileID1a1bySi_SitF06customdE0fMf_.swift", {{.*}}source: "{{.*}}MacroUser/macro_expand.swift{{.*}}// original-source-range: {{.*}}")
169169
#addBlocker(
170170
#stringify(a - b)
171171
)

0 commit comments

Comments
 (0)