swift: "Stored value type does not match pointer operand type!" compiler crash
Describe the bug The following function crashes the compiler:
func setEnumOverrideIfExists<T: RawRepresentable>(for key: String, in override: [String: Any], target: inout T) where T.RawValue == UInt {
if let overrideValue = override[key] as? UInt, let overrideValue = T(rawValue: overrideValue) {
target = overrideValue
}
}
If, however, I make the following change, there is no crash:
func setEnumOverrideIfExists<T: RawRepresentable>(for key: String, in override: [String: Any], target: inout T) where T.RawValue == UInt {
if let overrideValue = override[key] as? UInt, let overrideValueEnum = T(rawValue: overrideValue) {
target = overrideValueEnum
}
}
To Reproduce Steps to reproduce the behavior:
- Add the function above in a Swift file
- Compile
Expected behavior Compiler should not crash.
Environment (please complete the following information):
- OS: macOS 12.5 (21G5046c)
- Xcode Version/Tag/Branch: Xcode 13.2
Additional context
Stored value type does not match pointer operand type!
store i64 %95, i8** %9, align 8, !dbg !393
i8*in function $s6Panels22PrototypeOverrideModelV07setEnumC8IfExists3for2in0E0ySS_SDySSypGxztSYRzSu8RawValueRtzlF
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
<unknown>:0: note: Broken function found, compilation aborted!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/lnatan/Desktop/Code/craft-manager-mac/Submodules/craft-panels/Panels/Panels/Plugins/Sync/Prototyping/PrototypeOverridesEditors.swift -primary-file /Users/lnatan/Desktop/Code/craft-manager-mac/Submodules/craft-panels/Panels/Panels/Plugins/Sync/Prototyping/Models/PrototypeOverrideModel.swift /Users/lnatan/Desktop/Code/craft-manager-mac/Submodules/craft-panels/Panels/Panels/Plugins/Sync/Prototyping/SwiftUIUtils.swift -emit-module-path /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Objects-normal/x86_64/PrototypeOverrideModel~partial.swiftmodule -emit-module-doc-path /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Objects-normal/x86_64/PrototypeOverrideModel~partial.swiftdoc -emit-module-source-info-path /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Objects-normal/x86_64/PrototypeOverrideModel~partial.swiftsourceinfo -emit-dependencies-path /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Objects-normal/x86_64/PrototypeOverrideModel.d -emit-reference-dependencies-path /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Objects-normal/x86_64/PrototypeOverrideModel.swiftdeps -serialize-diagnostics-path /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Objects-normal/x86_64/PrototypeOverrideModel.dia -target x86_64-apple-macos11.0 -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -I /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Products/Debug -F /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Products/Debug -enable-testing -g -import-underlying-module -module-cache-path /Users/lnatan/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -serialize-debugging-options -Xcc -working-directory -Xcc /Users/lnatan/Desktop/Code/craft-manager-mac/Submodules/craft-panels/Panels -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Panels-generated-files.hmap -Xcc -I/Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Panels-own-target-headers.hmap -Xcc -I/Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Panels-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Panels-project-headers.hmap -Xcc -I/Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Products/Debug/include -Xcc -I/Users/lnatan/Desktop/Code/craft-manager-mac/Submodules/craft-panels/Panels/Pods/Headers/Public -Xcc -I/Users/lnatan/Desktop/Code/craft-manager-mac/Submodules/craft-panels/Panels/Pods/Headers/Public/CocoaLumberjack -Xcc -I/Users/lnatan/Desktop/Code/craft-manager-mac/Submodules/craft-panels/Panels/Pods/Headers/Public/RNCryptor-objc -Xcc -I/Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/DerivedSources-normal/x86_64 -Xcc -I/Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/DerivedSources/x86_64 -Xcc -I/Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -DCURRENT_USER=@\"lnatan\" -Xcc -DCOCOAPODS=1 -Xcc -ivfsoverlay -Xcc /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/unextended-module-overlay.yaml -module-name Panels -target-sdk-version 12.1.0 -o /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Build/Intermediates.noindex/Panels.build/Debug/Panels.build/Objects-normal/x86_64/PrototypeOverrideModel.o -index-store-path /Users/lnatan/Library/Developer/Xcode/DerivedData/Panels-eduudpvkojkgnobxrswznjeogchl/Index/DataStore -index-system-modules
1. Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
2.
3. Running pass 'Module Verifier' on function '@"$s6Panels22PrototypeOverrideModelV07setEnumC8IfExists3for2in0E0ySS_SDySSypGxztSYRzSu8RawValueRtzlF"'
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 0x000000010f1d7c27 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1 swift-frontend 0x000000010f1d6bb8 llvm::sys::RunSignalHandlers() + 248
2 swift-frontend 0x000000010f1d8236 SignalHandler(int) + 278
3 libsystem_platform.dylib 0x00007ff80790adfd _sigtramp + 29
4 libsystem_platform.dylib 0x0000000000000003 _sigtramp + 18446603370454012451
5 libsystem_c.dylib 0x00007ff807840d24 abort + 123
6 swift-frontend 0x000000010a2e9502 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_2::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) + 978
7 swift-frontend 0x000000010f12169e llvm::report_fatal_error(llvm::Twine const&, bool) + 286
8 swift-frontend 0x000000010f12157b llvm::report_fatal_error(char const*, bool) + 43
9 swift-frontend 0x000000010f0b815f (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 111
10 swift-frontend 0x000000010f05236a llvm::FPPassManager::runOnFunction(llvm::Function&) + 1354
11 swift-frontend 0x000000010f051651 llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 113
12 swift-frontend 0x000000010f058b75 llvm::legacy::FunctionPassManager::run(llvm::Function&) + 341
13 swift-frontend 0x000000010a7deb61 swift::performLLVMOptimizations(swift::IRGenOptions const&, llvm::Module*, llvm::TargetMachine*) + 1585
14 swift-frontend 0x000000010a7df9c7 swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef, swift::UnifiedStatsReporter*) + 2055
15 swift-frontend 0x000000010a2f4a9d 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*) + 3581
16 swift-frontend 0x000000010a2e6346 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 13830
17 swift-frontend 0x000000010a226b08 main + 1032
18 dyld 0x000000011c3fa52e start + 462
error: Abort trap: 6 (in target 'Panels' from project 'Panels')
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 25
Commits related to this issue
- Add regression test to close #59572 — committed to AnthonyLatsis/swift by AnthonyLatsis 2 years ago
- Add regression test to close #59572 — committed to AnthonyLatsis/swift by AnthonyLatsis 2 years ago
@max-christian Here’s how I described figuring out which file was causing the issue in a private thread, in case you want to try a similar approach:
Here you can find a Swift 5.9 Package that reproduce the issue in Xcode 15
MyLibrary.zip
@AnthonyLatsis I happened to run into what I believe to be this same issue in one of my projects when building with Xcode 15 beta 1, and I managed to narrow it down and create a sample project that reproduces it.
Let me know if I should file mine separately, in case it’s not directly related to this one.
Here’s the reproduction case:
Here’s the stack dump:
Here’s an Xcode project with the reproduction case: Swift-59572.zip
Thank you so much, I would have never discovered my issue without doing this! It helped me to discover that my code
was not triggering any compiler errors/warnings, but it was crashing the compiler. All I had to do was change it to
any Error
.Perhaps not elusive but just a bug that’s been fixed between Xcode 15.0 beta 2 and the snapshot I used? If there’s a possibility it’s a bug that needs attention I can open a separate issue, as the line of code that crashed the compiler isn’t an exact match for this issue:
Thanks to @insidegui for the zero byte object file trick; that successfully narrowed it down to one source file.