Skip to content

Commit 9e953d2

Browse files
authored
Merge pull request #82891 from xymus/cdecl-reserved-names
Sema: Report the use of reserved names by `@cdecl` functions
2 parents 7e26972 + a23c658 commit 9e953d2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,9 +2376,10 @@ void AttributeChecker::visitCDeclAttr(CDeclAttr *attr) {
23762376
attr);
23772377

23782378
// The standard library can use @_cdecl to implement runtime functions.
2379-
if (!canDeclareSymbolName(attr->Name, D->getModuleContext())) {
2379+
auto VD = dyn_cast<ValueDecl>(D);
2380+
if (VD && !canDeclareSymbolName(VD->getCDeclName(), D->getModuleContext())) {
23802381
diagnose(attr->getLocation(), diag::reserved_runtime_symbol_name,
2381-
attr->Name);
2382+
VD->getCDeclName());
23822383
}
23832384

23842385
// @_cdecl was never accepted on enums. Keep the previous diagnostic.

test/attr/attr_cdecl_official.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,6 @@ func swiftErrorProtocol(e: Error) {}
198198
func anyParam(e:Any) {}
199199
// expected-error @-1 {{global function cannot be marked '@cdecl' because the type of the parameter cannot be represented in C}}
200200
// expected-note @-2 {{protocols cannot be represented in C}}
201+
202+
@cdecl func swift_allocBox() {} // expected-warning {{symbol name 'swift_allocBox' is reserved for the Swift runtime and cannot be directly referenced without causing unpredictable behavior; this will become an error}}
203+
@cdecl(swift_allocObject) func swift_allocObject_renamed() {} // expected-warning {{symbol name 'swift_allocObject' is reserved for the Swift runtime and cannot be directly referenced without causing unpredictable behavior; this will become an error}}

0 commit comments

Comments
 (0)