Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insufficient support for va_list type #20636

Open
arkt8 opened this issue Jan 23, 2024 · 0 comments
Open

Insufficient support for va_list type #20636

arkt8 opened this issue Jan 23, 2024 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@arkt8
Copy link

arkt8 commented Jan 23, 2024

Describe the bug

There is no documented va_list alternative for use when using C bindings, but looks like there is a partial support when using v translate.

Reproduction Steps

File test.c:

#include <stdarg.h>

int sum(int qtd, ...) {
  va_list va;
  int s = 0;
  va_start(va, qtd);
  for (int i=0; i < qtd; i++) {
    s += (va_arg(va, int));
  }
  va_end(va);
  return s;
}

int main() {
  printf("Result %d\n", sum(3,4,5,6));
  return 0;
}

Then run:
v translate test.c

Expected Behavior

Work seamlessly converting to V and, after running the resulting binary print on screen:
Result 15

Current Behavior

The command v translate test.c gives the following error:

C to V translator 0.4.0
  translating /tmp/test.c     ... test.v:10:9: error: invalid expression: unexpected token `)`
    8 |     __builtin_va_start(va, qtd)
    9 |     for i := 0 ; i < qtd ; i ++ {
   10 |         s += ()
      |               ^
   11 |     }
   12 |     __builtin_va_end(va)

Internal vfmt error while formatting file: /tmp/test.v.
Encountered a total of: 1 errors.
 took    35 ms ; output .v file: test.v
Translated   1 files in    35 ms.

Possible Solution

Partial / insufficient implementation of va_list or stdarg.h.

Additional Information/Context

Even with the error, V still generates a test.v file with the following content:

@[translated]
module main

@[c2v_variadic]
fn sum(qtd int) int {
	va := Va_list{}
	mas := 0
	__builtin_va_start(va, qtd)
	for i := 0 ; i < qtd ; i ++ {
		s += ()
	}
	__builtin_va_end(va)
	return s
}

fn main()  {
	C.printf(c'Result %d\n', sum(3, 4, 5, 6))
	return 
}

V version

0.4.4 0205154

Environment details (OS name and version, etc.)

v doctor output:

V full version: V 0.4.4 65a1d2f.0205154
OS: linux, Debian GNU/Linux bookworm/sid
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz

getwd: /tmp
vexe: /opt/v/v
vexe mtime: 2024-01-23 01:53:07

vroot: OK, value: /opt/v
VMODULES: OK, value: /home/thadeu/.vmodules
VTMP: OK, value: /tmp/v_101000

Git version: git version 2.34.1
Git vroot status: weekly.2024.03-53-g02051540
.git/config present: true

CC version: cc (Debian 12.2.0-14) 12.2.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3-dirty

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@arkt8 arkt8 added the Bug This tag is applied to issues which reports bugs. label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant