Skip to content

Commit 0198585

Browse files
committed
Diagnose use of @_silgen_name and @abi together
1 parent d02c414 commit 0198585

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
@@ -8141,5 +8141,10 @@ ERROR(attr_abi_mismatched_var,none,
81418141
"no match for %select{%kind0 in the ABI|ABI %kind0}1",
81428142
(ValueDecl *, /*isABI=*/bool))
81438143

8144+
ERROR(attr_abi_incompatible_with_silgen_name,none,
8145+
"cannot use '@_silgen_name' and '@abi' on the same %0 because they serve "
8146+
"the same purpose",
8147+
(DescriptiveDeclKind))
8148+
81448149
#define UNDEFINE_DIAGNOSTIC_MACROS
81458150
#include "DefineDiagnosticMacros.h"

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,11 @@ void AttributeChecker::visitSILGenNameAttr(SILGenNameAttr *A) {
26452645
diagnose(A->getLocation(), diag::reserved_runtime_symbol_name,
26462646
A->Name);
26472647
}
2648+
2649+
if (D->getAttrs().hasAttribute<ABIAttr>()) {
2650+
diagnoseAndRemoveAttr(A, diag::attr_abi_incompatible_with_silgen_name,
2651+
D->getDescriptiveKind());
2652+
}
26482653
}
26492654

26502655
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)