Skip to content

v test -skip-unused [ C compilation error (from tcc) ] #24555

@Avey777

Description

@Avey777

Describe the bug

success : v -no-skip-unused -enable-globals -stats test g_pool_test.v
error : v -enable-globals -stats test g_pool_test.v

Reproduction Steps

g_pool.v

module dbpool

import db.mysql

__global g_conns_pool ConnectionPool


pub fn init_pool(config mysql.Config, pool_size int) !string {
	mut g_conn := &g_conns_pool
	g_conn.connections = chan mysql.DB{cap: pool_size}
	g_conn.config = config

	for _ in 0 .. pool_size {
		g_conn.connections <- mysql.connect(config) or { return '' }
	}
	return ''
}


pub fn acquire() mysql.DB {
	return <-g_conns_pool.connections
}


pub fn release(conn mysql.DB) {
	g_conns_pool.connections <- conn
}

g_pool_test.v

module dbpool

import db.mysql


fn test_init_pool() {

	config := mysql.Config{
		host:     'mysql2.sqlpub.com'
		port:     3307
		username: 'vcore_test'
		password: 'wfo8wS7CylT0qIMg'
		dbname:   'vcore_test'
	}


	init_pool(config, 10) or { '' }

	
	mut conn := acquire()
	defer { release(conn) }

	rows := conn.exec('SELECT * FROM sys_users limit 1')!
	dump(rows)
}

v -enable-globals -stats test g_pool_test.v

Expected Behavior

---- Testing... ---------------------------------------------------------------------------------------------------------
        V  source  code size:      38686 lines,     179449 tokens,    1058225 bytes,   418 types,    26 modules,   188 files
generated  target  code size:      34743 lines,    1198697 bytes
compilation took: 416.335 ms, compilation speed: 92920 vlines/s, cgen threads: 5
running tests in: /home/Jengro/Documents/Dev/v-product/vprod-workspase/backend/common/dbpool/g_pool_test.v
[/home/Jengro/Documents/Dev/v-product/vprod-workspase/backend/common/dbpool/g_pool_test.v:25] rows: [mysql.Row{
    vals: ['1', '354', '354', '3453', '', '', '', '', '1', '0', '', '2025-06-04 11:16:07', '', '2025-04-15 11:16:18', '0', '', '/dashboard']
}]
      OK     903.676 ms    NO asserts | common.dbpool.test_init_pool()
     Summary for running V tests in "g_pool_test.v": 0 total. Elapsed time: 903 ms.

 OK    1338.506 ms /home/Jengro/Documents/Dev/v-product/vprod-workspase/backend/common/dbpool/g_pool_test.v

Current Behavior

---- Testing... ---------------------------------------------------------------------------------------------------------
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/tsession_7f0c35f52740_01JVXYCAEDKKE1ZCEMV8RYJQ9N/g_pool_test.01JVXYCAEKQFZVXXS5KEZAHHVA.tmp.c:17221: warning: implicit declaration of function 'db__mysql__DB_close'
cc: /home/Jengro/.vmr/versions/v_versions/v_latest/thirdparty/tcc/lib/libgc.a: error: 'GC_noop1_ptr' defined twice
cc: tcc: error: undefined symbol 'db__mysql__DB_close'
...
cc: tcc: error: undefined symbol 'db__mysql__DB_close'
(note: the original output was 6 lines long; it was truncated to its first 3 lines + the last line)
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
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 .

Cannot compile file /home/Jengro/Documents/Dev/v-product/vprod-workspase/backend/common/dbpool/g_pool_test.v

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.10 ddb1564

Environment details (OS name and version, etc.)

V full version V 0.4.10 2c42574.ddb1564
OS linux, Deepin 23.1
Processor 6 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory 0.15GB/7.61GB
V executable /home/Jengro/.vmr/versions/v_versions/v_latest/v
V last modified time 2025-05-23 00:30:18
V home dir OK, value: /home/Jengro/.vmr/versions/v_versions/v_latest
VMODULES OK, value: /home/Jengro/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/Jengro/Documents/Dev/v-product/vprod-workspase/backend/common/dbpool
Git version git version 2.47.2
V git status weekly.2025.20-51-gddb15646
.git/config present true
cc version cc (Deepin 12.3.0-17deepin12) 12.3.0
gcc version gcc (Deepin 12.3.0-17deepin12) 12.3.0
clang version Deepin clang version 17.0.6 (5deepin5)
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Debian GLIBC 2.38-6deepin13+rb1) 2.38

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.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: markusedBugs/feature requests, that are related to the -skip-unused.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions