Skip to content

msvc int_min bug #25269

@kbkpbot

Description

@kbkpbot

Describe the bug

A msvc int_min bug cause v compiler fail.

Reproduction Steps

In vlib/v/ast/comptime_const_values.v

// i32 tries to return a `ComptTimeConstValue` as `i32` type.
pub fn (val ComptTimeConstValue) i32() ?i32 {
	x := val.i64()?
	if x > -2147483649 && x < 2147483648 {
		return i32(x)
	}
	return none
}

will fail under msvc.

And I create a test file for this bug:
bug.c

#include <stdio.h>
#include <stdint.h>

typedef int64_t i64;

void main() {
	i64 x = 2147483647;
    if (x > -2147483649  && x < 2147483648) {
        printf("x=%lld\n", x);
    }
}

compile it with msvc

cl bug.c

Expected Behavior

output

2147483647

Current Behavior

nothing output

Possible Solution

need a workaround for this.

Additional Information/Context

tcc, gcc, clang has no this bug

V version

V 0.4.11 84f6816.0a4a807

Environment details (OS name and version, etc.)

V full version V 0.4.11 84f6816.0a4a807
OS linux, Ubuntu 24.04.3 LTS
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Memory 7.52GB/15.51GB
V executable /media/HD/github/kbkpbot/v/v
V last modified time 2025-09-09 11:32:00
V home dir OK, value: /media/HD/github/kbkpbot/v
VMODULES OK, value: /home/mars/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/mars/v/bug/64
Git version git version 2.43.0
V git status weekly.2025.36-44-g0a4a8078
.git/config present true
cc version cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
gcc version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
clang version Ubuntu clang version 18.1.3 (1ubuntu1)
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 (Ubuntu GLIBC 2.39-0ubuntu8.5) 2.39

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

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Compilers: MSVCBugs/feature requests, that are related to compiling V programs with MSVC.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions