cgen: fix variadics called with 0 vargs

pull/4231/head
Alexey 2020-04-04 13:54:45 +03:00 committed by GitHub
parent 8ba6e45d83
commit d56276017c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 8 deletions

View File

@ -1981,17 +1981,21 @@ fn (g mut Gen) call_args(args []ast.CallArg, expected_types []table.Type) {
if is_variadic {
varg_type := expected_types[expected_types.len - 1]
struct_name := 'varg_' + g.typ(varg_type).replace('*', '_ptr')
len := args.len - arg_no
variadic_count := args.len - arg_no
varg_type_str := int(varg_type).str()
if len > g.variadic_args[varg_type_str] {
g.variadic_args[varg_type_str] = len
if variadic_count > g.variadic_args[varg_type_str] {
g.variadic_args[varg_type_str] = variadic_count
}
g.write('($struct_name){.len=$len,.args={')
for j in arg_no .. args.len {
g.ref_or_deref_arg(args[j], varg_type)
if j < args.len - 1 {
g.write(', ')
g.write('($struct_name){.len=$variadic_count,.args={')
if variadic_count > 0 {
for j in arg_no .. args.len {
g.ref_or_deref_arg(args[j], varg_type)
if j < args.len - 1 {
g.write(', ')
}
}
} else {
g.write('0')
}
g.write('}}')
}