Skip to content

Commit c35f430

Browse files
authored
Merge pull request #23576 from adrian-prantl/49181568-5.1
2 parents 154e24e + ac9ee92 commit c35f430

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,15 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
241241
return L;
242242

243243
if (auto *ClangDecl = D->getClangDecl()) {
244-
auto ClangSrcLoc = ClangDecl->getBeginLoc();
244+
clang::SourceLocation ClangSrcLoc = ClangDecl->getBeginLoc();
245245
clang::SourceManager &ClangSM =
246246
CI.getClangASTContext().getSourceManager();
247-
L.Line = ClangSM.getPresumedLineNumber(ClangSrcLoc);
248-
L.Filename = ClangSM.getBufferName(ClangSrcLoc);
247+
clang::PresumedLoc PresumedLoc = ClangSM.getPresumedLoc(ClangSrcLoc);
248+
if (!PresumedLoc.isValid())
249+
return L;
250+
L.Line = PresumedLoc.getLine();
251+
L.Column = PresumedLoc.getColumn();
252+
L.Filename = PresumedLoc.getFilename();
249253
return L;
250254
}
251255
return getSwiftDebugLoc(DI, D, End);

test/DebugInfo/Inputs/Macro.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#define MY_ENUM(NAME) \
2+
enum NAME : int NAME; \
3+
enum NAME : int
4+
5+
MY_ENUM(macro_enum) {
6+
zero = 0
7+
};

test/DebugInfo/Inputs/module.modulemap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ module OtherClangModule {
1414
header "OtherSubModule.h"
1515
export *
1616
}
17-
}
17+
}
18+
19+
module Macro {
20+
header "Macro.h"
21+
}
22+

test/DebugInfo/macro.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// REQUIRES: objc-interop
2+
// RUN: %target-swift-frontend -emit-ir %s -g -I %S/Inputs -o - \
3+
// RUN: -parse-as-library | %FileCheck %s
4+
5+
// The source file for "macro_enum", which is defined using a macro, should be
6+
// correctly identified.
7+
8+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "macro_enum",
9+
// CHECK-SAME: file: ![[MACRO_H:[0-9]+]]
10+
// CHECK: ![[MACRO_H]] = !DIFile(filename: "{{.*}}/Inputs/Macro.h",
11+
12+
import Macro
13+
14+
public func f(_ e : macro_enum) -> Int32 {
15+
switch (e) {
16+
case zero:
17+
return 0
18+
default:
19+
return e.rawValue
20+
}
21+
}

0 commit comments

Comments
 (0)