Skip to content

Commit 81bc136

Browse files
committed
Correct swift_bridge duplicate attribute warning logic
The swift_bridge attribute warns when the attribute is applied multiple times to the same declaration. However, it warns about the arguments being different to the attribute without ever checking if the arguments actually are different. If the arguments are different, diagnose, otherwise silently accept the code. Either way, drop the duplicated attribute.
1 parent e771614 commit 81bc136

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5751,9 +5751,11 @@ static void handleSwiftBridge(Sema &S, Decl *D, const ParsedAttr &AL) {
57515751
if (!S.checkStringLiteralArgumentAttr(AL, 0, BT))
57525752
return;
57535753

5754-
// Don't duplicate annotations that are already set.
5755-
if (D->hasAttr<SwiftBridgeAttr>()) {
5756-
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
5754+
// Warn about duplicate attributes if they have different arguments, but drop
5755+
// any duplicate attributes regardless.
5756+
if (const auto *Other = D->getAttr<SwiftBridgeAttr>()) {
5757+
if (Other->getSwiftType() != BT)
5758+
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
57575759
return;
57585760
}
57595761

clang/test/SemaObjC/attr-swift_bridge.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ @protocol P
3131
typedef NSArray *NSArrayAlias __attribute__((__swift_bridge__("ArrayAlias")));
3232

3333
struct __attribute__((__swift_bridge__("StructT"))) T {};
34+
35+
// Duplicate attributes with the same arguments are fine.
36+
struct __attribute__((swift_bridge("foo"), swift_bridge("foo"))) S;
37+
// Duplicate attributes with different arguments are not.
38+
struct __attribute__((swift_bridge("foo"), swift_bridge("bar"))) S; // expected-warning {{attribute 'swift_bridge' is already applied with different arguments}}

0 commit comments

Comments
 (0)