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

weird assertion failure for __global shmap shared map[string]f64, when unrelated function is commented/uncommented #22705

Closed
spytheman opened this issue Oct 30, 2024 · 2 comments · Fixed by #22707
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@spytheman
Copy link
Member

spytheman commented Oct 30, 2024

V doctor:

V full version: V 0.4.8 8ffcc34.08c2019
OS: linux, Ubuntu 20.04.6 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /space/v/oo
vexe: /space/v/oo/v
vexe mtime: 2024-10-28 19:30:44

vroot: OK, value: /space/v/oo
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.0
Git vroot status: weekly.2024.44-4-gd79b8509-dirty
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

What did you do?
./v -g -o vdbg cmd/v && ./vdbg -enable-globals z_test.v

fn bug_when_uncommented() { numberfns['two'] = fn () int { return 2 } }

__global (
	shmap     shared map[string]f64
	numberfns map[string]fn () int
)

fn test_global_shared_map() {
	lock shmap {
		dump(shmap)
		shmap['one'] = 1.25
		shmap['two'] = -0.75
		shmap['three'] = 5
		dump(shmap)
		dump(shmap['one'])
		dump(shmap['two']) // changed by the top line to 0, should be -0.75
		dump(shmap['three']) // changed by the top line to 0, should be 5.0
	}
	x, y := rlock shmap {
		shmap['two'], shmap['one']
	}
	dump(x)
	dump(y)
	assert x == -0.75
	assert y == 1.25
}

What did you expect to see?

A test that runs without assertion failures

What did you see instead?

#0 21:30:28 ^ master /v/oo>v -enable-globals z_test.v
[z_test.v:10] shmap: &{}
[z_test.v:14] shmap: &{'one': 1.25}
[z_test.v:15] shmap['one']: 1.25
[z_test.v:16] shmap['two']: 0.0
[z_test.v:17] shmap['three']: 0.0
[z_test.v:22] x: 0.0
[z_test.v:23] y: 1.25
z_test.v:24: ✗ fn test_global_shared_map
   > assert x == f64(-0.75)
     Left value (len: 3): `0.0`
    Right value (len: 5): `-0.75`

#1 21:31:34 ^ master /v/oo>

Note also, that dump(shmap) only displays the first element, even though the map has several, which may be another bug.

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-21153

@spytheman spytheman added the Bug This tag is applied to issues which reports bugs. label Oct 30, 2024
@spytheman
Copy link
Member Author

If the first line is commented out, the test works with both tcc, clang and gcc .

The test is isolated from vlib/v/tests/init_global_test.v where it caused flaky behavior.

I think at some point, it did pass fine, and it may have regressed due to some recent change, but I have not yet bisected to see at what version.

@spytheman
Copy link
Member Author

spytheman commented Oct 30, 2024

Here is a relevant diff between the good (commented line) and bad versions (uncommented line):

26579,26580c26593,26594
<               map_set(&shmap->val, &(string[]){_SLIT("two")}, &(f64[]) { -0.75 });
<               map_set(&shmap->val, &(string[]){_SLIT("three")}, &(f64[]) { 5 });
---
>               (*(f64*)map_get(ADDR(map, shmap->val), &(string[]){_SLIT("two")}, &(f64[]){ 0 })) = -0.75;
>               (*(f64*)map_get(ADDR(map, shmap->val), &(string[]){_SLIT("three")}, &(f64[]){ 0 })) = 5;
26596,26598c26610,26612

@spytheman spytheman added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Oct 30, 2024
@spytheman spytheman self-assigned this Oct 30, 2024
spytheman added a commit to spytheman/v that referenced this issue Oct 30, 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. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
1 participant