Skip to content

Commit a23c658

Browse files
committed
Sema: Report the use of reserved @cdecl names
1 parent 569ca00 commit a23c658

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
@@ -2384,9 +2384,10 @@ void AttributeChecker::visitCDeclAttr(CDeclAttr *attr) {
23842384
attr);
23852385

23862386
// The standard library can use @_cdecl to implement runtime functions.
2387-
if (!canDeclareSymbolName(attr->Name, D->getModuleContext())) {
2387+
auto VD = dyn_cast<ValueDecl>(D);
2388+
if (VD && !canDeclareSymbolName(VD->getCDeclName(), D->getModuleContext())) {
23882389
diagnose(attr->getLocation(), diag::reserved_runtime_symbol_name,
2389-
attr->Name);
2390+
VD->getCDeclName());
23902391
}
23912392

23922393
// @_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)