Skip to content

Commit 70f1a0f

Browse files
authored
Merge pull request #82175 from swiftlang/gaborh/using-shadow-decl-mangling-on-6.2
[6.2][cxx-interop] Fix crash in ASTMangler triggered by UsingShadowDecls
2 parents 8f3c0ae + 2327cec commit 70f1a0f

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"
@@ -3079,7 +3080,7 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl,
30793080

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

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

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

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