Skip to content

Commit 7c5888c

Browse files
authored
Merge pull request #82144 from swiftlang/gaborh/using-shadow-decl-mangling
2 parents d9c73d3 + 059051c commit 7c5888c

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "clang/AST/ASTContext.h"
5050
#include "clang/AST/Attr.h"
5151
#include "clang/AST/Decl.h"
52+
#include "clang/AST/DeclCXX.h"
5253
#include "clang/AST/DeclObjC.h"
5354
#include "clang/AST/DeclTemplate.h"
5455
#include "clang/AST/Mangle.h"
@@ -3080,7 +3081,7 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl,
30803081

30813082
auto *nominal = dyn_cast<NominalTypeDecl>(decl);
30823083

3083-
if (nominal && isa<BuiltinTupleDecl>(nominal))
3084+
if (isa_and_nonnull<BuiltinTupleDecl>(nominal))
30843085
return appendOperator("BT");
30853086

30863087
// Check for certain standard types.
@@ -3132,6 +3133,12 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl,
31323133
return false;
31333134
}
31343135

3136+
// Mangle `Foo` from `namespace Bar { class Foo; } using Bar::Foo;` the same
3137+
// way as if we spelled `Bar.Foo` explicitly.
3138+
if (const auto *usingShadowDecl =
3139+
dyn_cast<clang::UsingShadowDecl>(namedDecl))
3140+
namedDecl = usingShadowDecl->getTargetDecl();
3141+
31353142
// Mangle ObjC classes using their runtime names.
31363143
auto interface = dyn_cast<clang::ObjCInterfaceDecl>(namedDecl);
31373144
auto protocol = dyn_cast<clang::ObjCProtocolDecl>(namedDecl);

test/Interop/Cxx/namespace/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,8 @@ module MembersTransitive {
6969
header "members-transitive.h"
7070
requires cplusplus
7171
}
72+
73+
module UsingFromNamespace {
74+
header "using-from-namespace.h"
75+
requires cplusplus
76+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
namespace Test {
4+
class Foo {};
5+
namespace Test2 {
6+
class Bar {};
7+
} // namespace Test2
8+
9+
using Test2::Bar;
10+
} // namespace Test
11+
12+
using Test::Bar;
13+
using Test::Foo;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %target-swift-emit-irgen -I %S/Inputs/ -cxx-interoperability-mode=default -g %s
2+
3+
import UsingFromNamespace
4+
5+
func f(_ foo: Foo) {}
6+
func g(_ bar: Bar) {}

0 commit comments

Comments
 (0)