Skip to content

Commit 31429fc

Browse files
committed
[Legacy parser] No freestanding macros in @abi
SwiftSyntaxParser is already doing this, and we already diagnosed it in Sema anyway, so we’re just moving that diagnostic earlier so the ASTGen testing mode is happy. Also adding compiler tests for it. Macro-related tests are not included in this commit; they require matching swift-syntax changes which are being negotiated.
1 parent a103e21 commit 31429fc

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,11 @@ ERROR(attr_unsupported_on_target, none,
15681568
ERROR(attr_name_unsupported_on_target, none,
15691569
"attribute '%0' is unsupported on target '%1'", (StringRef, StringRef))
15701570

1571+
// abi attribute
1572+
ERROR(attr_abi_incompatible_kind,none,
1573+
"cannot use %0 in '@abi'",
1574+
(DescriptiveDeclKind))
1575+
15711576
// availability
15721577
ERROR(attr_availability_platform,none,
15731578
"expected platform name or '*' for '%0' attribute", (StringRef))

lib/Parse/ParseDecl.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,9 +3357,18 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
33573357
}
33583358

33593359
if (abiDecl) {
3360-
Attributes.add(new (Context) ABIAttr(abiDecl,
3361-
AtLoc, { Loc, rParenLoc },
3362-
/*implicit=*/false));
3360+
auto attr = new (Context) ABIAttr(abiDecl, AtLoc, { Loc, rParenLoc },
3361+
/*implicit=*/false);
3362+
3363+
// Diagnose syntactically invalid abiDecl kind here to match behavior of
3364+
// Swift parser.
3365+
if (!attr->canAppearOnDecl(abiDecl) && !isa<PatternBindingDecl>(abiDecl)){
3366+
diagnose(abiDecl->getLoc(), diag::attr_abi_incompatible_kind,
3367+
abiDecl->getDescriptiveKind());
3368+
attr->setInvalid();
3369+
}
3370+
3371+
Attributes.add(attr);
33633372
}
33643373

33653374
break;

test/attr/attr_abi.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ struct CustomAttrPropertyWrapper {
12851285
}
12861286
12871287
// CustomAttr for attached macro -- see Macros/macro_expand_peers.swift
1288+
// Freestanding macro in @abi -- see Macros/macro_expand.swift
12881289
12891290
// CustomAttr for result builder -- banned in '@abi'
12901291
// Has no ABI impact on either a parameter or a decl.

0 commit comments

Comments
 (0)