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

cgen doesn't create temporaries for arguments with multiple references #22749

Open
zeozeozeo opened this issue Nov 3, 2024 · 0 comments · May be fixed by #22752
Open

cgen doesn't create temporaries for arguments with multiple references #22749

zeozeozeo opened this issue Nov 3, 2024 · 0 comments · May be fixed by #22752
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@zeozeozeo
Copy link
Contributor

zeozeozeo commented Nov 3, 2024

V doctor:

V full version: V 0.4.8 5c65e58.335bb63
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 10 cpus, 64bit, little endian, 

getwd: C:\Users\user\Downloads
vexe: C:\Users\user\Desktop\Code\v\v.exe
vexe mtime: 2024-11-03 09:59:01

vroot: OK, value: C:\Users\user\Desktop\Code\v
VMODULES: OK, value: C:\Users\user\.vmodules
VTMP: OK, value: C:\Users\user\AppData\Local\Temp\v_0

Git version: git version 2.42.0.windows.1
Git vroot status: weekly.2024.43-96-g335bb635
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,

operable program or batch file.


thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

What did you do?
./v -g -o vdbg cmd/v && ./vdbg test.v

fn takes_ref(x &&&&int) {
	unsafe { ****x = 5 }
}

fn main() {
	y := 4;
	takes_ref(y);
	println(y);
}

What did you expect to see?

5 in stdout

What did you see instead?

C:/Users/user/AppData/Local/Temp/v_0/test.01JBRWGXT25H4QKMQ8M9RWFQTW.tmp.c:7204: at print_backtrace_skipping_top_frames_tcc: Backtrace
C:/Users/user/AppData/Local/Temp/v_0/test.01JBRWGXT25H4QKMQ8M9RWFQTW.tmp.c:7171: by print_backtrace_skipping_top_frames
C:/Users/user/AppData/Local/Temp/v_0/test.01JBRWGXT25H4QKMQ8M9RWFQTW.tmp.c:8116: by unhandled_exception_handler
7ffd9d7c8b5c : by ???
C:/Users/user/AppData/Local/Temp/v_0/test.01JBRWGXT25H4QKMQ8M9RWFQTW.tmp.c:13738: at main__takes_ref: RUNTIME ERROR: invalid memory access
C:/Users/user/AppData/Local/Temp/v_0/test.01JBRWGXT25H4QKMQ8M9RWFQTW.tmp.c:13745: by main__main
C:/Users/user/AppData/Local/Temp/v_0/test.01JBRWGXT25H4QKMQ8M9RWFQTW.tmp.c:13784: by wmain
00467060 : by ???
004671c3 : by ???
7ffd9d447614 : by ???

Additional information
This equivalent program in Rust prints 5:

fn takes_ref(x: &mut &mut &mut &mut i32) {
    ****x = 5;
}

fn main() {
    let mut y = 4;
    takes_ref(&mut &mut &mut &mut y);
    println!("{y}");
}

The generated C code looks like this:

VV_LOCAL_SYMBOL void main__main(void) {
	int y = 4;;
	main__takes_ref((voidptr)&/*qq*/y);;
	println(int_str(y));;
}

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.

Huly®: V_0.6-21195

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. labels Nov 3, 2024
@felipensp felipensp self-assigned this Nov 3, 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. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants