cgen: fix compiling call expressions with no varargs (tcc bug)

pull/7525/head
Delyan Angelov 2020-12-23 20:53:56 +02:00
parent 4dfb7dbffa
commit 36dcace0a7
3 changed files with 31 additions and 10 deletions

View File

@ -3,7 +3,6 @@ module gen
// NB: @@@ here serve as placeholders.
// They will be replaced with correct strings
// for each constant, during C code generation.
const (
// V_COMMIT_HASH is generated by cmd/tools/gen_vc.v .
c_commit_hash_default = '
@ -17,8 +16,8 @@ const (
#define V_CURRENT_COMMIT_HASH "@@@"
#endif
'
c_common_macros = '
#define EMPTY_VARG_INITIALIZATION 0
#define EMPTY_STRUCT_DECLARATION
#define EMPTY_STRUCT_INITIALIZATION 0
// Due to a tcc bug, the length of an array needs to be specified, but GCC crashes if it is...
@ -53,8 +52,10 @@ const (
#endif
#ifdef __TINYC__
#undef EMPTY_VARG_INITIALIZATION
#undef EMPTY_STRUCT_DECLARATION
#undef EMPTY_STRUCT_INITIALIZATION
#define EMPTY_VARG_INITIALIZATION
#define EMPTY_STRUCT_DECLARATION char _dummy
#define EMPTY_STRUCT_INITIALIZATION 0
#undef EMPTY_ARRAY_OF_ELEMS
@ -75,8 +76,7 @@ const (
// for __offset_of
#ifndef __offsetof
#define __offsetof(s,memb) \\
((size_t)((char *)&((s *)0)->memb - (char *)0))
#define __offsetof(s,memb) ((size_t)((char *)&((s *)0)->memb - (char *)0))
#endif
#define OPTION_CAST(x) (x)

View File

@ -836,7 +836,8 @@ fn (mut g Gen) call_args(node ast.CallExpr) {
}
}
} else {
g.write('0')
// NB: tcc can not handle 0 here, while msvc needs it
g.write('EMPTY_VARG_INITIALIZATION')
}
g.write('}}')
}

View File

@ -0,0 +1,20 @@
struct Config {
token string
}
struct Client {
x u64
y u64
}
fn new(config Config, shard_count ...int) ?&Client {
return &Client{1, 2}
}
fn test_can_compile_an_empty_var_arg() {
x := new(Config{
token: 'xyz'
}) or { panic(err) }
assert x.x == 1
assert x.y == 2
}