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

Compiler error when building global arrays of empty Structs #21761

Closed
raw-bin opened this issue Jun 29, 2024 · 1 comment · Fixed by #21764
Closed

Compiler error when building global arrays of empty Structs #21761

raw-bin opened this issue Jun 29, 2024 · 1 comment · Fixed by #21764
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Compiler: Clang Bugs/feature requests, that are related to compiler Clang

Comments

@raw-bin
Copy link

raw-bin commented Jun 29, 2024

Describe the bug

Consider the following code:

❯ cat 1.v
module main

const num_elements = 10

struct DummyStruct {}

__global (
        d [num_elements]DummyStruct
)

fn main() {}

When built with the following invocation, the compilation fails:

❯ v -enable-globals 1.v
==================
/tmp/v_501/1.01J1JR6W82J8GJBYBQHK0EWBH8.tmp.c:2068:41: error: initializer for aggregate with no elements requires explicit braces
 Array_fixed_main__DummyStruct_10  d = {0}; // global4
                                        ^
1 error generated.
...
==================
(Use `v -cg` to print the entire error message)

builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

On the other hand, if DummyStruct is non-empty then the compilation succeeds.

Consider the following:

❯ cat 2.v
module main

const num_elements = 10

struct DummyStruct {
        dummy_item i32
}

__global (
        d [num_elements]DummyStruct
)

fn main() {}

The only change is that DummyStruct now has a dummy_item.

The compilation succeeds as follows:

❯ ~/Work/repos/vlang/v/v -enable-globals 2.v

NOTE:

❯ v --version
V 0.4.6 23e3894

❯ neofetch --off
spinlock@deadlock.local
-------------------
OS: macOS 14.5 23F79 arm64
Host: Mac14,9
Kernel: 23.5.0
Uptime: 11 days, 11 hours, 48 mins
Packages: 250 (port)
Shell: fish 3.7.1
Resolution: 5120x1440 , 3024x1964
DE: Aqua
WM: Quartz Compositor
WM Theme: Blue (Dark)
Terminal: tmux
CPU: Apple M2 Pro
GPU: Apple M2 Pro
Memory: 4652MiB / 32768MiB

Reproduction Steps

See above

Expected Behavior

Structs containing no members is a perfectly valid use case and is often referenced in the official documentation. There is nothing special about them that warrants a compiler build failure in the case of global arrays.

Current Behavior

See bug description above.

Possible Solution

No response

Additional Information/Context

No response

V version

0.4.6 23e3894

Environment details (OS name and version, etc.)

macOS 14.5 arm64

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.

@raw-bin raw-bin added the Bug This tag is applied to issues which reports bugs. label Jun 29, 2024
@felipensp
Copy link
Member

It fails only on clang.

@felipensp felipensp added the Compiler: Clang Bugs/feature requests, that are related to compiler Clang label Jun 29, 2024
@felipensp felipensp self-assigned this Jun 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. Compiler: Clang Bugs/feature requests, that are related to compiler Clang
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants