Skip to content

Compiler SIGSEGV: ternary string result passed to an extern's string implicit parameter #3374

Description

@borisbat

Passing a ternary (?:) string expression directly to an extern function's string implicit parameter crashes the compiler with SIGSEGV (at address ~0x5f), at compile time — the function does not need to be called.

Minimal repro

options gen2

require llvm/daslib/llvm_boost

def make(b : LLVMOpaqueBuilder?; v : LLVMOpaqueValue?; t : LLVMOpaqueType?; i : int) {
    return LLVMBuildBitCast(b, v, t, i == 0 ? "a" : "b")
}

[export]
def main {
    print("compiled\n")
}

bin/daslang repro.dasCRASH: SIGSEGV (Segmentation fault) (signal 11) at address 0x5f

The callee here is dasLLVM's raw binding:

[extern(cdecl, name="LLVMBuildBitCast", library="LLVM.dll")]
def LLVMBuildBitCast(... ; Name : string implicit) : LLVMOpaqueValue? {}

Variants matrix

Name argument Result
i == 0 ? "a" : "b" (ternary, two literals) CRASH
i == 0 ? "a" : "a{i}" (ternary + interpolation) CRASH
"a{i}" (plain interpolation, no ternary) compiles
let nm = i == 0 ? "a" : "b" then pass nm compiles
same ternary into a plain das function taking name : string compiles

So the trigger is specifically an ExprOp3 string result flowing into a string implicit extern parameter; hoisting the ternary into a local is the workaround.

Side effect: the daslang MCP server's compile_check also SIGSEGVs on any file containing the pattern (same root, it just compiles the file).

Found while writing the dasLLAMA GEMM generator (emit_block_mx4, kernel-gen branch); the one hit site there is hoisted with a comment pointing here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions