Skip to content

Commit c0d0cf5

Browse files
committed
Parser: Reject @cdecl attributes with the string format
1 parent 12acb5e commit c0d0cf5

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
@@ -2989,14 +2989,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
29892989
}
29902990

29912991
case DeclAttrKind::CDecl: {
2992-
if (!AttrName.starts_with("_") &&
2993-
2994-
// Backwards support for @cdecl("stringId"). Remove before enabling in
2995-
// production so we accept only the identifier format.
2996-
lookahead<bool>(1, [&](CancellableBacktrackingScope &) {
2997-
return Tok.isNot(tok::string_literal);
2998-
})) {
2999-
2992+
if (!AttrName.starts_with("_")) {
30002993
std::optional<StringRef> CName;
30012994
if (consumeIfAttributeLParen()) {
30022995
// Custom C name.
@@ -3107,10 +3100,9 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
31073100
Attributes.add(new (Context) SILGenNameAttr(AsmName.value(), Raw, AtLoc,
31083101
AttrRange, /*Implicit=*/false));
31093102
else if (DK == DeclAttrKind::CDecl) {
3110-
bool underscored = AttrName.starts_with("_");
31113103
Attributes.add(new (Context) CDeclAttr(AsmName.value(), AtLoc,
31123104
AttrRange, /*Implicit=*/false,
3113-
/*isUnderscored*/underscored));
3105+
/*isUnderscored*/true));
31143106
} else if (DK == DeclAttrKind::Expose) {
31153107
for (auto *EA : Attributes.getAttributes<ExposeAttr>()) {
31163108
// 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)