Skip to content

Commit 8d428c4

Browse files
committed
Diagnose use of @_silgen_name and @abi together
1 parent aa10ce3 commit 8d428c4

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
@@ -2657,6 +2657,11 @@ void AttributeChecker::visitSILGenNameAttr(SILGenNameAttr *A) {
26572657
diagnose(A->getLocation(), diag::reserved_runtime_symbol_name,
26582658
A->Name);
26592659
}
2660+
2661+
if (D->getAttrs().hasAttribute<ABIAttr>()) {
2662+
diagnoseAndRemoveAttr(A, diag::attr_abi_incompatible_with_silgen_name,
2663+
D->getDescriptiveKind());
2664+
}
26602665
}
26612666

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