-autofree tries to free const
fixed size arrays
#21211
Labels
Bug
This tag is applied to issues which reports bugs.
OS: Windows
Bugs/feature requests, that are specific to Windows OS.
const
fixed size arrays
#21211
Describe the bug
When declaring a fixed size array that requires some kind of cleanup, using
-autofree
causes cgen to callarray_free
on the array itself.This bug can be triggered declaring such an array, or simply by importing
time
, sincetime
declares an array like this.Reproduction Steps
run with `v -autofree run fixed_size_autofree_bug.v
Expected Behavior
The program to print the words and exit cleanly.
Current Behavior
The program crashes during
_vcleanup
:Possible Solution
The C code generates these definitions:
The line
array_free(&_const_main__words);
is what causes the crash. Instead of generating this it should be generating some other cleanup code.Additional Information/Context
Running on Windows with
msvc
.This bug can also be triggered by simply importing
time
in a program that uses -autofree, due to a fixed-size array of strings being declared there:https://github.com/vlang/v/blob/master/vlib/time/time.v#L4
V version
V 0.4.5 ad17be5
Environment details (OS name and version, etc.)
V full version: V 0.4.5 386bd77.ad17be5
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 4 cpus, 64bit, little endian,
getwd: C:\Users\Owner\Code\v-experiments\fixed_size_autofree_bug
vexe: C:\Program Files\v\v.exe
vexe mtime: 2024-04-07 05:22:56
vroot: contains spaces, value: C:\Program Files\v
VMODULES: OK, value: C:\Users\Owner.vmodules
VTMP: OK, value: C:\Users\Owner\AppData\Local\Temp\v_0
Git version: git version 2.37.2.windows.2
Git vroot status: weekly.2024.14-26-gad17be5d (1 commit(s) behind V master)
.git/config present: true
CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.
thirdparty/tcc: N/A
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.
The text was updated successfully, but these errors were encountered: