Skip to content

Debug Info: Fix a bug when decoding the source file for a Clang Decl #23576

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 1 commit into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,15 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
return L;

if (auto *ClangDecl = D->getClangDecl()) {
auto ClangSrcLoc = ClangDecl->getBeginLoc();
clang::SourceLocation ClangSrcLoc = ClangDecl->getBeginLoc();
clang::SourceManager &ClangSM =
CI.getClangASTContext().getSourceManager();
L.Line = ClangSM.getPresumedLineNumber(ClangSrcLoc);
L.Filename = ClangSM.getBufferName(ClangSrcLoc);
clang::PresumedLoc PresumedLoc = ClangSM.getPresumedLoc(ClangSrcLoc);
if (!PresumedLoc.isValid())
return L;
L.Line = PresumedLoc.getLine();
L.Column = PresumedLoc.getColumn();
L.Filename = PresumedLoc.getFilename();
return L;
}
return getSwiftDebugLoc(DI, D, End);
Expand Down
7 changes: 7 additions & 0 deletions test/DebugInfo/Inputs/Macro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define MY_ENUM(NAME) \
enum NAME : int NAME; \
enum NAME : int

MY_ENUM(macro_enum) {
zero = 0
};
7 changes: 6 additions & 1 deletion test/DebugInfo/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ module OtherClangModule {
header "OtherSubModule.h"
export *
}
}
}

module Macro {
header "Macro.h"
}

21 changes: 21 additions & 0 deletions test/DebugInfo/macro.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// REQUIRES: objc-interop
// RUN: %target-swift-frontend -emit-ir %s -g -I %S/Inputs -o - \
// RUN: -parse-as-library | %FileCheck %s

// The source file for "macro_enum", which is defined using a macro, should be
// correctly identified.

// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "macro_enum",
// CHECK-SAME: file: ![[MACRO_H:[0-9]+]]
// CHECK: ![[MACRO_H]] = !DIFile(filename: "{{.*}}/Inputs/Macro.h",

import Macro

public func f(_ e : macro_enum) -> Int32 {
switch (e) {
case zero:
return 0
default:
return e.rawValue
}
}