swiftlang / swift

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

[SR-10196] Swift 5.0 bug #52596

Open swift-ci opened 5 years ago

swift-ci commented 5 years ago
Previous ID SR-10196
Radar None
Original Reporter mscott (JIRA User)
Type Bug
Environment Ubuntu 18.04 in Windows
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 9ff1106fc320fb02a1266b943dba6f90

Issue Description:

import Foundation
struct BIG{ var w=[Int32](repeating: 0,count: 10); init() {}}
struct FP{var x:BIG; var xes:Int32; init(){x=BIG(); xes=1}}
struct FP2{var a:FP; var b:FP; init(){a=FP(); b=FP()}}
struct FP4 {var a:FP2; var b:FP2; init(){a=FP2(); b=FP2()}}
struct ECP4 {var x:FP4; var y:FP4; var z:FP4; init(){x=FP4(); y=FP4(); z=FP4()}}
let Q=ECP4();

Crashes:-

Stack dump:

  1. Program arguments: /swift-5.0/usr/bin/swift -frontend -interpret mytest.swift -disable-objc-interop -color-diagnostics -module-name mytest
    #0 0x00000000042420c4 PrintStackTraceSignalHandler(void*) (/swift-5.0/usr/bin/swift+0x42420c4)
    #1 0x000000000423fe4e llvm::sys::RunSignalHandlers() (/swift-5.0/usr/bin/swift+0x423fe4e)
    #2 0x0000000004242282 SignalHandler(int) (/swift-5.0/usr/bin/swift+0x4242282)
    #3 0x00007f1171df2890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
    #4 0x00007f1172170069
    #5 0x0000000000c6f9d9 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef\<llvm::GenericValue>) (/swift-5.0/usr/bin/swift+0xc6f9d9)
    #6 0x0000000000c73a90 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector\<std::*cxx11::basic_string\<char, std::char_traits\<char>, std::allocator\<char> >, std::allocator\<std::_cxx11::basic_string\<char, std::char_traits\<char>, std::allocator\<char> > > > const&, char const* const*) (/swift-5.0/usr/bin/swift+0xc73a90)
    #7 0x00000000004eb8f0 swift::RunImmediately(swift::CompilerInstance&, std::vector\<std::cxx11::basic_string\<char, std::char_traits\<char>, std::allocator\<char> >, std::allocator\<std::_cxx11::basic_string\<char, std::char_traits\<char>, std::allocator\<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) (/swift-5.0/usr/bin/swift+0x4eb8f0)
    #8 0x00000000004c1fe3 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef\<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/swift-5.0/usr/bin/swift+0x4c1fe3)
    #9 0x00000000004bd809 swift::performFrontend(llvm::ArrayRef\<char const*>, char const*, void*, swift::FrontendObserver\
    ) (/swift-5.0/usr/bin/swift+0x4bd809)
    #10 0x000000000046e670 main (/swift-5.0/usr/bin/swift+0x46e670)
    #11 0x00007f11701e1b97 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b97)
    #12 0x000000000046ca8a _start (/swift-5.0/usr/bin/swift+0x46ca8a)
    Segmentation fault (core dumped)
belkadan commented 5 years ago

Does it crash if you compile and run the code as separate steps, instead of using the interpreter?

swift-ci commented 5 years ago

Comment by Michael Scott (JIRA)

I execute it from the terminal command line as

$ swift mytest.swift

Drop the xes parameter from struct FP, and it works

Replace

let Q=ECP4();

with

public func test() {
let Q=ECP4();
}
test()

and it works.

Something has busted the stack.

belkadan commented 5 years ago

Yes, but if you do

$ swiftc mytest.swift
$ ./mytest

does it still crash? That'll tell whether it's a JIT-specific bug or something generally wrong with the compiler.

(It's not failing on macOS with either the JIT or a normal compile.)

swift-ci commented 5 years ago

Comment by Michael Scott (JIRA)

Ah, now it works.

belkadan commented 5 years ago

Okay, so we have a Linux-specific JIT bug. :-( @lhames, is there any additional information we can extract here?

lhames commented 5 years ago

I'm afraid not at the moment.

Michael – do you have a +asserts build of LLVM? If so, does anything trigger for this test case?

We could also consider adding a debugging option to the swift interpreter to dump JIT'd object files for inspection.

swift-ci commented 5 years ago

Comment by Michael Scott (JIRA)

No, Sorry. Rebuilding swift LLVM is beyond my capabilities!