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 crashes with SIGSEGV when using big.integer_from_string in const in module #22961

Closed
gechandesu opened this issue Nov 24, 2024 · 1 comment · Fixed by #22963
Closed
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@gechandesu
Copy link
Contributor

gechandesu commented Nov 24, 2024

Describe the bug

Using the big.integer_from_string function inside a module as a constant causes a compiler segmentation fault. See reproduction steps below.

Note that the same code but in the main module does not result in an segfault:

// This example works fine
module main

import math.big

struct BigintRange {
	start big.Integer
	end   big.Integer
}

const big_range = BigintRange{
	start: big.integer_from_string('338288524927261089654018896841347694592')!
	end:   big.integer_from_string('338620831926207318622244848606417780735')!
}

fn main() {
	println(big_range)
}

// Output:
// BigintRange{
//     start: 338288524927261089654018896841347694592
//     end: 338620831926207318622244848606417780735
// }

Reproduction Steps

Create a dir e.g. mymod with contents:

// mod.v

module mymod

import math.big

struct BigintRange {
	start big.Integer
	end   big.Integer
}

const range = BigintRange{
	start: big.integer_from_string('338288524927261089654018896841347694592')!
	end:   big.integer_from_string('338620831926207318622244848606417780735')!
}
// mod_test.v

module mymod

fn test_dummy() {
    assert true
}

Then run v test .

---- Testing... ------------------------------------------------------------------------------------------
 FAIL     0.000 ms /home/ge/Code/v/netaddr/issues/mymod/mod_test.v
>> compilation failed:
signal 11: segmentation fault
                                                        | 0x55c52a79648a | /home/ge/.vlang/v(+0x1f348a) 
                                                        | 0x55c52a8a5a7d | /home/ge/.vlang/v(+0x302a7d) 
                                                        | 0x55c52a7d6dda | /home/ge/.vlang/v(+0x233dda) 
                                                        | 0x55c52a7d3057 | /home/ge/.vlang/v(+0x230057) 
                                                        | 0x55c52a8a803d | /home/ge/.vlang/v(+0x30503d) 
                                                        | 0x55c52a897402 | /home/ge/.vlang/v(+0x2f4402) 
                                                        | 0x55c52a897835 | /home/ge/.vlang/v(+0x2f4835) 
                                                        | 0x55c52a8997db | /home/ge/.vlang/v(+0x2f67db) 
                                                        | 0x55c52a8aa8de | /home/ge/.vlang/v(+0x3078de) 
                                                        | 0x55c52a84a4d7 | /home/ge/.vlang/v(+0x2a74d7) 
                                                        | 0x55c52a74255a | /home/ge/.vlang/v(+0x19f55a) 
                                                        | 0x55c52a743f0b | /home/ge/.vlang/v(+0x1a0f0b) 
                                                        | 0x55c52a5ce6c2 | /home/ge/.vlang/v(+0x2b6c2) 
                                                        | 0x55c52a5a6f1d | /home/ge/.vlang/v(+0x3f1d) 
                                                        | 0x7f3833d3839d | /usr/lib/libc.so.6(+0x9439d) 
                                                        | 0x7f3833dbd49c | /usr/lib/libc.so.6(+0x11949c) 

----------------------------------------------------------------------------------------------------------
To reproduce just failure 1 run:    '/home/ge/.vlang/v'  '/home/ge/Code/v/netaddr/issues/mymod/mod_test.v'
Summary for all V _test.v files: 1 failed, 1 total. Elapsed time: 545 ms, on 1 job. Comptime: 491 ms. Runtime: 0 ms.

Expected Behavior

No segfault.

Current Behavior

Compiler crashes with segfault.

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 1345eac

Environment details (OS name and version, etc.)

V full version: V 0.4.8 5ec9bb5.1345eac
OS: linux, Linux version 6.6.8-arch1-1 (linux@archlinux) (gcc (GCC) 13.2.1 20230801, GNU ld (GNU Binutils) 2.41.0) #1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000
Processor: 16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-1240P

getwd: /home/ge/Code/v/netaddr/issues/mymod
vexe: /home/ge/.vlang/v
vexe mtime: 2024-11-24 11:11:18

vroot: OK, value: /home/ge/.vlang
VMODULES: OK, value: /home/ge/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.1
Git vroot status: weekly.2024.47-25-g1345eac5 (3 commit(s) behind V master)
.git/config present: true

CC version: cc (GCC) 14.2.1 20240910
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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.

Huly®: V_0.6-21402

@gechandesu gechandesu added the Bug This tag is applied to issues which reports bugs. label Nov 24, 2024
@gechandesu gechandesu changed the title Compiler crashes with SIGSEGV when using big.integer_from_string as const in module Compiler crashes with SIGSEGV when using big.integer_from_string in const in module Nov 24, 2024
@JalonSolov
Copy link
Contributor

On Linux, with latest V 0.4.8 e86b526, I get

---- Testing... ----------------------------------------------------------------------------------------------------------------------------
 FAIL     0.000 ms /tmp/mymod/mod_test.v
>> compilation failed:
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:48529: at v__gen__c__Gen_or_block: RUNTIME ERROR: invalid memory access
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:53755: by v__gen__c__Gen_call_expr
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:44089: by v__gen__c__Gen_expr
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:43302: by v__gen__c__Gen_expr_with_cast
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:65222: by v__gen__c__Gen_struct_init_field_default
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:65206: by v__gen__c__Gen_struct_init_field
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:64670: by v__gen__c__Gen_struct_init
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:44429: by v__gen__c__Gen_expr
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:41588: by v__gen__c__Gen_expr_string_surround
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:47460: by v__gen__c__Gen_const_decl_init_later
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:47332: by v__gen__c__Gen_const_decl
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:42702: by v__gen__c__Gen_stmt
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:42503: by v__gen__c__Gen_stmts_with_tmp_var
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:42375: by v__gen__c__Gen_stmts
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:41231: by v__gen__c__Gen_gen_file
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:41172: by v__gen__c__cgen_process_one_file_cb
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:49096: by sync__pool__process_in_thread
/tmp/v_1000/v2.01JDF4XH4TYWH2B3NJ3XASGV84.tmp.c:12218: by sync__pool__process_in_thread_thread_wrapper
0x7a4420a2239d: by ???
0x7a4420aa749c: by ???

--------------------------------------------------------------------------------------------------------------------------------------------
To reproduce just failure 1 run:    '/home/jalon/git/v/v'  '/tmp/mymod/mod_test.v'
Summary for all V _test.v files: 1 failed, 1 total. Elapsed time: 552 ms, on 1 job. Comptime: 491 ms. Runtime: 0 ms.

@JalonSolov JalonSolov added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Nov 24, 2024
@felipensp felipensp self-assigned this Nov 24, 2024
@felipensp felipensp added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Nov 24, 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. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants