Skip to content

[LoadableByAddr] unchecked_bitwise_cast error. #71744

Closed
@fibrechannelscsi

Description

@fibrechannelscsi

Description

The attached code fails to compile with certain nightly toolchains when the test is run in Release mode. It compiles and runs successfully in Debug mode.

This requires two internal Packages in addition to the actual test file. As such, this reproducer has been archived and attached.

uncheckedBitCast.zip

Reproduction

Extract the attached file into a new directory and run swift test in release mode. For example:
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-01-30-a.xctoolchain/usr/bin/swift test -c release

Opening the enclosed attachment and building the test target in Release mode in Xcode will also work.

Upon building, this will generate about 50KB of SIL code as part of the error message (not attached). The test won't actually execute.

Expected behavior

The compilation should complete successfully, and the test should complete.

Environment

The 2024-01-30a and 2024-02-14a nightly toolchains generate this error message, but the 2024-01-22a toolchain does not.

Additional information

Stack trace (excluding the SIL-related error message):

1.	Apple Swift version 5.11-dev (LLVM aee6ede4f903b20, Swift 79fcb5e2e20760f)
2.	Compiling with the current language version
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { IRGen Preparation } on SIL for ReproducerTests)
4.	While running pass #64 SILModuleTransform "LoadableByAddress".
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000109d67e40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109d6660c llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109d68488 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018b12aa24 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018b0fbc28 pthread_kill + 288
5  libsystem_c.dylib        0x000000018b009ae8 abort + 180
6  swift-frontend           0x00000001049a504c PrettyStackTraceFrontend::~PrettyStackTraceFrontend() + 0
7  swift-frontend           0x0000000109ce7470 llvm::report_fatal_error(llvm::Twine const&, bool) + 256
8  swift-frontend           0x0000000109ce7370 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9  swift-frontend           0x0000000104f125d8 swift::SILInstructionVisitor<(anonymous namespace)::AssignAddressToDef, void>::visitUncheckedValueCastInst(swift::UncheckedValueCastInst*) + 0
10 swift-frontend           0x0000000104f0ef14 (anonymous namespace)::AssignAddressToDef::rewriteValue() + 7780
11 swift-frontend           0x0000000104ef77d0 runPeepholesAndReg2Mem(swift::SILPassManager*, swift::SILModule*, swift::irgen::IRGenModule*) + 4588
12 swift-frontend           0x0000000104ef6324 (anonymous namespace)::LoadableByAddress::run() + 13864
13 swift-frontend           0x0000000105358e74 swift::SILPassManager::runModulePass(unsigned int) + 848
14 swift-frontend           0x000000010535b118 swift::SILPassManager::execute() + 624
15 swift-frontend           0x0000000105355bf8 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
16 swift-frontend           0x0000000105355b7c swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
17 swift-frontend           0x0000000105390c1c swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
18 swift-frontend           0x0000000105371508 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 204
19 swift-frontend           0x0000000105355dd0 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
20 swift-frontend           0x0000000104e788e0 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::GlobalVariable**) + 1256
21 swift-frontend           0x00000001049a0da8 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 272
22 swift-frontend           0x000000010499d3d0 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1416
23 swift-frontend           0x000000010499ca88 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1184
24 swift-frontend           0x00000001049ad444 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
25 swift-frontend           0x000000010499ed78 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
26 swift-frontend           0x000000010499ddd4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2336
27 swift-frontend           0x00000001047d7b50 swift::mainEntry(int, char const**) + 3096
28 dyld                     0x000000018ada3f28 start + 2236

Note that there are certain modifications to the code that will cause the compilation to succeed. For example, commenting out r += n["b"]![1.0]!; in T.swift. All three += operations are required to generate this error.

Metadata

Metadata

Assignees

Labels

AutoDiffIRGenLLVM IR generationSILOptimizerArea → compiler: SIL optimization passesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwaremultiple modulesFlag: An issue whose reproduction requires multiple modulesoptimized onlyFlag: An issue whose reproduction requires optimized compilationswift 6.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions