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.
This commit is contained in:
Aaron Ballman 2021-02-11 07:11:27 -05:00
parent e771614bae
commit 81bc1365d8
2 changed files with 10 additions and 3 deletions

View File

@ -5751,9 +5751,11 @@ static void handleSwiftBridge(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!S.checkStringLiteralArgumentAttr(AL, 0, BT))
return;
// Don't duplicate annotations that are already set.
if (D->hasAttr<SwiftBridgeAttr>()) {
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
// Warn about duplicate attributes if they have different arguments, but drop
// any duplicate attributes regardless.
if (const auto *Other = D->getAttr<SwiftBridgeAttr>()) {
if (Other->getSwiftType() != BT)
S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
return;
}

View File

@ -31,3 +31,8 @@ __attribute__((__swift_bridge__("ProtocolP")))
typedef NSArray *NSArrayAlias __attribute__((__swift_bridge__("ArrayAlias")));
struct __attribute__((__swift_bridge__("StructT"))) T {};
// Duplicate attributes with the same arguments are fine.
struct __attribute__((swift_bridge("foo"), swift_bridge("foo"))) S;
// Duplicate attributes with different arguments are not.
struct __attribute__((swift_bridge("foo"), swift_bridge("bar"))) S; // expected-warning {{attribute 'swift_bridge' is already applied with different arguments}}