zig/test/cases/asm.zig
Sahnvour 703c6684d1 Crash fixes and small improvements to inline asm. (#1756)
* codegen: LLVMConstInlineAsm is deprecated.

* codegen: replace commas in asm constraint strings by pipes as required by LLVM.

* ir: enforce usage of '=' constraint modifier for inline assembly outputs.

Others are not currently supported and this was just asserted alter in `ir_render_asm`.

* asm: forbid comptime_int/floats as inputs in favor of explicitely sized constants.

Fixes a crash due to comptime_int/floats having no type_ref.

* asm: handle inputs with integers of <8 or non power of 2 bitsize.

We widen them to the next highest power of two.
2018-11-19 16:22:21 -05:00

49 lines
1.3 KiB
Zig

const config = @import("builtin");
const assert = @import("std").debug.assert;
comptime {
if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
asm volatile (
\\.globl aoeu;
\\.type aoeu, @function;
\\.set aoeu, derp;
);
}
}
test "module level assembly" {
if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
assert(aoeu() == 1234);
}
}
test "output constraint modifiers" {
// This is only testing compilation.
var a: u32 = 3;
asm volatile ("" : [_]"=m,r"(a) : : "");
asm volatile ("" : [_]"=r,m"(a) : : "");
}
test "alternative constraints" {
// Make sure we allow commas as a separator for alternative constraints.
var a: u32 = 3;
asm volatile ("" : [_]"=r,m"(a) : [_]"r,m"(a) : "");
}
test "sized integer/float in asm input" {
asm volatile ("" : : [_]"m"(usize(3)) : "");
asm volatile ("" : : [_]"m"(i15(-3)) : "");
asm volatile ("" : : [_]"m"(u3(3)) : "");
asm volatile ("" : : [_]"m"(i3(3)) : "");
asm volatile ("" : : [_]"m"(u121(3)) : "");
asm volatile ("" : : [_]"m"(i121(3)) : "");
asm volatile ("" : : [_]"m"(f32(3.17)) : "");
asm volatile ("" : : [_]"m"(f64(3.17)) : "");
}
extern fn aoeu() i32;
export fn derp() i32 {
return 1234;
}