Skip to content

Segfault: bitfields in inline assembly #4966

@ibuclaw

Description

@ibuclaw

Runnable example.

struct S { int x : 8; }

void f(ref S s, int y)
{
    asm { "mov %1, %0" : "=r" (s.x) : "r" (y); }
}

void main()
{
    S s;
    f(s, 15);
    assert(s.x == 15);
}
0  ldc2      0x0000621ef8d4a0e7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  ldc2      0x0000621ef8d47eec llvm::sys::RunSignalHandlers() + 188
2  ldc2      0x0000621ef8d4a78f
3  libc.so.6 0x0000735c9061f330
4  ldc2      0x0000621ef9055767 GccAsmStatement_toIR(GccAsmStatement*, IRState*) + 1895
5  ldc2      0x0000621ef8fd5398 CompoundAsmStatement_toIR(CompoundAsmStatement*, IRState*) + 4696
6  ldc2      0x0000621ef9053a7b
7  ldc2      0x0000621ef8fe5f04 DtoDefineFunction(FuncDeclaration*, bool) + 7076
8  ldc2      0x0000621ef9013352 codegenModule(IRState*, Module*) + 4274
9  ldc2      0x0000621ef90b9445 ldc::CodeGenerator::emit(Module*) + 213
10 ldc2      0x0000621ef5880f5a codegenModules(Array<Module*>&) + 938
11 ldc2      0x0000621ef5884865 mars_tryMain(Param&, Array<char const*>&) + 2069
12 ldc2      0x0000621ef58d1bc0 cppmain() + 9376
13 ldc2      0x0000621ef9275aed _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv + 77
14 ldc2      0x0000621ef92758c4 _d_run_main2 + 468
15 ldc2      0x0000621ef92756dd _d_run_main + 141
16 ldc2      0x0000621ef90b5fc8 main + 680
17 libc.so.6 0x0000735c906041ca
18 libc.so.6 0x0000735c9060428b __libc_start_main + 139
19 ldc2      0x0000621ef58d678e _start + 46
Segmentation fault (core dumped)

Other examples that should fail

struct T { int m : 32; }
void mwrite(T t) { asm { "" : "=m" (t.m); } // taking address of bitfield
void mread(T t) { asm { "" :: "m" (t.m); } // taking address of bitfield

The C equivalent to all of the above (importC) should succeed or fail in the same way as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions