Skip to content

Commit 9d939d0

Browse files
committed
Parser: Reject @cdecl attributes with the string format
1 parent 1099bd9 commit 9d939d0

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,14 +3009,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
30093009
}
30103010

30113011
case DeclAttrKind::CDecl: {
3012-
if (!AttrName.starts_with("_") &&
3013-
3014-
// Backwards support for @cdecl("stringId"). Remove before enabling in
3015-
// production so we accept only the identifier format.
3016-
lookahead<bool>(1, [&](CancellableBacktrackingScope &) {
3017-
return Tok.isNot(tok::string_literal);
3018-
})) {
3019-
3012+
if (!AttrName.starts_with("_")) {
30203013
std::optional<StringRef> CName;
30213014
if (consumeIfAttributeLParen()) {
30223015
// Custom C name.
@@ -3127,10 +3120,9 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
31273120
Attributes.add(new (Context) SILGenNameAttr(AsmName.value(), Raw, AtLoc,
31283121
AttrRange, /*Implicit=*/false));
31293122
else if (DK == DeclAttrKind::CDecl) {
3130-
bool underscored = AttrName.starts_with("_");
31313123
Attributes.add(new (Context) CDeclAttr(AsmName.value(), AtLoc,
31323124
AttrRange, /*Implicit=*/false,
3133-
/*isUnderscored*/underscored));
3125+
/*isUnderscored*/true));
31343126
} else if (DK == DeclAttrKind::Expose) {
31353127
for (auto *EA : Attributes.getAttributes<ExposeAttr>()) {
31363128
// A single declaration cannot have two @_exported attributes with

test/attr/attr_cdecl_official.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
// expected-error @-1 {{expected ')' in 'cdecl' attribute}}
2525
// expected-error @-2 {{expected declaration}}
2626

27+
@cdecl("oldStringStyle") func oldStringStyle() {}
28+
// expected-error @-1 {{expected C identifier in 'cdecl' attribute}}
29+
// expected-error @-2 {{expected declaration}}
30+
2731
@cdecl func defaultName() {}
2832

2933
@cdecl(noBody)

0 commit comments

Comments
 (0)