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

C error when casting index and returning a pointer on a fixed length array #13128

Closed
weshardee opened this issue Jan 10, 2022 · 0 comments · Fixed by #13131
Closed

C error when casting index and returning a pointer on a fixed length array #13128

weshardee opened this issue Jan 10, 2022 · 0 comments · Fixed by #13131
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@weshardee
Copy link

V doctor:

OS: macos, macOS, 11.6, 20G165
Processor: 16 cpus, 64bit, little endian, Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
CC version: Apple clang version 13.0.0 (clang-1300.0.29.3)

getwd: /Users/wes/dev/test-v
vmodules: /Users/wes/.vmodules
vroot: /Users/wes/dev/v
vexe: /Users/wes/dev/v/v
vexe mtime: 2022-01-10 16:03:41
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 65eb383

Git version: git version 2.30.1 (Apple Git-130)
Git vroot status: weekly.2022.02-2-g65eb383c
.git/config present: true
thirdparty/tcc status: thirdparty-macos-amd64 93fa86be

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

type Entity = int

struct Component {
	vals [256]int
}

fn (c Component) get_broken(e Entity) &int {
	return &c.vals[int(e)]
}

What did you expect to see?

successful compilation

What did you see instead?

==================
   ^~~~~~~~~~~~~~~
/tmp/v_501/main.14493015409709803414.tmp.c:10882:48: error: too few arguments to function call, expected 2, have 1
        int* _t1 = &(*(c)).vals[v_fixed_index((int)(e)), 256)];
                                ~~~~~~~~~~~~~         ^
/tmp/v_501/main.14493015409709803414.tmp.c:6281:28: note: 'v_fixed_index' declared here
inline VV_LOCAL_SYMBOL int v_fixed_index(int i, int len) {
                           ^
/tmp/v_501/main.14493015409709803414.tmp.c:10882:54: error: expected ']'
        int* _t1 = &(*(c)).vals[v_fixed_index((int)(e)), 256)];
                                                            ^
/tmp/v_501/main.14493015409709803414.tmp.c:10882:25: note: to match this '['
        int* _t1 = &(*(c)).vals[v_fixed_index((int)(e)), 256)];
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

spytheman added a commit to jeffmikels/v that referenced this issue Jan 11, 2022
* origin:
  ci: vfmt fmt.v ...
  cgen: fix `$if T.typ is Type {` (vlang#13135)
  parser: add support for mutable if guards (vlang#13132)
  tests: test with valgrind rune.bytes(), fix leak in .str_escaped()
  builtin: reduce allocations in `rune.bytes()`
  builtin: allow msvc users to link against a custom compiled Boehm library (vlang#13133)
  cgen: fix cast in the index of reference fixed array (fix vlang#13128) (vlang#13131)
  builtin: add a rune.bytes() convenience method (vlang#13129)
  checker: check error for match conditions with parenthesis (vlang#13130)
@medvednikov medvednikov added the Bug This tag is applied to issues which reports bugs. label Jul 19, 2022
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

Successfully merging a pull request may close this issue.

2 participants