Skip to content

Commit 0610aca

Browse files
authored
Merge pull request #10984 from swiftlang/jepa3
[stable/20250601] Revert "[Clang][Sema] Allow qualified type names in `swift_name` attr…
2 parents 8a46525 + 0a78580 commit 0610aca

File tree

2 files changed

+4
-49
lines changed

2 files changed

+4
-49
lines changed

clang/lib/Sema/SemaSwift.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ static bool isValidSwiftErrorResultType(QualType Ty) {
7272
return isValidSwiftContextType(Ty);
7373
}
7474

75-
static bool isValidSwiftContextName(StringRef ContextName) {
76-
// ContextName might be qualified, e.g. 'MyNamespace.MyStruct'.
77-
SmallVector<StringRef, 1> ContextNameComponents;
78-
ContextName.split(ContextNameComponents, '.');
79-
return all_of(ContextNameComponents, [&](StringRef Component) {
80-
return isValidAsciiIdentifier(Component);
81-
});
82-
}
83-
8475
void SemaSwift::handleAttrAttr(Decl *D, const ParsedAttr &AL) {
8576
if (AL.isInvalid() || AL.isUsedAsTypeAttr())
8677
return;
@@ -365,11 +356,11 @@ static bool validateSwiftFunctionName(Sema &S, const ParsedAttr &AL,
365356

366357
// Split at the first '.', if it exists, which separates the context name
367358
// from the base name.
368-
std::tie(ContextName, BaseName) = BaseName.rsplit('.');
359+
std::tie(ContextName, BaseName) = BaseName.split('.');
369360
if (BaseName.empty()) {
370361
BaseName = ContextName;
371362
ContextName = StringRef();
372-
} else if (ContextName.empty() || !isValidSwiftContextName(ContextName)) {
363+
} else if (ContextName.empty() || !isValidAsciiIdentifier(ContextName)) {
373364
S.Diag(Loc, diag::warn_attr_swift_name_invalid_identifier)
374365
<< AL << /*context*/ 1;
375366
return false;
@@ -593,11 +584,11 @@ bool SemaSwift::DiagnoseName(Decl *D, StringRef Name, SourceLocation Loc,
593584
!IsAsync) {
594585
StringRef ContextName, BaseName;
595586

596-
std::tie(ContextName, BaseName) = Name.rsplit('.');
587+
std::tie(ContextName, BaseName) = Name.split('.');
597588
if (BaseName.empty()) {
598589
BaseName = ContextName;
599590
ContextName = StringRef();
600-
} else if (!isValidSwiftContextName(ContextName)) {
591+
} else if (!isValidAsciiIdentifier(ContextName)) {
601592
Diag(Loc, diag::warn_attr_swift_name_invalid_identifier)
602593
<< AL << /*context*/ 1;
603594
return false;

clang/test/SemaObjCXX/attr-swift_name-cxx.mm

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
11
// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc -fblocks %s
22

3-
#define SWIFT_NAME(name) __attribute__((swift_name(name)))
43
#define SWIFT_ASYNC_NAME(name) __attribute__((__swift_async_name__(name)))
54

6-
namespace MyNS {
7-
struct NestedStruct {};
8-
}
9-
10-
void nestedStruct_method(MyNS::NestedStruct) SWIFT_NAME("MyNS.NestedStruct.method(self:)");
11-
void nestedStruct_methodConstRef(const MyNS::NestedStruct&) SWIFT_NAME("MyNS.NestedStruct.methodConstRef(self:)");
12-
void nestedStruct_invalidContext1(MyNS::NestedStruct) SWIFT_NAME(".MyNS.NestedStruct.invalidContext1(self:)"); // expected-warning {{'swift_name' attribute has invalid identifier for the context name}}
13-
void nestedStruct_invalidContext2(MyNS::NestedStruct) SWIFT_NAME("MyNS::NestedStruct.invalidContext2(self:)"); // expected-warning {{'swift_name' attribute has invalid identifier for the context name}}
14-
void nestedStruct_invalidContext3(MyNS::NestedStruct) SWIFT_NAME("::MyNS::NestedStruct.invalidContext3(self:)"); // expected-warning {{'swift_name' attribute has invalid identifier for the context name}}
15-
void nestedStruct_invalidContext4(MyNS::NestedStruct) SWIFT_NAME("MyNS..NestedStruct.invalidContext4(self:)"); // expected-warning {{'swift_name' attribute has invalid identifier for the context name}}
16-
void nestedStruct_invalidContext5(MyNS::NestedStruct) SWIFT_NAME("MyNS.NestedStruct.invalidContext5.(self:)"); // expected-warning {{'swift_name' attribute has invalid identifier for the base name}}
17-
void nestedStruct_invalidContext6(MyNS::NestedStruct) SWIFT_NAME("MyNS.NestedStruct::invalidContext6(self:)"); // expected-warning {{'swift_name' attribute has invalid identifier for the base name}}
18-
19-
namespace MyNS {
20-
namespace MyDeepNS {
21-
struct DeepNestedStruct {};
22-
}
23-
}
24-
25-
void deepNestedStruct_method(MyNS::MyDeepNS::DeepNestedStruct) SWIFT_NAME("MyNS.MyDeepNS.DeepNestedStruct.method(self:)");
26-
void deepNestedStruct_methodConstRef(const MyNS::MyDeepNS::DeepNestedStruct&) SWIFT_NAME("MyNS.MyDeepNS.DeepNestedStruct.methodConstRef(self:)");
27-
void deepNestedStruct_invalidContext(const MyNS::MyDeepNS::DeepNestedStruct&) SWIFT_NAME("MyNS::MyDeepNS::DeepNestedStruct.methodConstRef(self:)"); // expected-warning {{'swift_name' attribute has invalid identifier for the context name}}
28-
29-
typedef MyNS::MyDeepNS::DeepNestedStruct DeepNestedStructTypedef;
30-
31-
void deepNestedStructTypedef_method(DeepNestedStructTypedef) SWIFT_NAME("DeepNestedStructTypedef.method(self:)");
32-
void deepNestedStructTypedef_methodQualName(MyNS::MyDeepNS::DeepNestedStruct) SWIFT_NAME("DeepNestedStructTypedef.method(self:)");
33-
34-
struct TopLevelStruct {
35-
struct StructInStruct {};
36-
};
37-
38-
void structInStruct_method(TopLevelStruct::StructInStruct) SWIFT_NAME("TopLevelStruct.StructInStruct.method(self:)");
39-
void structInStruct_invalidContext(TopLevelStruct::StructInStruct) SWIFT_NAME("TopLevelStruct::StructInStruct.method(self:)"); // expected-warning {{'swift_name' attribute has invalid identifier for the context name}}
40-
415
typedef int (^CallbackTy)(void);
426

437
class CXXClass {

0 commit comments

Comments
 (0)