mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix assembly in generic fns (#10370)
This commit is contained in:
parent
114c382c46
commit
8a497080b3
@ -4957,7 +4957,7 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
|
||||
}
|
||||
} else if to_type_sym.kind == .interface_ {
|
||||
c.type_implements(node.expr_type, node.typ, node.pos)
|
||||
} else if node.typ == ast.bool_type {
|
||||
} else if node.typ == ast.bool_type && !c.inside_unsafe {
|
||||
c.error('cannot cast to bool - use e.g. `some_int != 0` instead', node.pos)
|
||||
} else if node.expr_type == ast.none_type && !node.typ.has_flag(.optional) {
|
||||
type_name := c.table.type_to_str(node.typ)
|
||||
|
@ -1937,7 +1937,8 @@ fn (mut g Gen) gen_asm_stmt(stmt ast.AsmStmt) {
|
||||
}
|
||||
g.writeln(' (')
|
||||
g.indent++
|
||||
for mut template in stmt.templates {
|
||||
for template_tmp in stmt.templates {
|
||||
mut template := template_tmp
|
||||
g.write('"')
|
||||
if template.is_directive {
|
||||
g.write('.')
|
||||
|
@ -183,3 +183,25 @@ fn test_flag_output() {
|
||||
assert out
|
||||
assert maybe_four == 9
|
||||
}
|
||||
|
||||
fn test_asm_generic() {
|
||||
u := u64(49)
|
||||
b := unsafe { bool(123) }
|
||||
assert generic_asm(u) == 14
|
||||
assert u == 63
|
||||
assert u64(generic_asm(b)) == 14
|
||||
assert u64(b) == 137
|
||||
}
|
||||
|
||||
fn generic_asm<T>(var &T) T {
|
||||
mut ret := T(14)
|
||||
unsafe {
|
||||
asm volatile amd64 {
|
||||
add var, ret
|
||||
; +m (var[0]) as var
|
||||
+r (ret)
|
||||
; ; memory
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import v.tests.assembly.util
|
||||
// rename this file to asm_test.amd64.v (and make more for other architectures) once pure v code is enforced
|
||||
|
||||
fn test_inline_asm() {
|
||||
a, mut b := 10, 0
|
||||
@ -165,3 +164,25 @@ fn test_flag_output() {
|
||||
assert out
|
||||
assert maybe_four == 9
|
||||
}
|
||||
|
||||
fn test_asm_generic() {
|
||||
u := u64(49)
|
||||
b := unsafe { bool(123) }
|
||||
assert generic_asm(u) == 14
|
||||
assert u == 63
|
||||
assert u64(generic_asm(b)) == 14
|
||||
assert u64(b) == 137
|
||||
}
|
||||
|
||||
fn generic_asm<T>(var &T) T {
|
||||
mut ret := T(14)
|
||||
unsafe {
|
||||
asm volatile amd64 {
|
||||
add var, ret
|
||||
; +m (var[0]) as var
|
||||
+r (ret)
|
||||
; ; memory
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user