Skip to content

Commit e3257fd

Browse files
committed
[Parse] Fix empty platform condition crash
Handle the empty argument case in `getSingleSubExp`, otherwise we'd crash with an index out of bounds. rdar://83017601
1 parent 88bf210 commit e3257fd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/Parse/ParseIfConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ static llvm::VersionTuple getCanImportVersion(ArgumentList *args,
116116

117117
static Expr *getSingleSubExp(ArgumentList *args, StringRef kindName,
118118
DiagnosticEngine *D) {
119+
if (args->empty())
120+
return nullptr;
121+
119122
if (auto *unary = args->getUnlabeledUnaryExpr())
120123
return unary;
121124

test/Parse/ConditionalCompilation/basicParseErrors.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,8 @@ undefinedFunc() // expected-error {{cannot find 'undefinedFunc' in scope}}
168168
#else
169169
if true {}
170170
#endif // OK
171+
172+
// rdar://83017601 Make sure we don't crash
173+
#if canImport()
174+
// expected-error@-1 {{expected only one argument to platform condition}}
175+
#endif

0 commit comments

Comments
 (0)