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-9589] Clang crash when calling external C library function with UnsafePointer to C struct as argument (was Can't pass an imported C extern const struct to a C function which expects a struct pointer) #52036

Open
swift-ci opened this issue Dec 31, 2018 · 14 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9589
Radar rdar://problem/65264230
Original Reporter ryanw (JIRA User)
Type Bug
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 7b70cae7dc6f369914bd284d4678cb60

Issue Description:

I'm trying to build a Swift app on Linux (Fedora 29) using a Wayland desktop. I need to pass a C struct declared externally as

 extern const struct wl_interface wl_compositor_interface;

(from https://people.freedesktop.org/~whot/wayland-doxygen/wayland/Server/wayland-server-protocol_8h_source.html)
to a C function declared as:

static void* wl_registry_bind(
    struct wl_registry *wl_registry,
    uint32_t name,
    const struct wl_interface *interface,
    uint32_t version 
)

However if I try to call the function as:

window._compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1)

I get the error:

error: cannot pass immutable value as inout argument: 'wl_compositor_interface' is a 'let' constant

Removing the & gives the (expected) error:

error: cannot convert value of type 'wl_interface' to expected argument type 'UnsafePointer<wl_interface>?'

If I try to create an UnsafePointer to the struct to pass to the function as follows:

var compositorInterfacePointer: wl_interface = wl_compositor_interface
window._compositor = wl_registry_bind(registry, name, &compositorInterfacePointer, 1)

I get a compiler crash (on both the Fedora-built Swift 4.2.1 and my own build from dev HEAD):
https://gist.github.com/tokyovigilante/89a1209eb7802b8a035d6f03b63adeae

Is there any way to pass these externally defined structs to a function which expects a const struct pointer?

@belkadan
Copy link
Contributor

belkadan commented Jan 7, 2019

@jckarter, with SE-0205, do we promise that the address will be consistent for globals?

@jckarter
Copy link
Member

jckarter commented Jan 7, 2019

The address should be consistent, but you still wouldn't be allowed to read or write through pointers outside of withUnsafePointer blocks or immediate calls due to exclusivity enforcement. If the identity of the object is important, it's best to malloc or UnsafeMutablePointer.allocate it. Nonetheless, the compiler shouldn't crash in these examples.

@belkadan
Copy link
Contributor

belkadan commented Jan 7, 2019

It's an external global constant; the user doesn't have a choice about how to get its address.

@jckarter
Copy link
Member

jckarter commented Jan 7, 2019

OK, for extern globals you should always get the same address, and Swift's exclusivity enforcement doesn't matter, since Swift doesn't have full control over the storage anyway.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 8, 2019

Comment by Ryan (JIRA)

So best practice would be to wrap the function call inside a

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 8, 2019

Comment by Ryan (JIRA)

Any update on this issue? Would be great to get this compiler crash resolved.

@belkadan
Copy link
Contributor

Do you have a self-contained example that causes the crash? It's likely something about the definition of wl_interface that's causing it, not the pointer issue.

@swift-ci
Copy link
Collaborator Author

Comment by Ryan (JIRA)

Somewhat confusingly I generated a standalone example and this worked with no problems, although the crash persists in my project.

I've dug into it a bit more. I'm also importing Vulkan using another system library target, and if I import CVulkan in any other .swift file in that module then I get the compiler crash. Removing the CVulkan import allows the Wayland code to build. Unfortunately adding CVulkan to the standalone example works fine.

As I'm planning to move away from Vulkan in favour of a different renderer its a bit of a moot point now, but will post a new bug if I get any more compiler crashes. Thanks for your attention to this. I've attached the example (which does work fine) for reference. It would need to be built on Linux running a Wayland compositor (I'm using Fedora 30 with Sway, but the default Gnome would work ok too I think). wayland-client-devel et al also required.

Sources/WaylandTest/main.swift:

import CWaylandClient
import Dispatch
import Foundation

public class WaylandWSIWindow {
    var _compositor: UnsafeMutableRawPointer! = nil
}

func handleGlobal(userdata: UnsafeMutableRawPointer?,
                          registry: OpaquePointer?, name: UInt32,
                          interface: UnsafePointer<Int8>?, version: UInt32) {
    guard let interfaceCString = interface, let userdata = userdata else {
        return
    }
    let window = Unmanaged<WaylandWSIWindow>.fromOpaque(userdata).takeUnretainedValue()
    let interfaceString = String(cString: interfaceCString)
    print("\(name): \(interfaceString) \(version)")
    if strcmp(interfaceCString, wl_compositor_interface.name) == 0 {

        withUnsafePointer(to: wl_compositor_interface) { interfacePointer in
            window._compositor = wl_registry_bind(registry, name,
                                                  interfacePointer, 1)
        }
        print("Bound wl_compositor")
    }
}

func handleGlobalRemove(data: UnsafeMutableRawPointer?,
                        registry: OpaquePointer?, name: UInt32) {
}

var registryListener = wl_registry_listener(
    global: handleGlobal,
    global_remove: handleGlobalRemove
)

let window = WaylandWSIWindow()
let unsafeSelf = Unmanaged.passUnretained(window).toOpaque()

guard let display = wl_display_connect(nil) else {
    print("Failed to create wl_display")
    exit(-1)
}
print("Created wl_display")

let registry = wl_display_get_registry(display)
wl_registry_add_listener(registry, &registryListener, unsafeSelf)
wl_display_dispatch(display)
wl_display_roundtrip(display)

signal(SIGINT) { _ in
    exit(0)
}

dispatchMain()

Package.swift

// swift-tools-version:4.2
import PackageDescription

let package = Package(
    name: "WaylandTest",
    products: [
        .executable(name: "WaylandTest", targets: ["WaylandTest"])
    ],
    targets: [
        .systemLibrary(
            name: "CWaylandClient",
            pkgConfig: "wayland-client"),
        .target(
            name: "WaylandTest",
            dependencies: ["CWaylandClient"])
    ]
)

Sources/CWaylandClient/cwaylandclient.h

#include <wayland-client.h>

Sources/CWaylandClient/module.modulemap

module CWaylandClient {
    umbrella header "cwaylandclient.h"
    export *
    link "wayland-client"
}

@swift-ci
Copy link
Collaborator Author

Comment by Ryan (JIRA)

I have been able to reproduce this crash when using the wayland client API from a swift library (rather than a single-file example) without Vulkan, so re-opening. (Relatively) minimal example on [Github|https://github.com/tokyovigilante/WaylandTest.]

Should be reproducible on Swift 4.2 or 5.0-dev on Ubuntu or Fedora 29/30 with the Wayland client dev packages installed.

@swift-ci
Copy link
Collaborator Author

Comment by Ryan (JIRA)

Noted similar crashes (in LLVM) in SR-8846 and SR-10090. The crash relates to an insertion in an LLVM C++ header imported by the swift compiler, so technically in the swift compiler although related to imported LLVM code.

@swift-ci
Copy link
Collaborator Author

Comment by Ryan (JIRA)

Swift compiler build with additional logging gives the crash log below:

a[0/1] Compiling .build/checkouts/LoggerAPI/Sources/LoggerAPI/Logger.swift [1/2] Merging module .build/x86_64-unknown-linux/debug/LoggerAPI.swiftmodule [2/3] Compiling .build/checkouts/HeliumLogger/Sources/HeliumLogger/HeliumLogger.swift [2/4] Compiling .build/checkouts/HeliumLogger/Sources/HeliumLogger/HeliumStreamLogger.swift [3/4] Compiling .build/checkouts/HeliumLogger/Sources/HeliumLogger/HeliumLogger.swift [4/5] Merging module .build/x86_64-unknown-linux/debug/HeliumLogger.swiftmodule [5/6] Compiling Sources/Harness/POSIXErrors.swift [5/7] Compiling Sources/Harness/PrecisionTimer.swift [5/8] Compiling Sources/Harness/System/FSEvents-Darwin.swift [5/9] Compiling Sources/Harness/System/FSEvents-Linux.swift [5/10] Compiling Sources/Harness/System/FSEvents.swift [5/11] Compiling Sources/Harness/Utilities.swift [8/11] Compiling Sources/Harness/System/FSEvents.swift [9/11] Compiling Sources/Harness/System/FSEvents-Linux.swift [11/12] Merging module .build/x86_64-unknown-linux/debug/Harness.swiftmodule [12/13] Compiling Sources/Merlin/MailWatcher/MailWatcher.swift [12/14] Compiling Sources/Airframe/Window/AirframeWindow.swift [12/15] Compiling Sources/Merlin/Maildir/Maildir.swift [12/16] Compiling Sources/Merlin/Maildir/MaildirReader.swift [12/17] Compiling Sources/Merlin/Maildir/RFC6154.swift [12/18] Compiling Sources/Airframe/Window/MacWSIWindow.swift [12/19] Compiling Sources/Merlin/Merlin.swift [12/20] Compiling Sources/Merlin/RFC822/MailParser.swift [12/21] Compiling Sources/Airframe/Window/WaylandWSIWindow.swift [12/22] Compiling Sources/Merlin/RFC822/RFC5322.swift [12/23] Compiling Sources/Merlin/Search/Notmuch.swift [12/24] Compiling Sources/Merlin/System/MerlinError.swift [12/25] Compiling Sources/Merlin/Types/MailAddress.swift [12/26] Compiling Sources/Merlin/Types/MailPart.swift [12/27] Compiling Sources/Merlin/Types/Message.swift [12/28] Compiling Sources/Merlin/Types/MessageHeader.swift [12/29] Compiling Sources/Merlin/Types/Thread.swift [12/30] Compiling Sources/Merlin/Utilities/StreamReader.swift /home/ryan/Projects/Develop/Spitfire/Sources/Merlin/Merlin.swift:68:18: warning: replace with notmuch #warning("replace with notmuch") ^~~~~~~~~~~~~~~~~~~~~~ [27/30] Compiling Sources/Merlin/Search/Notmuch.swift /home/ryan/Projects/Develop/Spitfire/Sources/Merlin/Maildir/Maildir.swift:61:13: warning: variable 'messages' was never mutated; consider changing to 'let' constant var messages: [URL] = [] ~~~ ^ let [29/30] Compiling Sources/Airframe/Window/WaylandWSIWindow.swift [29/31] Merging module .build/x86_64-unknown-linux/debug/Merlin.swiftmodule [30/31] Compiling Sources/Airframe/Window/WaylandWSIWindow.swift /home/ryan/Projects/Develop/Spitfire/Sources/Airframe/Window/WaylandWSIWindow.swift:57:9: warning: initialization of immutable value 'pointer' was never used; consider replacing with assignment to '_' or removing it let pointer = wl_seat_get_pointer(seat) ~~~~^~~~~~~ _ swift: /home/ryan/Projects/Develop/swift-source/llvm/tools/clang/lib/CodeGen/CGRecordLayout.h:187: unsigned int clang::CodeGen::CGRecordLayout::getLLVMFieldNo(const clang::FieldDecl *) const: Assertion `FieldInfo.count(FD) && "Invalid field for record!"' failed. Stack dump: 0. Program arguments: /home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift -frontend -c /home/ryan/Projects/Develop/Spitfire/Sources/Airframe/Window/AirframeWindow.swift /home/ryan/Projects/Develop/Spitfire/Sources/Airframe/Window/MacWSIWindow.swift -primary-file /home/ryan/Projects/Develop/Spitfire/Sources/Airframe/Window/WaylandWSIWindow.swift -emit-module-path /home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug/Airframe.build/Window/WaylandWSIWindow~partial.swiftmodule -emit-module-doc-path /home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug/Airframe.build/Window/WaylandWSIWindow~partial.swiftdoc -emit-dependencies-path /home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug/Airframe.build/Window/WaylandWSIWindow.d -emit-reference-dependencies-path /home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug/Airframe.build/Window/WaylandWSIWindow.swiftdeps -target x86_64-unknown-linux -disable-objc-interop -sdk / -I /home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug -I /home/ryan/Projects/Develop/Spitfire/Sources/XDGShell/include -enable-testing -g -module-cache-path /home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/home/ryan/Projects/Develop/Spitfire/Sources/CInotify/module.modulemap -Xcc -fmodule-map-file=/home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug/XDGShell.build/module.modulemap -Xcc -fmodule-map-file=/home/ryan/Projects/Develop/Spitfire/Sources/CWaylandEGL/module.modulemap -Xcc -fmodule-map-file=/home/ryan/Projects/Develop/Spitfire/Sources/CEGL/module.modulemap -Xcc -fmodule-map-file=/home/ryan/Projects/Develop/Spitfire/Sources/CWaylandClient/module.modulemap -parse-as-library -module-name Airframe -o /home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug/Airframe.build/Window/WaylandWSIWindow.swift.o -index-store-path /home/ryan/Projects/Develop/Spitfire/.build/x86_64-unknown-linux/debug/index/store -index-system-modules 1. //usr/include/wayland-client-protocol.h:1091:1: Generating code for declaration 'wl_registry_bind' #&#8203;0 0x00000000040ce89f llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x40ce89f) #&#8203;1 0x00000000040ccb50 llvm::sys::RunSignalHandlers() (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x40ccb50) #&#8203;2 0x00000000040cee08 SignalHandler(int) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x40cee08) #&#8203;3 0x00007f4793571e70 __restore_rt (/lib64/libpthread.so.0+0x12e70) #&#8203;4 0x00007f4792fd00f5 __GI_raise (/lib64/libc.so.6+0x380f5) #&#8203;5 0x00007f4792fba895 __GI_abort (/lib64/libc.so.6+0x22895) #&#8203;6 0x00007f4792fba769 _nl_load_domain.cold (/lib64/libc.so.6+0x22769) #&#8203;7 0x00007f4792fc8596 (/lib64/libc.so.6+0x30596) #&#8203;8 0x000000000203f2ff clang::CodeGen::CGRecordLayout::getLLVMFieldNo(clang::FieldDecl const*) const (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x203f2ff) #&#8203;9 0x000000000203f909 emitAddrOfFieldStorage(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::FieldDecl const*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x203f909) #&#8203;10 0x000000000202abb4 clang::CodeGen::CodeGenFunction::EmitLValueForField(clang::CodeGen::LValue, clang::FieldDecl const*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x202abb4) #&#8203;11 0x000000000203575b clang::CodeGen::CodeGenFunction::EmitMemberExpr(clang::MemberExpr const*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x203575b) #&#8203;12 0x0000000002027968 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2027968) #&#8203;13 0x000000000202faee clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x202faee) #&#8203;14 0x000000000207e364 (anonymous namespace)::ScalarExprEmitter::EmitLoadOfLValue(clang::Expr const*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x207e364) #&#8203;15 0x000000000207b308 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x207b308) #&#8203;16 0x0000000002081484 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2081484) #&#8203;17 0x000000000206e565 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x206e565) #&#8203;18 0x00000000020274ec clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x20274ec) #&#8203;19 0x00000000020280fc clang::CodeGen::CodeGenFunction::EmitAnyExprToTemp(clang::Expr const*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x20280fc) #&#8203;20 0x0000000001fc9d0a clang::CodeGen::CodeGenFunction::EmitCallArg(clang::CodeGen::CallArgList&, clang::Expr const*, clang::QualType) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x1fc9d0a) #&#8203;21 0x0000000001fc89be clang::CodeGen::CodeGenFunction::EmitCallArgs(clang::CodeGen::CallArgList&, llvm::ArrayRef<clang::QualType>, llvm::iterator_range<clang::Stmt::ConstExprIterator>, clang::CodeGen::CodeGenFunction::AbstractCallee, unsigned int, clang::CodeGen::CodeGenFunction::EvaluationOrder) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x1fc89be) #&#8203;22 0x0000000001fdc59e void clang::CodeGen::CodeGenFunction::EmitCallArgs<clang::FunctionProtoType>(clang::CodeGen::CallArgList&, clang::FunctionProtoType const*, llvm::iterator_range<clang::Stmt::ConstExprIterator>, clang::CodeGen::CodeGenFunction::AbstractCallee, unsigned int, clang::CodeGen::CodeGenFunction::EvaluationOrder) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x1fdc59e) #&#8203;23 0x0000000002041972 clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2041972) #&#8203;24 0x000000000204084e clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x204084e) #&#8203;25 0x000000000207de5c (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x207de5c) #&#8203;26 0x0000000002077822 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2077822) #&#8203;27 0x000000000206e565 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x206e565) #&#8203;28 0x00000000020274ec clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x20274ec) #&#8203;29 0x0000000002027499 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2027499) #&#8203;30 0x00000000020f5f31 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x20f5f31) #&#8203;31 0x00000000020ff710 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x20ff710) #&#8203;32 0x000000000213f09b clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x213f09b) #&#8203;33 0x0000000002156ea9 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2156ea9) #&#8203;34 0x0000000002150bf8 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2150bf8) #&#8203;35 0x0000000002148a11 clang::CodeGen::CodeGenModule::EmitDeferred() (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2148a11) #&#8203;36 0x0000000002147dc7 clang::CodeGen::CodeGenModule::Release() (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x2147dc7) #&#8203;37 0x0000000001f68a84 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x1f68a84) #&#8203;38 0x0000000000572750 swift::irgen::IRGenModule::finalize() (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x572750) #&#8203;39 0x0000000000561cf6 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x561cf6) #&#8203;40 0x00000000005620a1 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::GlobalVariable**) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x5620a1) #&#8203;41 0x00000000004ec39d performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x4ec39d) #&#8203;42 0x00000000004e7d25 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x4e7d25) #&#8203;43 0x000000000048dd57 main (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x48dd57) #&#8203;44 0x00007f4792fbbf33 __libc_start_main (/lib64/libc.so.6+0x23f33) #&#8203;45 0x000000000048d9be _start (/home/ryan/Projects/Develop/swift-toolchain/usr/bin/swift+0x48d9be)

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 1, 2019

Comment by Ryan (JIRA)

Using the steps in https://apple-swift.readthedocs.io/en/latest/DebuggingTheCompiler.html

I'm able to get as far as the optimised SIL generation step, with the compiler crashing with the same assertion failure at the LLVM IR generation pass (ie using `swiftc -emit-ir -Xfrontend -disable-llvm-optzns -O file.swift`) fails. Happy to post the generated SIL representation if helpful, but it's pretty large.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 1, 2019

Comment by Ryan (JIRA)

I've also discovered that removing the XDGShell C module from the project allows compilation to succeed, although it's unclear why as the wl_registry_bind function is not imported from this module. However the XDGShell module is a Wayland protocol extension that is required for desktop window creation, so this isn't a viable solution other than for debugging this.

EDIT: Annoyingly the root cause seems to be that both XDGShell and WaylandWSIWindow (via the CWaylandClient system module) include the wayland-client.h header, which was causing the crash. Removing the #include from xdgshell.h allows compilation to succeed. The header has include guards so I'm not sure why this should crash, nor why I can remove the #include in a file in a separate module, however at least I can work around this for now.

@atrick
Copy link
Member

atrick commented Jul 9, 2020

@swift-cicreate

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

4 participants