Skip to content

Commit 1f115ad

Browse files
authored
Merge pull request #72009 from hamishknight/another-attr-fix
[Parse] Fix a couple more attribute SourceRanges
2 parents 8a25294 + 5d39788 commit 1f115ad

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3498,7 +3498,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
34983498
assert(!OriginalModuleName.empty());
34993499
assert(!PlatformAndVersions.empty());
35003500
assert(NK == NextSegmentKind::PlatformVersion);
3501-
AttrRange = SourceRange(Loc, Tok.getLoc());
3501+
AttrRange = SourceRange(Loc, RightLoc);
35023502
for (auto &Item: PlatformAndVersions) {
35033503
Attributes.add(new (Context) OriginallyDefinedInAttr(AtLoc, AttrRange,
35043504
OriginalModuleName,
@@ -3944,28 +3944,30 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
39443944
return makeParserSuccess();
39453945
}
39463946

3947-
if (!consumeIf(tok::r_paren)) {
3947+
SourceLoc rParenLoc;
3948+
if (!consumeIf(tok::r_paren, rParenLoc)) {
39483949
diagnose(Tok.getLoc(), diag::attr_expected_rparen,
39493950
AttrName, /*isModifier*/false);
39503951
return makeParserSuccess();
39513952
}
39523953

39533954
attr = new (Context) RawLayoutAttr(size, align,
3954-
AtLoc, SourceRange(Loc, Tok.getLoc()));
3955+
AtLoc, SourceRange(Loc, rParenLoc));
39553956
} else if (firstLabel.is("like")) {
39563957
// @_rawLayout(like: T)
39573958
auto likeType = parseType(diag::expected_type);
39583959
if (likeType.isNull()) {
39593960
return makeParserSuccess();
39603961
}
3961-
if (!consumeIf(tok::r_paren)) {
3962+
SourceLoc rParenLoc;
3963+
if (!consumeIf(tok::r_paren, rParenLoc)) {
39623964
diagnose(Tok.getLoc(), diag::attr_expected_rparen,
39633965
AttrName, /*isModifier*/false);
39643966
return makeParserSuccess();
39653967
}
39663968

39673969
attr = new (Context) RawLayoutAttr(likeType.get(),
3968-
AtLoc, SourceRange(Loc, Tok.getLoc()));
3970+
AtLoc, SourceRange(Loc, rParenLoc));
39693971
} else if (firstLabel.is("likeArrayOf")) {
39703972
// @_rawLayout(likeArrayOf: T, count: N)
39713973
auto likeType = parseType(diag::expected_type);
@@ -4003,14 +4005,15 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
40034005
return makeParserSuccess();
40044006
}
40054007

4006-
if (!consumeIf(tok::r_paren)) {
4008+
SourceLoc rParenLoc;
4009+
if (!consumeIf(tok::r_paren, rParenLoc)) {
40074010
diagnose(Tok.getLoc(), diag::attr_expected_rparen,
40084011
AttrName, /*isModifier*/false);
40094012
return makeParserSuccess();
40104013
}
40114014

40124015
attr = new (Context) RawLayoutAttr(likeType.get(), count,
4013-
AtLoc, SourceRange(Loc, Tok.getLoc()));
4016+
AtLoc, SourceRange(Loc, rParenLoc));
40144017
} else {
40154018
diagnose(Loc, diag::attr_rawlayout_expected_label,
40164019
"'size', 'like', or 'likeArrayOf'");

test/SourceKit/Misc/rdar123405070.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ public func foo() {}
88
@_extern(wasm, module: "b", name: "c")
99
@_extern(c)
1010
private func bar()
11+
12+
@_originallyDefinedIn(module: "foo", macOS 5.0)
13+
@available(macOS 5.0, *)
14+
public func baz() {}
15+
16+
@_rawLayout(size: 5, alignment: 4)
17+
@available(macOS 5.0, *)
18+
struct Qux {}
19+
20+
@_rawLayout(like: Qux)
21+
@available(macOS 5.0, *)
22+
struct Flim {}
23+
24+
@_rawLayout(likeArrayOf: Qux, count: 5)
25+
@available(macOS 5.0, *)
26+
struct Flam {}

0 commit comments

Comments
 (0)