Thanks to visit codestin.com
Credit goes to github.com

Skip to content

v gen wrong code for translated v code, ptr operation is wrong #25079

@kbkpbot

Description

@kbkpbot

Describe the bug

When use V compile a translated v code vtcc, it generated wrong c code, which will cause SIGSEGV

Reproduction Steps

a test file, p.v, this case is extracted from vtcc/src/i386-asm.v, function asm_compute_constraints

@[translated]
module main

struct ASMOperand {
        constraint [16]i8
}

fn main() {
        op := &ASMOperand{}
        str := &char(0)
        str = op.constraint

        dump(str)
}
v p.v

Expected Behavior

compile & run OK.

Current Behavior

$ ./p
0x7a8202d88a6c: at ???: RUNTIME ERROR: invalid memory access
/tmp/v_1000/p.01K27AADJKBY9B4WR2J8XB4DP4.tmp.c:2187: by main

Possible Solution

No response

Additional Information/Context

in generated C file:

VV_LOC void main__main(void) {
        main__ASMOperand* op = ((main__ASMOperand*)memdup(&(main__ASMOperand){.constraint = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},}, sizeof(main__ASMOperand)));
        char* str = ((char*)(0));
        memcpy(str, op->constraint, sizeof(Array_fixed_i8_16));
         _v_dump_expr_char__ptr(_S("p.v"), 13, _S("str"), str);
}

It use memcpy instead of a pointer assignment here.

V version

V 0.4.11 3b561d5.acbb12f

Environment details (OS name and version, etc.)

V full version V 0.4.11 3b561d5.acbb12f
OS linux, Ubuntu 24.04.3 LTS
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Memory 1.95GB/15.51GB
V executable /media/HD/github/kbkpbot/v/v
V last modified time 2025-08-09 08:56:05
V home dir OK, value: /media/HD/github/kbkpbot/v
VMODULES OK, value: /home/mars/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/mars/v/bug/ptr
Git version git version 2.43.0
V git status weekly.2025.17-550-g677852fe
.git/config present true
cc version cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
gcc version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
clang version Ubuntu clang version 18.1.3 (1ubuntu1)
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.39-0ubuntu8.5) 2.39

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.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions