Skip to content

Commit f49c594

Browse files
committed
Fix attribute insertion location in the presence of "static" and a modifier
We were incorrectly ignoring the "static" because it's not in the DeclAttributes list.
1 parent 836192b commit f49c594

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4335,7 +4335,14 @@ SourceLoc Decl::getAttributeInsertionLoc(bool forModifier) const {
43354335
return SourceLoc();
43364336

43374337
SourceLoc resultLoc = getAttrs().getStartLoc(forModifier);
4338-
return resultLoc.isValid() ? resultLoc : introDecl->getStartLoc();
4338+
if (resultLoc.isInvalid())
4339+
return introDecl->getStartLoc();
4340+
4341+
SourceLoc startLoc = introDecl->getStartLoc();
4342+
if (!forModifier && getASTContext().SourceMgr.isBefore(startLoc, resultLoc))
4343+
return startLoc;
4344+
4345+
return resultLoc;
43394346
}
43404347

43414348
/// Returns true if \p VD needs to be treated as publicly-accessible

test/Unsafe/safe.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func rethrowing(body: (UnsafeType) throws -> Void) rethrows { } // expected-warn
3030

3131
class HasStatics {
3232
// expected-note@+1{{make static method 'f' @unsafe to indicate that its use is not memory-safe}}{{3-3=@unsafe }}
33-
static func f(_: UnsafeType) { } // expected-warning{{reference to unsafe struct 'UnsafeType' [Unsafe]}}
33+
static internal func f(_: UnsafeType) { } // expected-warning{{reference to unsafe struct 'UnsafeType' [Unsafe]}}
3434
}
3535

3636
@unsafe

0 commit comments

Comments
 (0)