Skip to content

Commit 5277a76

Browse files
authored
Merge pull request #39634 from apple/es-m5
Module aliasing: use module real name to create DIModule
2 parents cf5fee0 + 8f62569 commit 5277a76

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,12 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
781781
if (Optional<ASTSourceDescriptor> ModuleDesc = getClangModule(*M))
782782
return getOrCreateModule(*ModuleDesc, ModuleDesc->getModuleOrNull());
783783
StringRef Path = getFilenameFromDC(M);
784-
StringRef Name = M->getName().str();
784+
// Use the module 'real' name, which can be different from the name if module
785+
// aliasing was used (swift modules only). For example, if a source file has
786+
// 'import Foo', and '-module-alias Foo=Bar' was passed in, the real name of
787+
// the module on disk is Bar (.swiftmodule or .swiftinterface), and is used
788+
// for loading and mangling.
789+
StringRef Name = M->getRealName().str();
785790
return getOrCreateModule(M, TheCU, Name, Path);
786791
}
787792

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
3+
/// Create a module Bar
4+
// RUN: echo 'public class Klass {}' > %t/FileBar.swift
5+
// RUN: %target-swift-frontend -module-name Bar %t/FileBar.swift -emit-module -emit-module-path %t/Bar.swiftmodule
6+
// RUN: test -f %t/Bar.swiftmodule
7+
8+
/// Create a module Foo that imports Cat with -module-alias Cat=Bar
9+
// RUN: %target-swift-frontend -emit-ir -module-name Foo -module-alias Cat=Bar %s -I %t -g -o - | %FileCheck %s
10+
11+
// CHECK-DAG: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}test{{/|\\\\}}DebugInfo{{/|\\\\}}module-alias-load-module.swift"
12+
// CHECK-DAG: ![[BARMODULE:[0-9]+]] = !DIModule({{.*}}, name: "Bar"
13+
// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[FILE]], entity: ![[BARMODULE]]
14+
15+
import Cat
16+
public func meow() -> Cat.Klass? { return nil }

0 commit comments

Comments
 (0)