From cbcfb37f96325cd38021d4ba3087071b56c058be Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Wed, 28 Feb 2024 22:21:43 +0000 Subject: [PATCH] [Parse] Fix a couple of SourceRanges These should point to the last token of the attribute, not the token that follows. rdar://123405070 --- lib/Parse/ParseDecl.cpp | 4 ++-- test/SourceKit/Misc/rdar123405070.swift | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/SourceKit/Misc/rdar123405070.swift diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 76ef85ecd7bed..dbe39b9b5cf85 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -1506,7 +1506,7 @@ bool Parser::parseExternAttribute(DeclAttributes &Attributes, return false; } - auto AttrRange = SourceRange(Loc, Tok.getLoc()); + auto AttrRange = SourceRange(Loc, rParenLoc); // Reject duplicate attributes with the same kind. if (ExternAttr::find(Attributes, kind)) { @@ -2329,7 +2329,7 @@ bool Parser::parseBackDeployedAttribute(DeclAttributes &Attributes, } assert(!PlatformAndVersions.empty()); - auto AttrRange = SourceRange(Loc, Tok.getLoc()); + auto AttrRange = SourceRange(Loc, RightLoc); for (auto &Item : PlatformAndVersions) { Attributes.add(new (Context) BackDeployedAttr(AtLoc, AttrRange, Item.first, Item.second, diff --git a/test/SourceKit/Misc/rdar123405070.swift b/test/SourceKit/Misc/rdar123405070.swift new file mode 100644 index 0000000000000..81fafb3efb075 --- /dev/null +++ b/test/SourceKit/Misc/rdar123405070.swift @@ -0,0 +1,10 @@ +// RUN: %sourcekitd-test -req=open %s -- %s +// Test that this doesn't crash sourcekitd + +@_backDeploy(before: macOS 14.0) +@inline(never) +public func foo() {} + +@_extern(wasm, module: "b", name: "c") +@_extern(c) +private func bar()