Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9313] Call to non-void noreturn C function causes Swift compiler to crash #51783

Closed
swift-ci opened this issue Nov 21, 2018 · 4 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself IRGen LLVM IR generation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9313
Radar rdar://problem/46264442
Original Reporter SvyatoslavScherbina (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment
$ swiftc -version
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin17.7.0
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, ClangImporter, IRGen
Assignee @aschwaighofer
Priority Medium

md5: 027fde34c019bd0ab617286d1db2645e

Issue Description:

1.h:

int foo() __attribute__((noreturn));

1.swift:

foo()

When compiling this with

$ swiftc 1.swift -import-objc-header 1.h

Swift compiler crashes while generating bitcode with "Cannot allocate unsized type":

Cannot allocate unsized type
  %3 = alloca void, align 8
loading unsized types is not allowed
  load void, void* %3, align 8
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken function found, compilation aborted!
0  swift                    0x0000000109f1c59a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000109f1bd4e SignalHandler(int) + 302
2  libsystem_platform.dylib 0x00007fff6688cf5a _sigtramp + 26
3  libsystem_platform.dylib 0x00007ffee9adeaa8 _sigtramp + 2200247144
4  libsystem_c.dylib        0x00007fff6662a1ae abort + 127
5  swift                    0x00000001061a1a67 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_1::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) + 519
6  swift                    0x0000000109ed01c8 llvm::report_fatal_error(llvm::Twine const&, bool) + 280
7  swift                    0x0000000109ed00ab llvm::report_fatal_error(char const*, bool) + 43
8  swift                    0x0000000109e97736 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 54
9  swift                    0x0000000109e3df9e llvm::FPPassManager::runOnFunction(llvm::Function&) + 446
10 swift                    0x0000000109e462b3 llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 115
11 swift                    0x0000000109e461a8 llvm::legacy::FunctionPassManager::run(llvm::Function&) + 392
12 swift                    0x0000000106368198 swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 4504
13 swift                    0x00000001061ae242 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 49170
14 swift                    0x000000010619ed35 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7717
15 swift                    0x0000000106144965 main + 1349
16 libdyld.dylib            0x00007fff6657e015 start + 1
17 libdyld.dylib            0x0000000000000011 start + 2577932285
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file 1.swift -target x86_64-apple-darwin17.7.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -import-objc-header /var/folders/_c/4nxwq8z91h331tr5pq1b29vh0000gn/T/1-254c9b.pch -module-name main -o /var/folders/_c/4nxwq8z91h331tr5pq1b29vh0000gn/T/1-2c0233.o 
1.  Running pass 'Module Verifier' on function '@main'
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

The error may differ if foo has different return type. E.g. int* return type causes the compiler to crash with segmentation fault.

@belkadan
Copy link
Contributor

Hm. We can't just import the function as returning Void because the return type might affect the calling convention (thinking of large struct returns). Maybe we need something down in IRGen?

@aschwaighofer
Copy link
Member

Fixed by #23112

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Aug 9, 2019

SvyatoslavScherbina (JIRA User), Could you verify if the problem is fixed and if so move the JIRA to "Closed"?

Thanks!
Anna

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 9, 2019

Comment by Svyatoslav Scherbina (JIRA)

I can confirm that the problem is fixed. Thank you!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

3 participants