mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
cgen: fix big IntegerLiteral LL postfix
This commit is contained in:
parent
bae7684276
commit
4f4eea48e8
3 changed files with 17 additions and 18 deletions
|
@ -268,3 +268,12 @@ fn test_int_max() {
|
|||
assert int_max(-5, 5) == 5
|
||||
assert int_max(5, -5) == 5
|
||||
}
|
||||
|
||||
fn test_big_int() {
|
||||
x := i64(2147483647)
|
||||
if x > -2147483649 && x < 2147483648 {
|
||||
assert true
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3184,13 +3184,6 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
|
|||
g.write('*')
|
||||
}
|
||||
}
|
||||
if expr is ast.IntegerLiteral {
|
||||
if expected_type in [ast.u64_type, ast.u32_type, ast.u16_type] && expr.val[0] != `-` {
|
||||
g.expr(expr)
|
||||
g.write('U')
|
||||
return
|
||||
}
|
||||
}
|
||||
if (exp_sym.kind == .function && !expected_type.has_option_or_result())
|
||||
|| (g.inside_struct_init && expected_type == ast.voidptr_type
|
||||
&& expected_type != got_type_raw && expr !is ast.StructInit) {
|
||||
|
@ -3814,6 +3807,10 @@ fn (mut g Gen) expr(node_ ast.Expr) {
|
|||
g.write2('-0', node.val[3..])
|
||||
} else {
|
||||
g.write(node.val)
|
||||
val_i64 := node.val.i64()
|
||||
if val_i64 > 2147483647 || val_i64 < -2147483648 {
|
||||
g.write('LL')
|
||||
}
|
||||
}
|
||||
}
|
||||
ast.IsRefType {
|
||||
|
@ -5670,13 +5667,6 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
|
|||
}
|
||||
}
|
||||
g.expr(node.expr)
|
||||
if node.expr is ast.IntegerLiteral {
|
||||
if node_typ in [ast.u64_type, ast.u32_type, ast.u16_type] {
|
||||
if !node.expr.val.starts_with('-') {
|
||||
g.write('U')
|
||||
}
|
||||
}
|
||||
}
|
||||
g.write('))')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
u64 VWEAK abc = ((u64)(1U)); // global
|
||||
u64 xyz = ((u64)(2U)); // global
|
||||
u64 VWEAK weak_1 = ((u64)(4U)); // global
|
||||
u64 VWEAK weak_2 = ((u64)(5U)); // global
|
||||
u64 VWEAK abc = ((u64)(1)); // global
|
||||
u64 xyz = ((u64)(2)); // global
|
||||
u64 VWEAK weak_1 = ((u64)(4)); // global
|
||||
u64 VWEAK weak_2 = ((u64)(5)); // global
|
||||
VV_LOC int main__a_weak_function(void);
|
||||
VV_LOC void main__main(void);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue