Skip to content

Commit dc307da

Browse files
committed
Diagnose use of @_silgen_name and @abi together
1 parent 052d1e7 commit dc307da

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

8117+
ERROR(attr_abi_incompatible_with_silgen_name,none,
8118+
"cannot use '@_silgen_name' and '@abi' on the same %0 because they serve "
8119+
"the same purpose",
8120+
(DescriptiveDeclKind))
8121+
81178122
#define UNDEFINE_DIAGNOSTIC_MACROS
81188123
#include "DefineDiagnosticMacros.h"

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,11 @@ void AttributeChecker::visitSILGenNameAttr(SILGenNameAttr *A) {
26352635
diagnose(A->getLocation(), diag::reserved_runtime_symbol_name,
26362636
A->Name);
26372637
}
2638+
2639+
if (D->getAttrs().hasAttribute<ABIAttr>()) {
2640+
diagnoseAndRemoveAttr(A, diag::attr_abi_incompatible_with_silgen_name,
2641+
D->getDescriptiveKind());
2642+
}
26382643
}
26392644

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

test/attr/attr_abi.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ func async01() async {}
121121
@abi(func async11() async)
122122
func async11() async {}
123123
124+
//
125+
// Miscellaneous function checking
126+
//
127+
128+
@_silgen_name("conflictingAttrsSilgenName")
129+
@abi(func conflictingAttrsABI())
130+
func conflictingAttrsAPI() {} // expected-error@-2 {{cannot use '@_silgen_name' and '@abi' on the same global function because they serve the same purpose}} {{1-44=}}
131+
124132
//
125133
// PBD shape checking
126134
//

0 commit comments

Comments
 (0)