swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.34k forks source link

[SR-2364] CodeCompletion test crash in #if directive #44971

Open 41412bb9-c79a-4f5a-8a7f-383cb40aa74b opened 8 years ago

41412bb9-c79a-4f5a-8a7f-383cb40aa74b commented 8 years ago
Previous ID SR-2364
Radar None
Original Reporter @rintaro
Type Bug
Environment Swift version 3.0-dev (LLVM 17c4c6cf7a, Clang 4ca9e01a7c, Swift b3819c6783) Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | CodeCompletion | |Labels | Bug, CompilerCrash | |Assignee | @rintaro | |Priority | Medium | md5: b1d867885be2d565f2b6ac2fed316aa2

Issue Description:

test_pound_if.swift:

#if true
#^TOKEN^#
#else
#endif
$ ../build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift-ide-test -code-completion -source-filename test_pound_if.swift -code-completion-token=TOKEN
found code completion token TOKEN at offset 9
found code completion token TOKEN at offset 9
invalid IfConfigStmt end location
(#if_stmt
  (#if:
    (boolean_literal_expr type='<null>' value=true)
    (elements
      (top_level_code_decl
        (brace_stmt))
))0  swift-ide-test  0x0000000002f49198 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift-ide-test  0x0000000002f47996 llvm::sys::RunSignalHandlers() + 54
2  swift-ide-test  0x0000000002f49cc6
3  libpthread.so.0 0x00007f00d911cd10
4  libc.so.6       0x00007f00d78e41c7 gsignal + 55
5  libc.so.6       0x00007f00d78e5e2a abort + 362
6  swift-ide-test  0x0000000000bbbb03
7  swift-ide-test  0x0000000000bd0ffb
8  swift-ide-test  0x0000000000bcf7f6
9  swift-ide-test  0x0000000000bcf3f4 swift::Decl::walk(swift::ASTWalker&) + 20
10 swift-ide-test  0x0000000000c6a17e swift::SourceFile::walk(swift::ASTWalker&) + 174
11 swift-ide-test  0x0000000000bb20c4 swift::verify(swift::SourceFile&) + 52
12 swift-ide-test  0x00000000008ca0c3 swift::Parser::parseTopLevel() + 563
13 swift-ide-test  0x00000000008ff160 swift::parseIntoSourceFile(swift::SourceFile&, unsigned int, bool*, swift::SILParserState*, swift::PersistentParserState*, swift::DelayedParsingCallbacks*) + 208
14 swift-ide-test  0x00000000007aa646 swift::CompilerInstance::performSema() + 3254
15 swift-ide-test  0x000000000074d2d0 main + 34704
16 libc.so.6       0x00007f00d78cfac0 __libc_start_main + 240
17 swift-ide-test  0x0000000000741639 _start + 41
Stack dump:
0.  Program arguments: ../build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift-ide-test -code-completion -source-filename test_pound_if.swift -code-completion-token=TOKEN 
1.  With parser at source location: test_pound_if.swift:5:1
2.  While walking into decl declaration 0x5445470 at test_pound_if.swift:1:1
Aborted (core dumped)

Doesn't crash if it's in some declaration:

class C {
#if true
#^TOKEN^#
#else
#endif
}

or without #else:

#if true
#^TOKEN^#
#endif
benlangmuir commented 7 years ago

When this is fixed, we should fix up the test case disabled in https://github.com/apple/swift/pull/5211.

41412bb9-c79a-4f5a-8a7f-383cb40aa74b commented 6 years ago

https://github.com/apple/swift/pull/18354