mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: @cdecl functions C name defaults to the Swift name
This commit is contained in:
@@ -4543,7 +4543,10 @@ StringRef ValueDecl::getCDeclName() const {
|
||||
|
||||
// Handle explicit cdecl attributes.
|
||||
if (auto cdeclAttr = getAttrs().getAttribute<CDeclAttr>()) {
|
||||
return cdeclAttr->Name;
|
||||
if (!cdeclAttr->Name.empty())
|
||||
return cdeclAttr->Name;
|
||||
else
|
||||
return getBaseIdentifier().str();
|
||||
}
|
||||
|
||||
return "";
|
||||
|
||||
@@ -1307,7 +1307,7 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
|
||||
if (!clangMangling.empty())
|
||||
return clangMangling;
|
||||
}
|
||||
return CDeclA->Name.str();
|
||||
return getDecl()->getCDeclName().str();
|
||||
}
|
||||
|
||||
if (SKind == ASTMangler::SymbolKind::DistributedThunk) {
|
||||
|
||||
@@ -2387,8 +2387,8 @@ void AttributeChecker::visitCDeclAttr(CDeclAttr *attr) {
|
||||
diagnose(attr->getLocation(), diag::cdecl_not_at_top_level,
|
||||
attr);
|
||||
|
||||
// The name must not be empty.
|
||||
if (attr->Name.empty())
|
||||
// @_cdecl name must not be empty.
|
||||
if (attr->Name.empty() && attr->Underscored)
|
||||
diagnose(attr->getLocation(), diag::cdecl_empty_name,
|
||||
attr);
|
||||
|
||||
|
||||
@@ -33,6 +33,10 @@ func a0_simple(x: Int, bar y: Int) -> Int { return x }
|
||||
// CHECK-LABEL: // My documentation
|
||||
// CHECK-LABEL: SWIFT_EXTERN ptrdiff_t simple(ptrdiff_t x, ptrdiff_t y) SWIFT_NOEXCEPT SWIFT_WARN_UNUSED_RESULT;
|
||||
|
||||
@cdecl
|
||||
func a1_defaultName(x: Int) -> Int { return x }
|
||||
// CHECK-LABEL: SWIFT_EXTERN ptrdiff_t a1_defaultName(ptrdiff_t x) SWIFT_NOEXCEPT SWIFT_WARN_UNUSED_RESULT;
|
||||
|
||||
@cdecl("primitiveTypes")
|
||||
public func b_primitiveTypes(i: Int, ci: CInt, l: CLong, c: CChar, f: Float, d: Double, b: Bool) {}
|
||||
// CHECK-LABEL: SWIFT_EXTERN void primitiveTypes(ptrdiff_t i, int ci, long l, char c, float f, double d, bool b) SWIFT_NOEXCEPT;
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
// expected-error @-1 {{expected ')' in 'cdecl' attribute}}
|
||||
// expected-error @-2 {{expected declaration}}
|
||||
|
||||
@cdecl("") // expected-error{{@cdecl symbol name cannot be empty}}
|
||||
func emptyName(x: Int) -> Int { return x }
|
||||
@cdecl func defaultName() {}
|
||||
|
||||
@cdecl("noBody")
|
||||
func noBody(x: Int) -> Int // expected-error{{expected '{' in body of function}}
|
||||
|
||||
Reference in New Issue
Block a user