Skip to content

Commit 28f8d0c

Browse files
author
Harlan Haskins
committed
Fix #sourceLocation and fix FileCheck tests
1 parent 7107e98 commit 28f8d0c

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

lib/AST/InlinableText.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,20 @@ static void appendRange(
218218

219219
// Skip over #sourceLocation's in the file.
220220
if (token.is(tok::pound_sourceLocation)) {
221-
lexer.lex(token);
222221

223-
// Skip from the left paren to the right paren.
224-
assert(token.is(tok::l_paren));
222+
// Append the text leading up to the #sourceLocation
223+
auto charRange = CharSourceRange(
224+
sourceMgr, nonCommentStart, token.getLoc());
225+
StringRef text = sourceMgr.extractText(charRange);
226+
scratch.append(text.begin(), text.end());
227+
228+
// Skip to the right paren. We know the AST is already valid, so there's
229+
// definitely a right paren.
225230
while (!token.is(tok::r_paren)) {
226231
lexer.lex(token);
227232
}
228233

229-
nonCommentStart = Lexer::getLocForEndOfToken(sourceMgr, token.getLoc());
234+
nonCommentStart = Lexer::getLocForEndOfToken(sourceMgr, token);
230235
}
231236

232237
if (token.is(tok::comment)) {

test/ModuleInterface/if-configs.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface)
88
// RUN: %FileCheck %s < %t.swiftinterface
99

10-
// CHECK: func hasClosureDefaultArgWithComplexNestedPoundIfs(_ x: () -> Swift.Void = {
10+
// CHECK-LABEL: func hasClosureDefaultArgWithComplexNestedPoundIfs(_ x: () -> Swift.Void = {
1111
// CHECK-NOT: #if NOT_PROVIDED
1212
// CHECK-NOT: print("should not exist")
1313
// CHECK-NOT: #elseif !NOT_PROVIDED
@@ -35,7 +35,7 @@ public func hasClosureDefaultArgWithComplexNestedPoundIfs(_ x: () -> Void = {
3535
}) {
3636
}
3737

38-
// CHECK: func hasClosureDefaultArgWithComplexPoundIf(_ x: () -> Swift.Void = {
38+
// CHECK-LABEL: func hasClosureDefaultArgWithComplexPoundIf(_ x: () -> Swift.Void = {
3939
// CHECK-NOT: #if NOT_PROVIDED
4040
// CHECK-NOT: print("should not exist")
4141
// CHECK-NOT: #else
@@ -64,7 +64,7 @@ public func hasClosureDefaultArgWithComplexPoundIf(_ x: () -> Void = {
6464
}) {
6565
}
6666

67-
// CHECK: func hasClosureDefaultArgWithMultilinePoundIfCondition(_ x: () -> Swift.Void = {
67+
// CHECK-LABEL: func hasClosureDefaultArgWithMultilinePoundIfCondition(_ x: () -> Swift.Void = {
6868
// CHECK-NOT: #if (
6969
// CHECK-NOT: !false && true
7070
// CHECK-NOT: )
@@ -95,7 +95,7 @@ public func hasClosureDefaultArgWithMultilinePoundIfCondition(_ x: () -> Void =
9595
}) {
9696
}
9797

98-
// CHECK: func hasClosureDefaultArgWithSinglePoundIf(_ x: () -> Swift.Void = {
98+
// CHECK-LABEL: func hasClosureDefaultArgWithSinglePoundIf(_ x: () -> Swift.Void = {
9999
// CHECK-NOT: #if true
100100
// CHECK: print("true")
101101
// CHECK-NOT: #else
@@ -111,24 +111,7 @@ public func hasClosureDefaultArgWithSinglePoundIf(_ x: () -> Void = {
111111
}) {
112112
}
113113

114-
// CHECK: func hasIfCompilerCheck
115-
// CHECK: #if compiler(>=5.3)
116-
// CHECK-NEXT: return true
117-
// CHECK-NEXT: #else
118-
// CHECK-NEXT: return false
119-
// CHECK-NEXT: #endif
120-
@_alwaysEmitIntoClient
121-
public func hasIfCompilerCheck(_ x: () -> Bool = {
122-
#if compiler(>=5.3)
123-
return true
124-
#else
125-
return false
126-
#endif
127-
}) {
128-
}
129-
130-
// CHECK: func hasComments
131-
// CHECK-NOT: #if NOT_PROVIDED
114+
// CHECK-LABEL: func hasComments
132115
// CHECK: print(
133116
// CHECK: "this should show up"
134117
// CHECK-NOT: comment! don't mess up indentation!
@@ -146,7 +129,7 @@ public func hasIfCompilerCheck(_ x: () -> Bool = {
146129
// CHECK-NOT: comment!
147130
// CHECK: return true
148131
@inlinable
149-
public func hasComments() -> Bool {
132+
public func hasComments(_ x: () -> Bool = {
150133
/* comment! */ // comment!
151134
#if NOT_PROVIDED
152135
// comment!
@@ -178,4 +161,21 @@ public func hasComments() -> Bool {
178161
// comment!
179162
return/* comment! */true/* comment! */
180163
#endif
164+
}) {
165+
}
166+
167+
// CHECK-LABEL: func hasIfCompilerCheck
168+
// CHECK: #if compiler(>=5.3)
169+
// CHECK-NEXT: return true
170+
// CHECK-NEXT: #else
171+
// CHECK-NEXT: return false
172+
// CHECK-NEXT: #endif
173+
@_alwaysEmitIntoClient
174+
public func hasIfCompilerCheck(_ x: () -> Bool = {
175+
#if compiler(>=5.3)
176+
return true
177+
#else
178+
return false
179+
#endif
180+
}) {
181181
}

0 commit comments

Comments
 (0)