Skip to content

Commit a50aa0a

Browse files
committed
Diagnose use of @_silgen_name and @abi together
1 parent 781fb98 commit a50aa0a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8150,5 +8150,10 @@ ERROR(attr_abi_mismatched_var,none,
81508150
"no match for %select{%kind0 in the ABI|ABI %kind0}1",
81518151
(ValueDecl *, /*isABI=*/bool))
81528152

8153+
ERROR(attr_abi_incompatible_with_silgen_name,none,
8154+
"cannot use '@_silgen_name' and '@abi' on the same %0 because they serve "
8155+
"the same purpose",
8156+
(DescriptiveDeclKind))
8157+
81538158
#define UNDEFINE_DIAGNOSTIC_MACROS
81548159
#include "DefineDiagnosticMacros.h"

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,11 @@ void AttributeChecker::visitSILGenNameAttr(SILGenNameAttr *A) {
26542654
diagnose(A->getLocation(), diag::reserved_runtime_symbol_name,
26552655
A->Name);
26562656
}
2657+
2658+
if (D->getAttrs().hasAttribute<ABIAttr>()) {
2659+
diagnoseAndRemoveAttr(A, diag::attr_abi_incompatible_with_silgen_name,
2660+
D->getDescriptiveKind());
2661+
}
26572662
}
26582663

26592664
void AttributeChecker::visitUsedAttr(UsedAttr *attr) {

test/attr/attr_abi.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ func async01() async {}
124124
@abi(func async11() async)
125125
func async11() async {}
126126
127+
//
128+
// Miscellaneous function checking
129+
//
130+
131+
@_silgen_name("conflictingAttrsSilgenName")
132+
@abi(func conflictingAttrsABI())
133+
func conflictingAttrsAPI() {} // expected-error@-2 {{cannot use '@_silgen_name' and '@abi' on the same global function because they serve the same purpose}} {{1-44=}}
134+
127135
//
128136
// PBD shape checking
129137
//

0 commit comments

Comments
 (0)