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

NSDecimalDivide() crashes on Linux with certain inputs #595

Open
zcohan opened this issue May 6, 2024 · 3 comments
Open

NSDecimalDivide() crashes on Linux with certain inputs #595

zcohan opened this issue May 6, 2024 · 3 comments
Assignees
Labels
bug Something isn't working linux Issue regarding compiling/running on Linux

Comments

@zcohan
Copy link

zcohan commented May 6, 2024

Description

Dividing particular Decimal numbers causes a crash (in NSDecimalDivide) on Linux.

Reproduction

import Foundation

let firstNumber: Decimal = 1147858867
let secondNumber: Decimal = 4294967295
let division = firstNumber / secondNumber

print(division) // we never make it here

Stack dump

Stack dump:
0.	Program arguments: /swift/5.10.0/usr/bin/swift-frontend -frontend -interpret test.swift -disable-objc-interop -color-diagnostics -new-driver-path /swift/5.10.0/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /swift/5.10.0/usr/lib/swift -module-name test -plugin-path /swift/5.10.0/usr/lib/swift/host/plugins -plugin-path /swift/5.10.0/usr/local/lib/swift/host/plugins
1.	Swift version 5.10 (swift-5.10-RELEASE)
2.	Compiling with the current language version
3.	While running user code "test.swift"
 #0 0x000061870b881623 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/swift/5.10.0/usr/bin/swift-frontend+0x61b7623)
 apple/swift#1 0x000061870b87f5de llvm::sys::RunSignalHandlers() (/swift/5.10.0/usr/bin/swift-frontend+0x61b55de)
 apple/swift#2 0x000061870b88199a SignalHandler(int) Signals.cpp:0:0
 apple/swift#3 0x0000736cc1645320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
 apple/swift#4 0x0000736cbe958ead $s10Foundation15NSDecimalDivideyAA0B6NumberC16CalculationErrorOSpyAA7DecimalVG_SPyAHGAjD12RoundingModeOtFTf4nnnd_n crtstuff.c:0:0
 apple/swift#5 0x0000736cbe94bec1 $s10Foundation7DecimalV1doiyA2C_ACtFZ (/swift/5.10.0/usr/lib/swift/linux/libFoundation.so+0x34bec1)
 apple/swift#6 0x0000736cc28910f2 
 apple/swift#7 0x000061870649d31d llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, llvm::Optional<llvm::StringRef>) (/swift/5.10.0/usr/bin/swift-frontend+0xdd331d)
 apple/swift#8 0x00006187063833f8 swift::SwiftJIT::runMain(llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>) (/swift/5.10.0/usr/bin/swift-frontend+0xcb93f8)
 apple/swift#9 0x0000618706381223 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 const&, swift::SILOptions const&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>&&) (/swift/5.10.0/usr/bin/swift-frontend+0xcb7223)
apple/swift#10 0x000061870632dea6 processCommandLineAndRunImmediately(swift::CompilerInstance&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>&&, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::FrontendObserver*, int&) FrontendTool.cpp:0:0
apple/swift#11 0x0000618706329102 performCompileStepsPostSILGen(swift::CompilerInstance&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
apple/swift#12 0x000061870632818b swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/swift/5.10.0/usr/bin/swift-frontend+0xc5e18b)
apple/swift#13 0x000061870633b4ba withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
apple/swift#14 0x000061870632c4f8 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
apple/swift#15 0x0000618706329f7d swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/swift/5.10.0/usr/bin/swift-frontend+0xc5ff7d)
apple/swift#16 0x00006187061c32c0 swift::mainEntry(int, char const**) (/swift/5.10.0/usr/bin/swift-frontend+0xaf92c0)
apple/swift#17 0x0000736cc162a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
apple/swift#18 0x0000736cc162a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
apple/swift#19 0x00006187061c23f5 _start (/swift/5.10.0/usr/bin/swift-frontend+0xaf83f5)

💣 Program crashed: Illegal instruction at 0x0000736cbe958ead

Thread 0 "swift-frontend" crashed:

0 0x0000736cbe958ead specialized NSDecimalDivide(_:_:_:_:) + 8781 in libFoundation.so

Backtrace took 0.06s

Expected behavior

I expect "0.26725671888963708628193407465748816604" to be printed to the console. This is what happens when running on a Mac.

Environment

Swift version 5.10 (swift-5.10-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional information

No response

@zcohan zcohan added the bug Something isn't working label May 6, 2024
@finagolfin
Copy link

I can reproduce on Android AArch64: this is a bug in swift-corelibs-foundation, which is not used on macOS.

@AnthonyLatsis
Copy link

@parkera Please transfer this.

@AnthonyLatsis AnthonyLatsis added the linux Issue regarding compiling/running on Linux label May 7, 2024
@parkera parkera transferred this issue from apple/swift May 7, 2024
@parkera
Copy link
Member

parkera commented May 7, 2024

@iCharlesHu you were looking at Decimal recently - can you investigate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linux Issue regarding compiling/running on Linux
Projects
None yet
Development

No branches or pull requests

5 participants