Skip to content

Commit 66a6f1d

Browse files
committed
Diagnose use of @_silgen_name and @abi together
1 parent 6e9d537 commit 66a6f1d

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

8137+
ERROR(attr_abi_incompatible_with_silgen_name,none,
8138+
"cannot use '@_silgen_name' and '@abi' on the same %0 because they serve "
8139+
"the same purpose",
8140+
(DescriptiveDeclKind))
8141+
81378142
#define UNDEFINE_DIAGNOSTIC_MACROS
81388143
#include "DefineDiagnosticMacros.h"

lib/Sema/TypeCheckAttr.cpp

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

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