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 error for enum field with expression involving a constant #21777

Closed
spytheman opened this issue Jul 1, 2024 · 3 comments · Fixed by #21779
Closed

cgen error for enum field with expression involving a constant #21777

spytheman opened this issue Jul 1, 2024 · 3 comments · Fixed by #21779
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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@spytheman
Copy link
Member

spytheman commented Jul 1, 2024

V doctor:

V full version: V 0.4.6 c689f80.605c43d
OS: linux, Ubuntu 20.04.6 LTS
Processor: 2 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-07-01 09:39:23

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

Git version: git version 2.43.2
Git vroot status: weekly.2024.26-21-g605c43df
.git/config present: true

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

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

const base = 600000

enum Abc {
	aa
	bb = base
	cc
	dd = base + 10
}

// assert int(Abc.dd) == 600010

What did you expect to see?

a compiled program

What did you see instead?

==================
/tmp/v_1000/a.01J1PTKV5BXQQ8PM29Q1HFZJAV.tmp.c:842: error: '_const_main__base' undeclared
...
==================
(Use `v -cg` to print the entire error message)

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.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Jul 1, 2024
@spytheman
Copy link
Member Author

The generated code had this on line 842:

    main__Abc__dd = (int_literal)(_const_main__base + 10), // (int_literal)(_const_main__base + 10)

while the define for the _const_main__base was later on line 1987:

#define _const_main__base 600000

@spytheman
Copy link
Member Author

spytheman commented Jul 1, 2024

bb = base leads to main__Abc__bb = 600000, which is also fine, i.e. another potential resolution, beside reordering, is evaluating the base + 10 expression immediately in the checker/transformer, and generating main__Abc__bb = 600010 directly.

@spytheman spytheman self-assigned this Jul 1, 2024
@JalonSolov
Copy link
Contributor

I'd vote transformer. Checker should only check - transformer should do changes.

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

2 participants