Skip to content

Commit 7a1ab7a

Browse files
authored
Merge pull request #37970 from DougGregor/clang-swift-attr-for-modifiers
2 parents e11a188 + 6ba2629 commit 7a1ab7a

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ NOTE(unresolvable_clang_decl_is_a_framework_bug,none,
8282
"please report this issue to the owners of '%0'",
8383
(StringRef))
8484

85-
WARNING(clang_swift_attr_without_at,none,
86-
"Swift attribute '%0' does not start with '@'", (StringRef))
85+
WARNING(clang_swift_attr_unhandled,none,
86+
"Ignoring unknown Swift attribute or modifier '%0'", (StringRef))
8787

8888
WARNING(implicit_bridging_header_imported_from_module,none,
8989
"implicit import of bridging header '%0' via module %1 "

include/swift/Parse/Parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,8 @@ class Parser {
10041004

10051005
/// Parse the optional modifiers before a declaration.
10061006
bool parseDeclModifierList(DeclAttributes &Attributes, SourceLoc &StaticLoc,
1007-
StaticSpellingKind &StaticSpelling);
1007+
StaticSpellingKind &StaticSpelling,
1008+
bool isFromClangAttribute = false);
10081009

10091010
/// Parse an availability attribute of the form
10101011
/// @available(*, introduced: 1.0, deprecated: 3.1).

lib/ClangImporter/ImportDecl.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8728,19 +8728,28 @@ void ClangImporter::Implementation::importAttributes(
87288728
// Prime the lexer.
87298729
parser.consumeTokenWithoutFeedingReceiver();
87308730

8731+
bool hadError = false;
87318732
SourceLoc atLoc;
87328733
if (parser.consumeIf(tok::at_sign, atLoc)) {
8733-
(void)parser.parseDeclAttribute(
8734+
hadError = parser.parseDeclAttribute(
87348735
MappedDecl->getAttrs(), atLoc, initContext,
8735-
/*isFromClangAttribute=*/true);
8736+
/*isFromClangAttribute=*/true).isError();
87368737
} else {
8737-
// Complain about the missing '@'.
8738+
SourceLoc staticLoc;
8739+
StaticSpellingKind staticSpelling;
8740+
hadError = parser.parseDeclModifierList(
8741+
MappedDecl->getAttrs(), staticLoc, staticSpelling,
8742+
/*isFromClangAttribute=*/true);
8743+
}
8744+
8745+
if (hadError) {
8746+
// Complain about the unhandled attribute or modifier.
87388747
auto &clangSrcMgr = getClangASTContext().getSourceManager();
87398748
ClangSourceBufferImporter &bufferImporter =
87408749
getBufferImporterForDiagnostics();
87418750
SourceLoc attrLoc = bufferImporter.resolveSourceLocation(
87428751
clangSrcMgr, swiftAttr->getLocation());
8743-
diagnose(attrLoc, diag::clang_swift_attr_without_at,
8752+
diagnose(attrLoc, diag::clang_swift_attr_unhandled,
87448753
swiftAttr->getAttribute());
87458754
}
87468755
continue;

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,7 +3554,8 @@ ParserStatus Parser::parseDeclAttributeList(DeclAttributes &Attributes) {
35543554
// 'distributed'
35553555
bool Parser::parseDeclModifierList(DeclAttributes &Attributes,
35563556
SourceLoc &StaticLoc,
3557-
StaticSpellingKind &StaticSpelling) {
3557+
StaticSpellingKind &StaticSpelling,
3558+
bool isFromClangAttribute) {
35583559
SyntaxParsingContext ListContext(SyntaxContext, SyntaxKind::ModifierList);
35593560
bool isError = false;
35603561
bool hasModifier = false;
@@ -3622,7 +3623,8 @@ bool Parser::parseDeclModifierList(DeclAttributes &Attributes,
36223623

36233624
SyntaxParsingContext ModContext(SyntaxContext,
36243625
SyntaxKind::DeclModifier);
3625-
isError |= parseNewDeclAttribute(Attributes, /*AtLoc=*/{}, Kind);
3626+
isError |= parseNewDeclAttribute(
3627+
Attributes, /*AtLoc=*/{}, Kind, isFromClangAttribute);
36263628
hasModifier = true;
36273629
continue;
36283630
}

test/ClangImporter/objc_async.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ actor MySubclassCheckingSwiftAttributes : ProtocolWithSwiftAttributes {
121121
syncMethod() // expected-error{{ctor-isolated instance method 'syncMethod()' can not be referenced from a non-isolated context}}
122122
}
123123

124+
nonisolated func nonisolatedMethod() {
125+
}
126+
124127
@MainActor func mainActorMethod() {
125128
syncMethod() // expected-error{{actor-isolated instance method 'syncMethod()' can not be referenced from the main actor}}
126129
}

test/IDE/print_clang_objc_async.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import _Concurrency
9898

9999
// CHECK-LABEL: protocol ProtocolWithSwiftAttributes {
100100
// CHECK-NEXT: nonisolated func independentMethod()
101+
// CHECK-NEXT: nonisolated func nonisolatedMethod()
101102
// CHECK-NEXT: {{^}} @objc @MainActor func mainActorMethod()
102103
// CHECK-NEXT: {{^}} @objc @MainActor func uiActorMethod()
103104
// CHECK-NEXT: {{^}} @objc optional func missingAtAttributeMethod()

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_res
9696

9797
@protocol ProtocolWithSwiftAttributes
9898
-(void)independentMethod __attribute__((__swift_attr__("@actorIndependent")));
99+
-(void)nonisolatedMethod __attribute__((__swift_attr__("nonisolated")));
99100
-(void)mainActorMethod __attribute__((__swift_attr__("@MainActor")));
100101
-(void)uiActorMethod __attribute__((__swift_attr__("@UIActor")));
101102

0 commit comments

Comments
 (0)