Skip to content

Commit 33bc9ae

Browse files
committed
Diagnose use of @_silgen_name and @abi together
1 parent a5185af commit 33bc9ae

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

8127+
ERROR(attr_abi_incompatible_with_silgen_name,none,
8128+
"cannot use '@_silgen_name' and '@abi' on the same %0 because they serve "
8129+
"the same purpose",
8130+
(DescriptiveDeclKind))
8131+
81278132
#define UNDEFINE_DIAGNOSTIC_MACROS
81288133
#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
@@ -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)